2022-02-10 05:48:22 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-02-24 00:15:44 +01:00
|
|
|
"dagger.io/dagger"
|
2022-04-01 04:21:54 +02:00
|
|
|
|
2022-02-10 05:48:22 +01:00
|
|
|
"universe.dagger.io/bash"
|
2022-04-01 04:21:54 +02:00
|
|
|
"universe.dagger.io/alpine"
|
|
|
|
"universe.dagger.io/docker"
|
|
|
|
"universe.dagger.io/go"
|
|
|
|
"universe.dagger.io/go/golangci"
|
2022-02-10 05:48:22 +01:00
|
|
|
)
|
|
|
|
|
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)
|
2022-03-10 01:31:14 +01:00
|
|
|
// Uncomment if running locally on Mac M1 to bypass qemu
|
|
|
|
// platform: "linux/aarch64"
|
|
|
|
platform: "linux/amd64"
|
2022-02-18 05:39:40 +01:00
|
|
|
|
2022-04-01 04:21:54 +02:00
|
|
|
client: filesystem: "../": read: exclude: [
|
|
|
|
"ci",
|
|
|
|
"**/node_modules",
|
|
|
|
"cmd/dagger/dagger",
|
|
|
|
"cmd/dagger/dagger-debug",
|
|
|
|
]
|
|
|
|
client: filesystem: "./build": write: contents: actions.build.output
|
2022-02-10 05:48:22 +01:00
|
|
|
|
|
|
|
actions: {
|
2022-04-01 04:21:54 +02:00
|
|
|
_source: client.filesystem["../"].read.contents
|
|
|
|
|
|
|
|
// FIXME: this can be removed once `go` supports built-in VCS info
|
|
|
|
version: {
|
|
|
|
_image: alpine.#Build & {
|
|
|
|
packages: bash: _
|
|
|
|
packages: curl: _
|
|
|
|
packages: git: _
|
2022-02-18 05:39:40 +01:00
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
|
2022-04-01 04:21:54 +02:00
|
|
|
_revision: bash.#Run & {
|
|
|
|
input: _image.output
|
|
|
|
workdir: "/src"
|
|
|
|
mounts: source: {
|
|
|
|
dest: "/src"
|
|
|
|
contents: _source
|
|
|
|
}
|
|
|
|
|
|
|
|
script: contents: #"""
|
|
|
|
printf "$(git rev-parse --short HEAD)" > /revision
|
|
|
|
"""#
|
|
|
|
export: files: "/revision": string
|
2022-03-01 02:46:29 +01:00
|
|
|
}
|
2022-02-11 02:18:57 +01:00
|
|
|
|
2022-04-01 04:21:54 +02:00
|
|
|
output: _revision.export.files["/revision"]
|
|
|
|
}
|
2022-03-01 02:46:29 +01:00
|
|
|
|
2022-04-01 04:21:54 +02:00
|
|
|
build: go.#Build & {
|
|
|
|
source: _source
|
|
|
|
package: "./cmd/dagger/"
|
|
|
|
os: client.platform.os
|
|
|
|
arch: client.platform.arch
|
2022-03-01 02:46:29 +01:00
|
|
|
|
2022-04-01 04:21:54 +02:00
|
|
|
ldflags: "-s -w -X go.dagger.io/dagger/version.Revision=\(version.output)"
|
2022-02-10 05:48:22 +01:00
|
|
|
|
2022-02-11 01:09:08 +01:00
|
|
|
env: {
|
2022-03-01 23:48:50 +01:00
|
|
|
CGO_ENABLED: "0"
|
|
|
|
// Makes sure the linter and unit tests complete before starting the build
|
2022-04-01 04:21:54 +02:00
|
|
|
// "__depends_lint": "\(goLint.exit)"
|
|
|
|
// "__depends_tests": "\(goTest.exit)"
|
2022-02-11 01:09:08 +01:00
|
|
|
}
|
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
|
2022-04-01 04:21:54 +02:00
|
|
|
test: go.#Test & {
|
|
|
|
// container: image: _goImage.output
|
|
|
|
source: _source
|
|
|
|
package: "./..."
|
2022-03-01 23:48:50 +01:00
|
|
|
|
2022-04-01 04:21:54 +02:00
|
|
|
// FIXME: doesn't work with CGO_ENABLED=0
|
|
|
|
// command: flags: "-race": true
|
2022-03-01 02:46:29 +01:00
|
|
|
|
2022-04-01 04:21:54 +02:00
|
|
|
env: {
|
|
|
|
// FIXME: removing this complains about lack of gcc
|
|
|
|
CGO_ENABLED: "0"
|
|
|
|
}
|
2022-02-11 02:18:57 +01:00
|
|
|
}
|
2022-02-24 00:15:44 +01:00
|
|
|
|
2022-04-01 04:21:54 +02:00
|
|
|
lint: {
|
|
|
|
go: golangci.#Lint & {
|
|
|
|
source: _source
|
|
|
|
version: "1.45"
|
|
|
|
}
|
|
|
|
|
|
|
|
cue: docker.#Build & {
|
|
|
|
steps: [
|
|
|
|
alpine.#Build & {
|
|
|
|
packages: bash: _
|
|
|
|
packages: curl: _
|
|
|
|
packages: git: _
|
|
|
|
},
|
|
|
|
|
|
|
|
docker.#Copy & {
|
|
|
|
contents: _source
|
|
|
|
source: "go.mod"
|
|
|
|
dest: "go.mod"
|
|
|
|
},
|
|
|
|
|
|
|
|
// Install CUE
|
|
|
|
bash.#Run & {
|
|
|
|
script: contents: #"""
|
|
|
|
export CUE_VERSION="$(grep cue ./go.mod | cut -d' ' -f2 | head -1 | sed -E 's/\.[[:digit:]]\.[[:alnum:]]+-[[:alnum:]]+$//')"
|
|
|
|
export CUE_TARBALL="cue_${CUE_VERSION}_linux_amd64.tar.gz"
|
|
|
|
echo "Installing cue version $CUE_VERSION"
|
|
|
|
curl -L "https://github.com/cue-lang/cue/releases/download/${CUE_VERSION}/${CUE_TARBALL}" | tar zxf - -C /usr/local/bin
|
|
|
|
cue version
|
|
|
|
"""#
|
|
|
|
},
|
|
|
|
|
|
|
|
// CACHE: copy only *.cue files
|
|
|
|
docker.#Copy & {
|
|
|
|
contents: _source
|
|
|
|
include: ["*.cue"]
|
|
|
|
dest: "/cue"
|
|
|
|
},
|
|
|
|
|
|
|
|
// LINT
|
|
|
|
bash.#Run & {
|
|
|
|
workdir: "/cue"
|
|
|
|
script: contents: #"""
|
|
|
|
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -t -n 1 -P 8 cue fmt -s
|
|
|
|
test -z "$(git status -s . | grep -e "^ M" | grep "\.cue" | cut -d ' ' -f3 | tee /dev/stderr)"
|
|
|
|
"""#
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
2022-02-24 00:15:44 +01:00
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
}
|