forked from cubzh/cubzh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI : first dagger program to run unit tests
- Loading branch information
1 parent
08865b9
commit f8ed129
Showing
7 changed files
with
310 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ci/core_unit_tests/go.sum filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: CI | ||
|
||
on: | ||
# push: | ||
# branches: | ||
# - dagger | ||
# - main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
|
||
# Core Unit Tests | ||
# -------------------------------------------------- | ||
core_unit_tests: | ||
name: Core Unit Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.18' | ||
cache: true | ||
cache-dependency-path: ci/core_unit_tests/go.sum | ||
|
||
- name: Build Dagger program | ||
working-directory: ./ci/core_unit_tests | ||
run: go build -v ./... | ||
|
||
- name: Run Dagger program | ||
working-directory: . | ||
# run: echo "ERROR=./ci/core_unit_tests/unit_tests" >> $GITHUB_OUTPUT | ||
run: ./ci/core_unit_tests/unit_tests | ||
|
||
# other_ci_job: | ||
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Dagger | ||
|
||
## CI : Unit Tests | ||
|
||
[https://devel.docs.dagger.io/8g34z/get-started-sdk-go/](https://devel.docs.dagger.io/8g34z/get-started-sdk-go/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
module cu.bzh/core/ci/unit_tests | ||
|
||
go 1.18 | ||
|
||
require dagger.io/dagger v0.3.0 | ||
|
||
require ( | ||
github.com/Khan/genqlient v0.5.0 // indirect | ||
github.com/Microsoft/go-winio v0.5.2 // indirect | ||
github.com/agext/levenshtein v1.2.3 // indirect | ||
github.com/bhoriuchi/graphql-go-tools v1.0.0 // indirect | ||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect | ||
github.com/containerd/console v1.0.3 // indirect | ||
github.com/containerd/containerd v1.6.8 // indirect | ||
github.com/containerd/continuity v0.3.0 // indirect | ||
github.com/containerd/ttrpc v1.1.0 // indirect | ||
github.com/containerd/typeurl v1.0.2 // indirect | ||
github.com/dagger/dagger v0.3.2 // indirect | ||
github.com/docker/cli v20.10.17+incompatible // indirect | ||
github.com/docker/distribution v2.8.1+incompatible // indirect | ||
github.com/docker/docker v20.10.17+incompatible // indirect | ||
github.com/docker/docker-credential-helpers v0.6.4 // indirect | ||
github.com/docker/go-connections v0.4.0 // indirect | ||
github.com/docker/go-units v0.4.0 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/gofrs/flock v0.8.1 // indirect | ||
github.com/gogo/googleapis v1.4.1 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect | ||
github.com/graphql-go/graphql v0.8.0 // indirect | ||
github.com/graphql-go/handler v0.2.3 // indirect | ||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.2 // indirect | ||
github.com/iancoleman/strcase v0.2.0 // indirect | ||
github.com/klauspost/compress v1.15.9 // indirect | ||
github.com/mattn/go-colorable v0.1.12 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/moby/buildkit v0.10.5 // indirect | ||
github.com/moby/locker v1.0.1 // indirect | ||
github.com/moby/sys/signal v0.7.0 // indirect | ||
github.com/morikuni/aec v1.0.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/rs/zerolog v1.28.0 // indirect | ||
github.com/sirupsen/logrus v1.9.0 // indirect | ||
github.com/tonistiigi/fsutil v0.0.0-20220115021204-b19f7f9cb274 // indirect | ||
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect | ||
github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f // indirect | ||
github.com/vektah/gqlparser/v2 v2.5.1 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.34.0 // indirect | ||
go.opentelemetry.io/otel v1.10.0 // indirect | ||
go.opentelemetry.io/otel/exporters/jaeger v1.4.1 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.9.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.9.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.9.0 // indirect | ||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.9.0 // indirect | ||
go.opentelemetry.io/otel/sdk v1.9.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.10.0 // indirect | ||
go.opentelemetry.io/proto/otlp v0.18.0 // indirect | ||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect | ||
golang.org/x/net v0.0.0-20220811182439-13a9a731de15 // indirect | ||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect | ||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect | ||
google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c // indirect | ||
google.golang.org/grpc v1.49.0 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
) | ||
|
||
replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220414164044-61404de7df1a+incompatible |
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"dagger.io/dagger" | ||
) | ||
|
||
func main() { | ||
//fmt.Println("Hello Dagger!") | ||
|
||
err := buildAnRunCurrentDirectory() | ||
if err != nil { | ||
fmt.Println(err) | ||
fmt.Println("exit_failure") | ||
os.Exit(1) | ||
} | ||
fmt.Println("exit_success") | ||
os.Exit(0) | ||
|
||
//branch := "dagger" | ||
|
||
// err := buildAnRunBranch(branch) | ||
// if err != nil { | ||
// fmt.Println(err) | ||
// } | ||
|
||
//fmt.Println("The End. 🙂") | ||
|
||
} | ||
|
||
func buildAnRunCurrentDirectory() error { | ||
|
||
// Get background context | ||
ctx := context.Background() | ||
// Initialize dagger client | ||
client, err := dagger.Connect(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer client.Close() | ||
|
||
fmt.Println("Getting files...") | ||
rootDir := client.Host().Workdir().Read() | ||
rootDirID, err := rootDir.ID(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("Building Docker container...") | ||
// build container with correct dockerfile | ||
buildOpts := dagger.ContainerBuildOpts{ | ||
Dockerfile: "./dockerfiles/ubuntu_build_env.Dockerfile", | ||
} | ||
ciContainer := client.Container().Build(rootDirID, buildOpts) | ||
|
||
fmt.Println("Compiling tests in container...") | ||
// set workdir and execute build commands | ||
ciContainer = ciContainer.WithWorkdir("/core/tests/cmake") | ||
ciContainer = ciContainer.Exec(dagger.ContainerExecOpts{ | ||
// Args: []string{"cmake", "-G", "Ninja", "."}, | ||
Args: []string{"bash", "-c", "cmake -G Ninja ."}, | ||
}) | ||
output, err := ciContainer.Stdout().Contents(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(output) | ||
code, err := ciContainer.ExitCode(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if code != 0 { | ||
return errors.New("cmake error") | ||
} | ||
|
||
fmt.Println("Running tests in container...") | ||
ciContainer = ciContainer.Exec(dagger.ContainerExecOpts{ | ||
Args: []string{"cmake", "--build", ".", "--clean-first"}, | ||
}) | ||
output, err = ciContainer.Stdout().Contents(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(output) | ||
code, err = ciContainer.ExitCode(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if code != 0 { | ||
return errors.New("cmake --build error") | ||
} | ||
|
||
ciContainer = ciContainer.Exec(dagger.ContainerExecOpts{ | ||
Args: []string{"./unit_tests"}, | ||
}) | ||
output, err = ciContainer.Stdout().Contents(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(output) | ||
code, err = ciContainer.ExitCode(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if code != 0 { | ||
return errors.New("running error") | ||
} | ||
|
||
fmt.Println("Tests done!") | ||
return nil | ||
} | ||
|
||
// func buildAnRunBranch(branchName string) error { | ||
|
||
// // Get background context | ||
// ctx := context.Background() | ||
// // Initialize dagger client | ||
// client, err := dagger.Connect(ctx) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// defer client.Close() | ||
|
||
// fmt.Println("Cloning Git repository...") | ||
|
||
// // Clone the cubzh repo at the specified branch | ||
// repo := client.Git("github.com/cubzh/cubzh") | ||
// repoID, err := repo.Branch(branchName).Tree().ID(ctx) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// fmt.Println("Building Docker container...") | ||
// // build container with correct dockerfile | ||
// buildOpts := dagger.ContainerBuildOpts{ | ||
// Dockerfile: "./dockerfiles/ubuntu_build_env.Dockerfile", | ||
// } | ||
// ciContainer := client.Container().Build(repoID, buildOpts) | ||
|
||
// fmt.Println("Running tests in container...") | ||
// // set workdir and execute build commands | ||
// ciContainer = ciContainer.WithWorkdir("/core/tests/cmake") | ||
// ciContainer = ciContainer.Exec(dagger.ContainerExecOpts{ | ||
// Args: []string{"cmake", "-G", "Ninja", "."}, | ||
// }) | ||
// code, err := ciContainer.ExitCode(ctx) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// if code != 0 { | ||
// return errors.New("cmake error") | ||
// } | ||
// ciContainer = ciContainer.Exec(dagger.ContainerExecOpts{ | ||
// Args: []string{"cmake", "--build", "."}, | ||
// }) | ||
// code, err = ciContainer.ExitCode(ctx) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// if code != 0 { | ||
// return errors.New("cmake --build error") | ||
// } | ||
// ciContainer = ciContainer.Exec(dagger.ContainerExecOpts{ | ||
// Args: []string{"./unit_tests"}, | ||
// }) | ||
// code, err = ciContainer.ExitCode(ctx) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// if code != 0 { | ||
// return errors.New("running error") | ||
// } | ||
// output, err := ciContainer.Stdout().Contents(ctx) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// fmt.Println(output) | ||
|
||
// fmt.Println("Tests done!") | ||
|
||
// return nil | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters