Skip to content

Commit

Permalink
ci: add test function to DotnetSdk module (#25)
Browse files Browse the repository at this point in the history
* ci: add test function to DotnetSdk module

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* ci: enable test output

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* ci: introduce dev module

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* docs: add README.md

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* ci: add github workflow

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* chore: remove unneccesery files

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* Apply suggestions from code review

* ci: wrap dotnet test with sh

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* ci: try another attempts

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* ci: try remove blame hang

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

* ci: rename workflow name

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>

---------

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
  • Loading branch information
wingyplus authored Jun 29, 2024
1 parent e769d64 commit 46a59f6
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 37 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: dotnet sdk
on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test
uses: dagger/dagger-for-github@v5
with:
verb: call
module: ./dev
args: test --source=.
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Dagger SDK for DotNet

This is the place for DotNet Dagger SDK.

## Development

This project provides `dev` module to uses for developing the SDK.

### Introspection

Uses for fetching introspection by using the command:

```
$ dagger -m dev introspect export --path=./sdk/Dagger.SDK/introspection.json
```

### Test

You can running all tests by:

```
$ dagger -m dev test --source=.
```
7 changes: 1 addition & 6 deletions dagger.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"name": "dotnet-sdk",
"sdk": "go",
"dependencies": [
{
"name": "docker",
"source": "github.com/shykes/daggerverse/docker@c9a80c9eac0675a53a7e052da3594207f4235988"
}
],
"dependencies": [],
"source": ".",
"engineVersion": "v0.11.6"
}
4 changes: 4 additions & 0 deletions dev/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dagger.gen.go linguist-generated
/internal/dagger/** linguist-generated
/internal/querybuilder/** linguist-generated
/internal/telemetry/** linguist-generated
4 changes: 4 additions & 0 deletions dev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dagger.gen.go
/internal/dagger
/internal/querybuilder
/internal/telemetry
4 changes: 4 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Dev module for DotNet SDK

A temporary module for developing DotNet SDK. In the future, this module will be
written by DotNet SDK itself.
12 changes: 12 additions & 0 deletions dev/dagger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Functions for managing Dagger.
package main

const daggerVersion = "0.11.9"

func installDaggerCli(ctr *Container) *Container {
return ctr.
WithEnvVariable("BIN_DIR", "/usr/local/bin").
WithEnvVariable("DAGGER_VERSION", daggerVersion).
WithExec([]string{"apk", "add", "--no-cache", "curl"}).
WithExec([]string{"sh", "-c", "curl -L https://dl.dagger.io/dagger/install.sh | sh"})
}
6 changes: 6 additions & 0 deletions dev/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "dev",
"sdk": "go",
"source": ".",
"engineVersion": "dev-a89a76d23b5dd8e8efeda2d0f313631ffb656402"
}
41 changes: 41 additions & 0 deletions dev/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import "fmt"

const dockerEngineVersion = "27"

func dockerEngine() *Service {
// Copied some if it from https://github.com/shykes/daggerverse/blob/main/docker/main.go.
return dag.Container().
From(fmt.Sprintf("docker:%s-dind", dockerEngineVersion)).
WithoutEntrypoint().
WithExec([]string{
"dockerd",
"--host=tcp://0.0.0.0:2375",
"--host=unix:///var/run/docker.sock",
"--tls=false",
}, ContainerWithExecOpts{
InsecureRootCapabilities: true,
ExperimentalPrivilegedNesting: true,
}).
WithExposedPort(2375).
AsService()
}

func dockerCli() *Container {
return dag.Container().
From(fmt.Sprintf("docker:%s-cli", dockerEngineVersion))

}

func installDockerCli(ctr *Container) *Container {
return ctr.WithFile(
"/usr/local/bin/docker",
dockerCli().File("/usr/local/bin/docker"),
)
}

func dockerd(ctr *Container) *Container {
return ctr.WithServiceBinding("dockerd", dockerEngine()).
WithEnvVariable("DOCKER_HOST", "tcp://dockerd:2375")
}
File renamed without changes.
54 changes: 54 additions & 0 deletions dev/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// A dev module for dagger-dotnet-sdk.
//
// This module contains functions for developing the SDK such as, running tests,
// generate introspection, etc.
package main

import (
"context"
_ "embed"
)

//go:embed introspection.graphql
var introspectionGraphql string

const introspectionJsonPath = "/introspection.json"

type Dev struct {
}

// Fetch introspection json from the Engine.
//
// This function forked from https://github.com/helderco/daggerverse/blob/main/codegen/main.go but
// didn't modify anything in the data.
//
// It's uses for test for the codegen only.
func (m *Dev) Introspect() *File {
return dag.Container().
From("alpine:3.20").
With(installDaggerCli).
WithNewFile("/introspection.graphql", ContainerWithNewFileOpts{Contents: introspectionGraphql}).
WithExec([]string{"sh", "-c", "dagger query < /introspection.graphql > " + introspectionJsonPath}, ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
}).
File(introspectionJsonPath)
}

func (m *Dev) Test(
ctx context.Context,
// SDK Source directory.
source *Directory,
) error {
_, err := dag.Container().
From("mcr.microsoft.com/dotnet/sdk:8.0-alpine3.20").
WithMountedDirectory("/src", source).
WithWorkdir("/src/sdk").
WithFile("Dagger.SDK/introspection.json", m.Introspect()).
WithExec([]string{"dotnet", "restore"}).
WithExec([]string{"dotnet", "build", "--no-restore"}).
WithExec([]string{"dotnet", "test", "--no-build"}, ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
}).
Sync(ctx)
return err
}
32 changes: 1 addition & 31 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
// The DotNet SDK and runtime.
package main

import (
_ "embed"
)

//go:embed introspection.graphql
var introspectionGraphql string

const introspectionJsonPath = "/introspection.json"

type DotnetSdk struct{}

// Fetch introspection json from the Engine.
//
// This function forked from https://github.com/helderco/daggerverse/blob/main/codegen/main.go but
// didn't modify anything in the data.
//
// It's uses for test for the codegen only.
func (m *DotnetSdk) Introspect() *File {
return dag.Docker().
Cli(DockerCliOpts{
Version: "26",
Engine: dag.Docker().Engine(DockerEngineOpts{Version: "26"}),
}).
Container().
WithExec([]string{"apk", "add", "--no-cache", "curl"}).
WithExec([]string{"sh", "-c", "curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=/usr/local/bin sh"}).
WithNewFile("/introspection.graphql", ContainerWithNewFileOpts{Contents: introspectionGraphql}).
WithExec([]string{"sh", "-c", "dagger query < /introspection.graphql > " + introspectionJsonPath}, ContainerWithExecOpts{
ExperimentalPrivilegedNesting: true,
}).
File(introspectionJsonPath)
type DotnetSdk struct {
}

0 comments on commit 46a59f6

Please sign in to comment.