From 646a4d153d6f7893eee350095977dbbe56ceaf3e Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 1 Mar 2022 14:48:50 -0800 Subject: [PATCH] ci: implemented go test Signed-off-by: Sam Alba --- ci/images.cue | 2 +- ci/main.cue | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ci/images.cue b/ci/images.cue index 8263b1c7..6e2296f7 100644 --- a/ci/images.cue +++ b/ci/images.cue @@ -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 & { diff --git a/ci/main.cue b/ci/main.cue index 78c69d67..d4df297e 100644 --- a/ci/main.cue +++ b/ci/main.cue @@ -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,24 +58,27 @@ 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 input: _baseImages.goBuilder 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)" + GOOS: strings.ToLower(inputs.params.os) + GOARCH: strings.ToLower(inputs.params.arch) + 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 \ + 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