This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/ci.cue
Sam Alba bc17cef74a ci: run go unit tests from the dagger plan
Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
2022-04-19 15:41:40 -07:00

100 lines
1.9 KiB
CUE

package main
import (
"dagger.io/dagger"
"universe.dagger.io/bash"
"universe.dagger.io/alpine"
"universe.dagger.io/go"
"github.com/dagger/dagger/ci/golangci"
"github.com/dagger/dagger/ci/shellcheck"
"github.com/dagger/dagger/ci/markdownlint"
"github.com/dagger/dagger/ci/cue"
)
dagger.#Plan & {
client: filesystem: ".": read: exclude: [
"bin",
"**/node_modules",
"cmd/dagger/dagger",
"cmd/dagger/dagger-debug",
]
client: filesystem: "./bin": write: contents: actions.build.output
actions: {
_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: _
}
_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
}
output: _revision.export.files["/revision"]
}
build: go.#Build & {
source: _source
package: "./cmd/dagger/"
os: client.platform.os
arch: client.platform.arch
ldflags: "-s -w -X go.dagger.io/dagger/version.Revision=\(version.output)"
env: {
CGO_ENABLED: "0"
// Makes sure the linter and unit tests complete before starting the build
// "__depends_lint": "\(goLint.exit)"
// "__depends_tests": "\(goTest.exit)"
}
}
// Go unit tests
test: go.#Test & {
// container: image: _goImage.output
source: _source
package: "./..."
command: flags: "-race": true
}
lint: {
go: golangci.#Lint & {
source: _source
version: "1.45"
}
shell: shellcheck.#Lint & {
source: _source
}
markdown: markdownlint.#Lint & {
source: _source
files: ["./docs", "README.md"]
}
"cue": cue.#Lint & {
source: _source
}
}
}
}