Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add test function to DotnetSdk module #25

Merged
merged 11 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>Dagger.SDK.SourceGenerator.Tests</RootNamespace>
<TestingExtensionsProfile>Default</TestingExtensionsProfile>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions sdk/Dagger.SDK.Tests/Dagger.SDK.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TestingExtensionsProfile>Default</TestingExtensionsProfile>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
Expand Down