mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
added a test workflow on push using dagger ci
This commit is contained in:
@@ -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
|
||||||
@@ -18,6 +18,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
|
goCache := client.CacheVolume("golang")
|
||||||
|
|
||||||
// use a node:16-slim container
|
// use a node:16-slim container
|
||||||
// mount the source code directory on the host
|
// mount the source code directory on the host
|
||||||
// at /src in the container
|
// at /src in the container
|
||||||
@@ -25,7 +27,7 @@ func main() {
|
|||||||
From("golang:1.21").
|
From("golang:1.21").
|
||||||
WithDirectory("/src", client.Host().Directory(".", dagger.HostDirectoryOpts{
|
WithDirectory("/src", client.Host().Directory(".", dagger.HostDirectoryOpts{
|
||||||
Exclude: []string{"ci/"},
|
Exclude: []string{"ci/"},
|
||||||
}))
|
})).WithMountedCache("/src/dagger_dep_cache/go_dep", goCache)
|
||||||
|
|
||||||
geese := []string{"darwin", "linux", "windows"}
|
geese := []string{"darwin", "linux", "windows"}
|
||||||
goarch := "amd64"
|
goarch := "amd64"
|
||||||
@@ -35,10 +37,8 @@ func main() {
|
|||||||
runner := source.WithWorkdir("/src").
|
runner := source.WithWorkdir("/src").
|
||||||
WithExec([]string{"go", "mod", "tidy"})
|
WithExec([]string{"go", "mod", "tidy"})
|
||||||
|
|
||||||
runner = source.WithWorkdir("/src/src_code/go_src")
|
|
||||||
// run application tests
|
// run application tests
|
||||||
|
test := runner.WithWorkdir("/src/src_code/go_src").WithExec([]string{"go", "test"})
|
||||||
test := runner.WithExec([]string{"go", "test"})
|
|
||||||
|
|
||||||
buildDir := test.Directory("/src/dist")
|
buildDir := test.Directory("/src/dist")
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Reference in New Issue
Block a user