ci: implemented go lint

Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
Sam Alba 2022-02-10 17:18:57 -08:00
parent 679bb30148
commit f17c470feb
2 changed files with 34 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import (
) )
let GoVersion = "1.17" let GoVersion = "1.17"
let GolangCILintVersion = "1.44.0"
// Base container images used for the CI // Base container images used for the CI
images: { 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)"
},
]
}
} }

View File

@ -3,9 +3,7 @@ package main
import ( import (
"strings" "strings"
// "dagger.io/dagger"
"dagger.io/dagger/engine" "dagger.io/dagger/engine"
"universe.dagger.io/bash" "universe.dagger.io/bash"
) )
@ -35,6 +33,12 @@ engine.#Plan & {
id: "go mod cache" 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 & { build: bash.#Run & {
input: images.goBuilder.output input: images.goBuilder.output
@ -54,10 +58,7 @@ engine.#Plan & {
"""# """#
mounts: { mounts: {
"dagger source code": { source
contents: inputs.directories.source.contents
dest: "/usr/src/dagger"
}
"go mod cache": { "go mod cache": {
dest: "/gomodcache" dest: "/gomodcache"
@ -68,5 +69,16 @@ engine.#Plan & {
workdir: mounts["dagger source code"].dest workdir: mounts["dagger source code"].dest
export: directories: "/build": _ 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
}
}
} }
} }