ci: ported to new Plan syntax + implemented CUE fmt + go linter + code cleanup
Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
parent
2a9cf1ce7c
commit
297fded56d
@ -6,6 +6,7 @@ import (
|
||||
|
||||
let GoVersion = "1.17"
|
||||
let GolangCILintVersion = "1.44.0"
|
||||
let CUEVersion = "0.4.2"
|
||||
|
||||
// Base container images used for the CI
|
||||
#Images: {
|
||||
@ -40,4 +41,40 @@ let GolangCILintVersion = "1.44.0"
|
||||
_goLinter: docker.#Pull & {
|
||||
source: "index.docker.io/golangci/golangci-lint:v\(GolangCILintVersion)"
|
||||
}
|
||||
|
||||
// base image for CUE cli + alpine distrib
|
||||
cue: _cue._alpine.output
|
||||
_cue: {
|
||||
_cueBinary: docker.#Pull & {
|
||||
source: "index.docker.io/cuelang/cue:\(CUEVersion)"
|
||||
}
|
||||
|
||||
_alpine: docker.#Build & {
|
||||
_packages: ["bash", "git"]
|
||||
|
||||
steps: [
|
||||
docker.#Pull & {
|
||||
source: "index.docker.io/alpine:3"
|
||||
},
|
||||
for pkg in _packages {
|
||||
docker.#Run & {
|
||||
command: {
|
||||
name: "apk"
|
||||
args: ["add", pkg]
|
||||
flags: {
|
||||
"-U": true
|
||||
"--no-cache": true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
docker.#Copy & {
|
||||
// input: _alpine.output
|
||||
contents: _cueBinary.output.rootfs
|
||||
source: "/usr/bin/cue"
|
||||
dest: "/usr/bin/cue"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
41
ci/main.cue
41
ci/main.cue
@ -3,11 +3,11 @@ package main
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"dagger.io/dagger/engine"
|
||||
"dagger.io/dagger"
|
||||
"universe.dagger.io/bash"
|
||||
)
|
||||
|
||||
engine.#Plan & {
|
||||
dagger.#Plan & {
|
||||
|
||||
// FIXME: Ideally we would want to automatically set the platform's arch identical to the host
|
||||
// to avoid the performance hit caused by qemu (linter goes from <3s to >3m when arch is x86)
|
||||
@ -29,22 +29,25 @@ engine.#Plan & {
|
||||
}
|
||||
}
|
||||
|
||||
outputs: directories: "go binaries": {
|
||||
contents: actions.build.export.directories["/build"].contents
|
||||
dest: "./build"
|
||||
}
|
||||
// FIXME?
|
||||
// FTL failed to load plan: outputs.directories."go binaries".contents: undefined field: contents:
|
||||
//
|
||||
// outputs: directories: "go binaries": {
|
||||
// contents: actions.build.export.directories["/build"].contents
|
||||
// dest: "./build"
|
||||
// }
|
||||
|
||||
actions: {
|
||||
_goModCache: "go mod cache": {
|
||||
dest: "/gomodcache"
|
||||
contents: engine.#CacheDir & {
|
||||
contents: dagger.#CacheDir & {
|
||||
id: "go mod cache"
|
||||
}
|
||||
}
|
||||
|
||||
_baseImages: #Images
|
||||
|
||||
_source: "dagger source code": {
|
||||
_sourceCode: "dagger source code": {
|
||||
contents: inputs.directories.source.contents
|
||||
dest: "/usr/src/dagger"
|
||||
}
|
||||
@ -63,14 +66,14 @@ engine.#Plan & {
|
||||
mkdir -p /build
|
||||
git_revision=$(git rev-parse --short HEAD)
|
||||
CGO_ENABLED=0 \
|
||||
go build -v -o /build/dagger \
|
||||
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
|
||||
./cmd/dagger/
|
||||
go build -v -o /build/dagger \
|
||||
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
|
||||
./cmd/dagger/
|
||||
"""#
|
||||
|
||||
workdir: mounts["dagger source code"].dest
|
||||
mounts: {
|
||||
_source
|
||||
_sourceCode
|
||||
_goModCache
|
||||
}
|
||||
|
||||
@ -83,9 +86,21 @@ engine.#Plan & {
|
||||
script: contents: "golangci-lint run -v --timeout 5m"
|
||||
workdir: mounts["dagger source code"].dest
|
||||
mounts: {
|
||||
_source
|
||||
_sourceCode
|
||||
_goModCache
|
||||
}
|
||||
}
|
||||
|
||||
cueFmt: bash.#Run & {
|
||||
input: _baseImages.cue
|
||||
|
||||
script: contents: #"""
|
||||
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s
|
||||
"""#
|
||||
workdir: mounts["dagger source code"].dest
|
||||
mounts: {
|
||||
_sourceCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user