ci: implemented go test

Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
Sam Alba 2022-03-01 14:48:50 -08:00
parent 029a0d270f
commit 646a4d153d
2 changed files with 23 additions and 11 deletions

View File

@ -14,7 +14,7 @@ let CUEVersion = "0.4.2"
// base image to build go binaries
goBuilder: _goBuilder.output
_goBuilder: docker.#Build & {
_packages: ["bash", "git"]
_packages: ["bash", "git", "alpine-sdk"]
steps: [
docker.#Pull & {

View File

@ -33,7 +33,7 @@ dagger.#Plan & {
}
outputs: directories: "go binaries": {
contents: actions.build.export.directories["/build"]
contents: actions.goBuild.export.directories["/build"]
dest: "./build"
}
@ -58,7 +58,9 @@ dagger.#Plan & {
_baseImages: #Images
build: bash.#Run & {
// Go build the dagger binary
// depends on goLint and goTest to complete successfully
goBuild: bash.#Run & {
_mountSourceCode
_mountGoCache
@ -67,14 +69,15 @@ dagger.#Plan & {
env: {
GOOS: strings.ToLower(inputs.params.os)
GOARCH: strings.ToLower(inputs.params.arch)
// Makes sure the linter completes before starting the build
"__depends": "\(goLint.exit)"
CGO_ENABLED: "0"
// Makes sure the linter and unit tests complete before starting the build
"__depends_lint": "\(goLint.exit)"
"__depends_tests": "\(goTest.exit)"
}
script: contents: #"""
mkdir -p /build
git_revision=$(git rev-parse --short HEAD)
CGO_ENABLED=0 \
go build -v -o /build/dagger \
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
./cmd/dagger/
@ -83,20 +86,29 @@ dagger.#Plan & {
export: directories: "/build": _
}
// Go unit tests
goTest: bash.#Run & {
_mountSourceCode
_mountGoCache
input: _baseImages.goBuilder
script: contents: "go test -race -v ./..."
}
// Go lint using golangci-lint
goLint: bash.#Run & {
_mountSourceCode
_mountGoCache
input: _baseImages.goLinter
script: contents: "golangci-lint run -v --timeout 5m"
}
// CUE lint
cueLint: bash.#Run & {
_mountSourceCode
input: _baseImages.cue
script: contents: #"""
# Format the cue code
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s