From 8f88b5b74214badc2090044a8a37d50668f0c830 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 10 Nov 2026 10:57:59 +0000 Subject: [PATCH] ci(woodpecker): build once, keep Go's caches, fetch archied for the canary The same changes as the Actions workflows: a release gate runs `task check dist` and the dist step only packages; canary and promote copy archied out of archied:edge instead of compiling it. The gate and the pull-request check keep Go's module, build and lint caches on the host, in separate directories so a pull request cannot write into the cache a release build reads. Fixes: notes wait for the signed release and carry the prerelease flag; the canary clones with tags, which its rollback needs to diff migrations; release puts HEAD on main before `task release`, which refuses anything else. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01SSgGJ5xH1eDady5kVjcc8x --- .woodpecker/canary.yaml | 30 +++++++++++++++++------ .woodpecker/deploy.yaml | 52 +++++++++++++++++++++------------------- .woodpecker/promote.yaml | 23 ++++++++++++------ .woodpecker/quality.yaml | 9 +++++++ .woodpecker/release.yaml | 3 +++ 5 files changed, 79 insertions(+), 38 deletions(-) diff --git a/.woodpecker/canary.yaml b/.woodpecker/canary.yaml index 98de25331..e5d6edc94 100644 --- a/.woodpecker/canary.yaml +++ b/.woodpecker/canary.yaml @@ -17,10 +17,22 @@ when: # overlapping runs would judge the same release twice. concurrency: 1 +clone: + git: + image: woodpeckerci/plugin-git:2.8.0 + settings: + # A rollback compares the migrations between two release tags, so the + # checkout needs the tags and the trees behind them. + tags: true + partial: false + steps: - name: judge - image: golang:1.27.3-bookworm + image: docker:29-cli + volumes: + - /var/run/docker.sock:/var/run/docker.sock environment: + DOCKER_HOST: unix:///var/run/docker.sock CANARY_URL: from_secret: canary_url CANARY_WINDOW: @@ -33,14 +45,18 @@ steps: - '[ -n "$$CANARY_URL" ] || { echo "repo secret canary_url is not set, so there is no canary to judge"; exit 1; }' - '[ -n "$$ARCHIE_CANARY_TOKEN" ] || { echo "repo secret canary_token is not set, so the canary cannot be reached"; exit 1; }' - '[ -n "$$DEPLOY_TOKEN" ] || { echo "repo secret deploy_token is not set, so the registry cannot be tagged"; exit 1; }' - - go build -tags no_ui -o /tmp/archied ./cmd/archied - # archied reads the registry credentials a docker login would have - # written; this step has no docker CLI, so the file is written directly. + - apk add --no-cache git + # archied reads the registry credentials this login writes. + - printf '%s' "$$DEPLOY_TOKEN" | docker login git.catlow.cloud -u "$$CI_REPO_OWNER" --password-stdin + # The deploy pipeline already built this binary. edge is the newest main + # that passed the gate. - | set -eu - mkdir -p "$$HOME/.docker" - auth=$(printf '%s:%s' "$$CI_REPO_OWNER" "$$DEPLOY_TOKEN" | base64 -w0) - printf '{"auths":{"git.catlow.cloud":{"auth":"%s"}}}\n' "$$auth" > "$$HOME/.docker/config.json" + image=git.catlow.cloud/sam/archied:edge + docker pull -q "$$image" + container=$(docker create "$$image") + docker cp "$$container:/usr/local/bin/archied" /tmp/archied + docker rm "$$container" >/dev/null - | set -eu set -- diff --git a/.woodpecker/deploy.yaml b/.woodpecker/deploy.yaml index 16819776f..ac104fee6 100644 --- a/.woodpecker/deploy.yaml +++ b/.woodpecker/deploy.yaml @@ -24,13 +24,14 @@ when: concurrency: 1 variables: - # The gate and the distribution step both build the dashboard. Anchored here - # rather than written twice, so the digest and the pnpm version can only - # change in one place. + # Only the gate builds the dashboard and the release binaries; later steps + # reuse what it left in the workspace. The Node digest and the pnpm version + # are pinned here. - &node-setup | set -eu apt-get update -qq - apt-get install -y -qq --no-install-recommends xz-utils + # jq reads release.json for `task dist`. + apt-get install -y -qq --no-install-recommends xz-utils jq curl -fsSL -o /tmp/node.tar.xz https://nodejs.org/dist/v24.22.2/node-v24.22.2-linux-x64.tar.xz echo "48cc0e21e048790e54c0cf5749c2725005313d652651c40b7a21feb9697aaf75 /tmp/node.tar.xz" | sha256sum -c - tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 @@ -81,9 +82,15 @@ steps: volumes: - /var/run/docker.sock:/var/run/docker.sock - /var/tmp/woodpecker-archie-gate:/var/tmp/woodpecker-archie-gate + # Module, build and lint caches outlive the step's container; without + # them every pipeline downloads and compiles everything from nothing. + - /var/cache/woodpecker-archie:/cache environment: DOCKER_HOST: unix:///var/run/docker.sock TMPDIR: /var/tmp/woodpecker-archie-gate + GOCACHE: /cache/go-build + GOMODCACHE: /cache/go-mod + GOLANGCI_LINT_CACHE: /cache/golangci-lint commands: - '. "$$CI_WORKSPACE/.git/ci-plan.env"' - '[ "$$RUN" = true ] || { echo "a release tag owns this commit; the tag pipeline publishes it"; exit 0; }' @@ -104,9 +111,18 @@ steps: git branch main HEAD fi fi - - task check TEST_FLAGS=-count=1 + # A release also builds the binaries it ships, in the same task run: the + # dashboard is built once and the tree that passed is the tree that is + # published. dist/ stays in the workspace for the steps below. + - | + set -eu + if [ -n "$$RELEASE_VERSION" ]; then + task check dist TEST_FLAGS=-count=1 VERSION="$$RELEASE_VERSION" + else + task check TEST_FLAGS=-count=1 + fi - git diff --exit-code - - go install golang.org/x/vuln/cmd/govulncheck@latest + - go install golang.org/x/vuln/cmd/govulncheck@v1.9.0 - govulncheck ./... - | set -eu @@ -210,25 +226,10 @@ steps: - '[ -n "$$RELEASE_VERSION" ] || { echo "not a release; no distribution to build"; exit 0; }' - apt-get update -qq - apt-get install -y -qq --no-install-recommends jq zip - - *node-setup - # A subshell: a bare `cd ui` here would leave every later command in this - # step building from the dashboard directory. + # The gate built dist/ from the tree it checked; this only packages it. - | set -eu - ( - cd ui - pnpm install --frozen-lockfile - pnpm run build - ) - - | - set -eu - base=github.com/samcharles93/archie-core - ldflags="-X $${base}/internal/installtype.buildType=binary -X $${base}/internal/buildinfo.Version=$$RELEASE_VERSION -X $${base}/internal/buildinfo.Runtime=$$RELEASE_VERSION -X $${base}/internal/app/agentworker.version=$$RELEASE_VERSION" cmds=$(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json) - mkdir -p dist - for cmd in $$cmds; do - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$$ldflags" -o "dist/$$cmd" "./cmd/$$cmd" - done name="archie-core-archied-v$$RELEASE_VERSION-linux-amd64" mkdir -p "$$name" for cmd in $$cmds; do @@ -277,7 +278,7 @@ steps: - name: notes image: golang:1.27.3-bookworm - depends_on: [dist] + depends_on: [publish] environment: DEPLOY_TOKEN: from_secret: deploy_token @@ -291,6 +292,8 @@ steps: - | set -eu tag="v$$RELEASE_VERSION" + prerelease=false + case "$$RELEASE_VERSION" in *-*) prerelease=true ;; esac notes=$(mktemp) awk -v hdr="## [$$RELEASE_VERSION]" ' index($$0, hdr) == 1 { printing = 1 } @@ -307,7 +310,8 @@ steps: curl -sf -X DELETE -H "$$auth" "$$api/repos/$$repo/releases/tags/$$tag" >/dev/null || true curl -sf -X POST -H "$$auth" -H "Content-Type: application/json" \ -d "$(jq -n --arg tag "$$tag" --arg name "Archie v$$RELEASE_VERSION" --arg body "$(cat "$$notes")" \ - '{tag_name: $$tag, name: $$name, body: $$body, draft: false, prerelease: false}')" \ + --argjson prerelease "$$prerelease" \ + '{tag_name: $$tag, name: $$name, body: $$body, draft: false, prerelease: $$prerelease}')" \ "$$api/repos/$$repo/releases" >/dev/null echo "published release notes for $$tag" # The packages exist under this repository's namespace but are not diff --git a/.woodpecker/promote.yaml b/.woodpecker/promote.yaml index 386824738..8398dc4d6 100644 --- a/.woodpecker/promote.yaml +++ b/.woodpecker/promote.yaml @@ -12,10 +12,16 @@ when: concurrency: 1 +# Promotion reads the canary and the registry, never the repository. +skip_clone: true + steps: - name: promote - image: golang:1.27.3-bookworm + image: docker:29-cli + volumes: + - /var/run/docker.sock:/var/run/docker.sock environment: + DOCKER_HOST: unix:///var/run/docker.sock CANARY_URL: from_secret: canary_url ARCHIE_CANARY_TOKEN: @@ -27,14 +33,17 @@ steps: - '[ -n "$$CANARY_URL" ] || { echo "repo secret canary_url is not set, so there is no canary to read"; exit 1; }' - '[ -n "$$ARCHIE_CANARY_TOKEN" ] || { echo "repo secret canary_token is not set, so the canary cannot be reached"; exit 1; }' - '[ -n "$$DEPLOY_TOKEN" ] || { echo "repo secret deploy_token is not set, so the registry cannot be tagged"; exit 1; }' - - go build -tags no_ui -o /tmp/archied ./cmd/archied - # archied reads the registry credentials a docker login would have - # written; this step has no docker CLI, so the file is written directly. + # archied reads the registry credentials this login writes. + - printf '%s' "$$DEPLOY_TOKEN" | docker login git.catlow.cloud -u "$$CI_REPO_OWNER" --password-stdin + # The deploy pipeline already built this binary. edge is the newest main + # that passed the gate. - | set -eu - mkdir -p "$$HOME/.docker" - auth=$(printf '%s:%s' "$$CI_REPO_OWNER" "$$DEPLOY_TOKEN" | base64 -w0) - printf '{"auths":{"git.catlow.cloud":{"auth":"%s"}}}\n' "$$auth" > "$$HOME/.docker/config.json" + image=git.catlow.cloud/sam/archied:edge + docker pull -q "$$image" + container=$(docker create "$$image") + docker cp "$$container:/usr/local/bin/archied" /tmp/archied + docker rm "$$container" >/dev/null - >- /tmp/archied release canary promote -dashboard "$$CANARY_URL" -version "$$VERSION" diff --git a/.woodpecker/quality.yaml b/.woodpecker/quality.yaml index 728f0650c..d5bee9cb2 100644 --- a/.woodpecker/quality.yaml +++ b/.woodpecker/quality.yaml @@ -21,6 +21,15 @@ clone: steps: - name: check image: golang:1.27.3-bookworm + # Module, build and lint caches outlive the step's container. Pull requests + # get their own directory so they cannot write into the cache a release + # build reads. + volumes: + - /var/cache/woodpecker-archie-pr:/cache + environment: + GOCACHE: /cache/go-build + GOMODCACHE: /cache/go-mod + GOLANGCI_LINT_CACHE: /cache/golangci-lint commands: - go install github.com/go-task/task/v3/cmd/task@v3.48.0 - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(cat .golangci-version) diff --git a/.woodpecker/release.yaml b/.woodpecker/release.yaml index b8aed87cc..35189bfab 100644 --- a/.woodpecker/release.yaml +++ b/.woodpecker/release.yaml @@ -36,6 +36,9 @@ steps: - go install github.com/go-task/task/v3/cmd/task@v3.48.0 - git config user.name "Sam Catlow" - git config user.email "sam@catlow.tech" + # `task release` only cuts from a branch named main, and the clone can + # leave HEAD detached at main's tip. + - git checkout -q -B main - task release RELEASE="$$RELEASE" - | set -eu