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
|
2022-03-01 02:46:29 +01:00
|
|
|
source: {
|
|
|
|
path: "../"
|
|
|
|
exclude: ["./ci"]
|
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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": {
|
|
|
|
contents: inputs.directories.source.contents
|
|
|
|
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-02-10 05:48:22 +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-01 02:46:29 +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-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-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-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
|
|
|
}
|
|
|
|
}
|