diff --git a/.github/workflows/test_push.yml b/.github/workflows/test_push.yml new file mode 100644 index 0000000..2996f4b --- /dev/null +++ b/.github/workflows/test_push.yml @@ -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 \ No newline at end of file diff --git a/ci/build_test_release.go b/ci/build_test_release.go index eede784..903c7c0 100644 --- a/ci/build_test_release.go +++ b/ci/build_test_release.go @@ -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") diff --git a/ci/test_on_push.go b/ci/test_on_push.go new file mode 100644 index 0000000..3181d04 --- /dev/null +++ b/ci/test_on_push.go @@ -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) +} \ No newline at end of file diff --git a/cocommit_go-darwin b/cocommit_go-darwin new file mode 100755 index 0000000..a33338b Binary files /dev/null and b/cocommit_go-darwin differ diff --git a/cocommit_go-linux b/cocommit_go-linux new file mode 100755 index 0000000..e6d8c18 Binary files /dev/null and b/cocommit_go-linux differ diff --git a/cocommit_go-windows b/cocommit_go-windows new file mode 100755 index 0000000..9e1150a Binary files /dev/null and b/cocommit_go-windows differ