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 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)"
},
]
}
}

View File

@ -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
}
}
}
}