2022-02-10 05:48:22 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-02-11 01:09:08 +01:00
|
|
|
"strings"
|
|
|
|
|
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-02-10 05:48:22 +01:00
|
|
|
inputs: {
|
|
|
|
params: {
|
2022-02-11 01:09:08 +01:00
|
|
|
// FIXME: until we support a better way
|
2022-02-11 02:18:57 +01:00
|
|
|
os: string | *"darwin"
|
2022-02-11 01:09:08 +01:00
|
|
|
arch: string | *"amd64"
|
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
// FIXME: implement condition actions using params until we have a
|
|
|
|
// better way to select specific actions
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
directories: {
|
|
|
|
// dagger repository
|
|
|
|
source: path: "../"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 01:21:51 +01:00
|
|
|
outputs: directories: "go binaries": {
|
|
|
|
contents: actions.build.export.directories["/build"]
|
|
|
|
dest: "./build"
|
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
|
|
|
|
actions: {
|
2022-02-18 05:39:40 +01:00
|
|
|
_goModCache: "go mod cache": {
|
|
|
|
dest: "/gomodcache"
|
2022-02-24 00:15:44 +01:00
|
|
|
contents: dagger.#CacheDir & {
|
2022-02-18 05:39:40 +01:00
|
|
|
id: "go mod cache"
|
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
_baseImages: #Images
|
2022-02-17 20:58:31 +01:00
|
|
|
|
2022-02-24 00:15:44 +01:00
|
|
|
_sourceCode: "dagger source code": {
|
2022-02-11 02:18:57 +01:00
|
|
|
contents: inputs.directories.source.contents
|
|
|
|
dest: "/usr/src/dagger"
|
|
|
|
}
|
|
|
|
|
2022-02-10 05:48:22 +01:00
|
|
|
build: bash.#Run & {
|
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: {
|
|
|
|
GOMODCACHE: mounts["go mod cache"].dest
|
2022-02-11 02:18:57 +01:00
|
|
|
GOOS: strings.ToLower(inputs.params.os)
|
|
|
|
GOARCH: strings.ToLower(inputs.params.arch)
|
2022-03-01 02:09:33 +01:00
|
|
|
// Makes sure the linter completes before starting the build
|
|
|
|
"__depends": "\(goLint.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-02-11 01:09:08 +01:00
|
|
|
CGO_ENABLED=0 \
|
2022-02-24 00:15:44 +01:00
|
|
|
go build -v -o /build/dagger \
|
|
|
|
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
|
|
|
|
./cmd/dagger/
|
2022-02-10 05:48:22 +01:00
|
|
|
"""#
|
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
workdir: mounts["dagger source code"].dest
|
2022-02-10 05:48:22 +01:00
|
|
|
mounts: {
|
2022-02-24 00:15:44 +01:00
|
|
|
_sourceCode
|
2022-02-18 05:39:40 +01:00
|
|
|
_goModCache
|
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
|
|
|
|
|
|
|
goLint: bash.#Run & {
|
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"
|
|
|
|
workdir: mounts["dagger source code"].dest
|
|
|
|
mounts: {
|
2022-02-24 00:15:44 +01:00
|
|
|
_sourceCode
|
2022-02-18 05:39:40 +01:00
|
|
|
_goModCache
|
2022-02-11 02:18:57 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-24 00:15:44 +01:00
|
|
|
|
2022-02-24 01:21:51 +01:00
|
|
|
cueLint: bash.#Run & {
|
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
|
|
|
"""#
|
|
|
|
workdir: mounts["dagger source code"].dest
|
|
|
|
mounts: {
|
|
|
|
_sourceCode
|
|
|
|
}
|
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
}
|