Merge pull request #1589 from samalba/ci-poc

Port the dagger Makefile for go build, lint and test
This commit is contained in:
Andrea Luzzardi 2022-03-09 18:24:33 -08:00 committed by GitHub
commit cf0505614f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 241 additions and 0 deletions

44
.github/workflows/dagger-ci.yml vendored Normal file
View File

@ -0,0 +1,44 @@
name: "Dagger CI"
on:
push:
branches: [main]
paths:
- '**.sh'
- '**.bash'
- '**.go'
- '**.cue'
- '**.bats'
- 'Makefile'
- 'go.mod'
- 'go.sum'
- '.github/workflows/dagger-ci.yml'
pull_request:
branches: [main]
paths:
- '**.sh'
- '**.bash'
- '**.go'
- '**.cue'
- '**.bats'
- 'Makefile'
- 'go.mod'
- 'go.sum'
- '.github/workflows/dagger-ci.yml'
env:
DAGGER_LOG_FORMAT: plain
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Dagger CI
uses: dagger/dagger-for-github@v2
with:
workdir: ci
args: do build

1
ci/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/*

7
ci/README.md Normal file
View File

@ -0,0 +1,7 @@
# Dagger CI
WORK IN PROGRESS
This is the home of the new CI
Reference: https://github.com/dagger/dagger/issues/1549

1
ci/cue.mod/module.cue Normal file
View File

@ -0,0 +1 @@
module: ""

1
ci/cue.mod/pkg/dagger.io Symbolic link
View File

@ -0,0 +1 @@
../../../pkg/dagger.io

View File

@ -0,0 +1 @@
../../../pkg/universe.dagger.io

80
ci/images.cue Normal file
View File

@ -0,0 +1,80 @@
package main
import (
"universe.dagger.io/docker"
)
let GoVersion = "1.17"
let GolangCILintVersion = "1.44.0"
let CUEVersion = "0.4.2"
// Base container images used for the CI
#Images: {
// base image to build go binaries
goBuilder: _goBuilder.output
_goBuilder: docker.#Build & {
_packages: ["bash", "git", "alpine-sdk"]
steps: [
docker.#Pull & {
source: "index.docker.io/golang:\(GoVersion)-alpine"
},
for pkg in _packages {
docker.#Run & {
command: {
name: "apk"
args: ["add", pkg]
flags: {
"-U": true
"--no-cache": true
}
}
}
},
]
}
// base image for the Go linter
// https://golangci-lint.run/usage/install/#docker
goLinter: _goLinter.output
_goLinter: docker.#Pull & {
source: "index.docker.io/golangci/golangci-lint:v\(GolangCILintVersion)"
}
// base image for CUE cli + alpine distrib
cue: _cue._alpine.output
_cue: {
_cueBinary: docker.#Pull & {
source: "index.docker.io/cuelang/cue:\(CUEVersion)"
}
_alpine: docker.#Build & {
_packages: ["bash", "git"]
steps: [
docker.#Pull & {
source: "index.docker.io/alpine:3"
},
for pkg in _packages {
docker.#Run & {
command: {
name: "apk"
args: ["add", pkg]
flags: {
"-U": true
"--no-cache": true
}
}
}
},
docker.#Copy & {
// input: _alpine.output
contents: _cueBinary.output.rootfs
source: "/usr/bin/cue"
dest: "/usr/bin/cue"
},
]
}
}
}

106
ci/main.cue Normal file
View File

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