2022-02-10 05:48:22 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-02-24 00:15:44 +01:00
|
|
|
"dagger.io/dagger"
|
2022-02-10 05:48:22 +01:00
|
|
|
"universe.dagger.io/bash"
|
|
|
|
)
|
|
|
|
|
2022-02-24 00:15:44 +01:00
|
|
|
dagger.#Plan & {
|
2022-02-18 05:39:40 +01:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
platform: "linux/aarch64"
|
|
|
|
|
2022-03-10 01:22:49 +01:00
|
|
|
client: filesystem: {
|
|
|
|
"../": read: exclude: [
|
|
|
|
"ci",
|
|
|
|
"node_modules",
|
|
|
|
"cmd/dagger/dagger",
|
|
|
|
"cmd/dagger/dagger-debug",
|
|
|
|
]
|
|
|
|
"./build": write: contents: actions.build.export.directories["/build"]
|
2022-02-24 01:21:51 +01:00
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
|
|
|
|
actions: {
|
2022-03-01 02:46:29 +01:00
|
|
|
_mountGoCache: {
|
|
|
|
mounts: "go mod cache": {
|
|
|
|
dest: "/root/.gocache"
|
|
|
|
contents: dagger.#CacheDir & {
|
|
|
|
id: "go mod cache"
|
|
|
|
}
|
2022-02-18 05:39:40 +01:00
|
|
|
}
|
2022-03-01 02:46:29 +01:00
|
|
|
env: GOMODCACHE: mounts["go mod cache"].dest
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
|
2022-03-01 02:46:29 +01:00
|
|
|
_mountSourceCode: {
|
|
|
|
mounts: "dagger source code": {
|
2022-03-10 01:22:49 +01:00
|
|
|
contents: client.filesystem."../".read.contents
|
2022-03-01 02:46:29 +01:00
|
|
|
dest: "/usr/src/dagger"
|
|
|
|
}
|
|
|
|
workdir: mounts["dagger source code"].dest
|
2022-02-11 02:18:57 +01:00
|
|
|
}
|
|
|
|
|
2022-03-01 02:46:29 +01:00
|
|
|
_baseImages: #Images
|
|
|
|
|
2022-03-01 23:48:50 +01:00
|
|
|
// Go build the dagger binary
|
|
|
|
// depends on goLint and goTest to complete successfully
|
2022-03-10 01:22:49 +01:00
|
|
|
build: bash.#Run & {
|
2022-03-01 02:46:29 +01:00
|
|
|
_mountSourceCode
|
|
|
|
_mountGoCache
|
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
input: _baseImages.goBuilder
|
2022-02-10 05:48:22 +01:00
|
|
|
|
2022-02-11 01:09:08 +01:00
|
|
|
env: {
|
2022-03-10 01:22:49 +01:00
|
|
|
GOOS: client.platform.os
|
|
|
|
GOARCH: client.platform.arch
|
2022-03-01 23:48:50 +01:00
|
|
|
CGO_ENABLED: "0"
|
|
|
|
// Makes sure the linter and unit tests complete before starting the build
|
|
|
|
"__depends_lint": "\(goLint.exit)"
|
|
|
|
"__depends_tests": "\(goTest.exit)"
|
2022-02-11 01:09:08 +01:00
|
|
|
}
|
|
|
|
|
2022-02-10 05:48:22 +01:00
|
|
|
script: contents: #"""
|
|
|
|
mkdir -p /build
|
|
|
|
git_revision=$(git rev-parse --short HEAD)
|
2022-03-01 23:48:50 +01:00
|
|
|
go build -v -o /build/dagger \
|
2022-02-24 00:15:44 +01:00
|
|
|
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
|
|
|
|
./cmd/dagger/
|
2022-02-10 05:48:22 +01:00
|
|
|
"""#
|
|
|
|
|
2022-02-11 01:09:08 +01:00
|
|
|
export: directories: "/build": _
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
2022-02-11 02:18:57 +01:00
|
|
|
|
2022-03-01 23:48:50 +01:00
|
|
|
// Go unit tests
|
|
|
|
goTest: bash.#Run & {
|
|
|
|
_mountSourceCode
|
|
|
|
_mountGoCache
|
|
|
|
|
|
|
|
input: _baseImages.goBuilder
|
|
|
|
script: contents: "go test -race -v ./..."
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go lint using golangci-lint
|
2022-02-11 02:18:57 +01:00
|
|
|
goLint: bash.#Run & {
|
2022-03-01 02:46:29 +01:00
|
|
|
_mountSourceCode
|
|
|
|
_mountGoCache
|
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
input: _baseImages.goLinter
|
2022-02-11 02:18:57 +01:00
|
|
|
script: contents: "golangci-lint run -v --timeout 5m"
|
|
|
|
}
|
2022-02-24 00:15:44 +01:00
|
|
|
|
2022-03-01 23:48:50 +01:00
|
|
|
// CUE lint
|
2022-02-24 01:21:51 +01:00
|
|
|
cueLint: bash.#Run & {
|
2022-03-01 02:46:29 +01:00
|
|
|
_mountSourceCode
|
|
|
|
|
2022-02-24 00:15:44 +01:00
|
|
|
input: _baseImages.cue
|
|
|
|
script: contents: #"""
|
2022-02-24 04:14:04 +01:00
|
|
|
# Format the cue code
|
2022-02-24 00:15:44 +01:00
|
|
|
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s
|
2022-02-24 04:14:04 +01:00
|
|
|
# Check that all formatted files where committed
|
|
|
|
test -z $(git status -s . | grep -e '^ M' | grep .cue | cut -d ' ' -f3)
|
2022-02-24 00:15:44 +01:00
|
|
|
"""#
|
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
}
|