diff --git a/.github/workflows/dagger-ci.yml b/.github/workflows/dagger-ci.yml new file mode 100644 index 00000000..03d3f90b --- /dev/null +++ b/.github/workflows/dagger-ci.yml @@ -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 diff --git a/ci/.gitignore b/ci/.gitignore new file mode 100644 index 00000000..a007feab --- /dev/null +++ b/ci/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 00000000..0ad8a3d7 --- /dev/null +++ b/ci/README.md @@ -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 diff --git a/ci/cue.mod/module.cue b/ci/cue.mod/module.cue new file mode 100644 index 00000000..b57d0104 --- /dev/null +++ b/ci/cue.mod/module.cue @@ -0,0 +1 @@ +module: "" \ No newline at end of file diff --git a/ci/cue.mod/pkg/dagger.io b/ci/cue.mod/pkg/dagger.io new file mode 120000 index 00000000..61c69ed9 --- /dev/null +++ b/ci/cue.mod/pkg/dagger.io @@ -0,0 +1 @@ +../../../pkg/dagger.io \ No newline at end of file diff --git a/ci/cue.mod/pkg/universe.dagger.io b/ci/cue.mod/pkg/universe.dagger.io new file mode 120000 index 00000000..9b1eece6 --- /dev/null +++ b/ci/cue.mod/pkg/universe.dagger.io @@ -0,0 +1 @@ +../../../pkg/universe.dagger.io \ No newline at end of file diff --git a/ci/images.cue b/ci/images.cue new file mode 100644 index 00000000..6e2296f7 --- /dev/null +++ b/ci/images.cue @@ -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" + }, + ] + } + } +} diff --git a/ci/main.cue b/ci/main.cue new file mode 100644 index 00000000..a80281fa --- /dev/null +++ b/ci/main.cue @@ -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) + """# + } + } +}