added a test workflow on push using dagger ci

This commit is contained in:
Theis
2024-03-04 19:00:11 +01:00
parent 2ab5c47eca
commit 0992afa1f6
6 changed files with 66 additions and 4 deletions
+18
View File
@@ -0,0 +1,18 @@
name: Test On Push
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v3
- uses: actions/checkout@v3
- name: Get Dagger
run: go get dagger.io/dagger@latest
- name: Run Dagger Test Workflow
run: go run ci/test_on_push.go
+4 -4
View File
@@ -18,6 +18,8 @@ func main() {
}
defer client.Close()
goCache := client.CacheVolume("golang")
// use a node:16-slim container
// mount the source code directory on the host
// at /src in the container
@@ -25,7 +27,7 @@ func main() {
From("golang:1.21").
WithDirectory("/src", client.Host().Directory(".", dagger.HostDirectoryOpts{
Exclude: []string{"ci/"},
}))
})).WithMountedCache("/src/dagger_dep_cache/go_dep", goCache)
geese := []string{"darwin", "linux", "windows"}
goarch := "amd64"
@@ -35,10 +37,8 @@ func main() {
runner := source.WithWorkdir("/src").
WithExec([]string{"go", "mod", "tidy"})
runner = source.WithWorkdir("/src/src_code/go_src")
// run application tests
test := runner.WithExec([]string{"go", "test"})
test := runner.WithWorkdir("/src/src_code/go_src").WithExec([]string{"go", "test"})
buildDir := test.Directory("/src/dist")
+44
View File
@@ -0,0 +1,44 @@
package main
import (
"context"
"fmt"
"os"
"dagger.io/dagger"
)
func main() {
ctx := context.Background()
// initialize Dagger client
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
panic(err)
}
defer client.Close()
goCache := client.CacheVolume("golang")
// use a node:16-slim container
// mount the source code directory on the host
// at /src in the container
source := client.Container().
From("golang:1.21").
WithDirectory("/src", client.Host().Directory(".", dagger.HostDirectoryOpts{
Exclude: []string{"ci/", "build/"},
})).WithMountedCache("/src/dagger_dep_cache/go_dep", goCache)
// set the working directory in the container
// install application dependencies
runner := source.WithWorkdir("/src").
WithExec([]string{"go", "mod", "tidy"})
// run application tests
out, err := runner.WithWorkdir("/src/src_code/go_src").WithExec([]string{"go", "test"}).
Stderr(ctx)
if err != nil {
panic(err)
}
fmt.Println(out)
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.