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"
) )
@ -13,7 +11,7 @@ engine.#Plan & {
inputs: { inputs: {
params: { params: {
// FIXME: until we support a better way // FIXME: until we support a better way
os: string | *"darwin" os: string | *"darwin"
arch: string | *"amd64" arch: string | *"amd64"
// FIXME: implement condition actions using params // FIXME: implement condition actions using params
@ -26,8 +24,8 @@ engine.#Plan & {
} }
outputs: directories: "go binaries": { outputs: directories: "go binaries": {
contents: actions.build.export.directories["/build"].contents contents: actions.build.export.directories["/build"].contents
dest: "./build" dest: "./build"
} }
actions: { actions: {
@ -35,13 +33,19 @@ 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
env: { env: {
GOMODCACHE: mounts["go mod cache"].dest GOMODCACHE: mounts["go mod cache"].dest
GOOS: strings.ToLower(inputs.params.os) GOOS: strings.ToLower(inputs.params.os)
GOARCH: strings.ToLower(inputs.params.arch) GOARCH: strings.ToLower(inputs.params.arch)
} }
script: contents: #""" script: contents: #"""
@ -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
}
}
} }
} }