diff --git a/ci/base.cue b/ci/base.cue index 4e359b9e..73fea364 100644 --- a/ci/base.cue +++ b/ci/base.cue @@ -5,6 +5,7 @@ import ( ) let GoVersion = "1.17" +let GolangCILintVersion = "1.44.0" // Base container images used for the CI images: { @@ -31,4 +32,14 @@ images: { }, ] } + + // base image for the Go linter + // https://golangci-lint.run/usage/install/#docker + goLinter: docker.#Build & { + steps: [ + docker.#Pull & { + source: "index.docker.io/golangci/golangci-lint:v\(GolangCILintVersion)" + }, + ] + } } diff --git a/ci/main.cue b/ci/main.cue index af7bde66..84269e57 100644 --- a/ci/main.cue +++ b/ci/main.cue @@ -3,9 +3,7 @@ package main import ( "strings" - // "dagger.io/dagger" "dagger.io/dagger/engine" - "universe.dagger.io/bash" ) @@ -13,7 +11,7 @@ engine.#Plan & { inputs: { params: { // FIXME: until we support a better way - os: string | *"darwin" + os: string | *"darwin" arch: string | *"amd64" // FIXME: implement condition actions using params @@ -26,8 +24,8 @@ engine.#Plan & { } outputs: directories: "go binaries": { - contents: actions.build.export.directories["/build"].contents - dest: "./build" + contents: actions.build.export.directories["/build"].contents + dest: "./build" } actions: { @@ -35,13 +33,19 @@ engine.#Plan & { id: "go mod cache" } + source: "dagger source code": { + contents: inputs.directories.source.contents + dest: "/usr/src/dagger" + } + + // FIXME: build only if the linter passed build: bash.#Run & { input: images.goBuilder.output env: { GOMODCACHE: mounts["go mod cache"].dest - GOOS: strings.ToLower(inputs.params.os) - GOARCH: strings.ToLower(inputs.params.arch) + GOOS: strings.ToLower(inputs.params.os) + GOARCH: strings.ToLower(inputs.params.arch) } script: contents: #""" @@ -54,10 +58,7 @@ engine.#Plan & { """# mounts: { - "dagger source code": { - contents: inputs.directories.source.contents - dest: "/usr/src/dagger" - } + source "go mod cache": { dest: "/gomodcache" @@ -68,5 +69,16 @@ engine.#Plan & { workdir: mounts["dagger source code"].dest export: directories: "/build": _ } + + goLint: bash.#Run & { + input: images.goLinter.output + + // FIXME: the source volume is too slow, taking >3m on docker for mac (vs < 2sec on the host machine) + script: contents: "golangci-lint run -v --timeout 5m" + workdir: mounts["dagger source code"].dest + mounts: { + source + } + } } }