Files
archie/.github/workflows/deploy.yml
T
sam 1b53c5787e ci(deploy): build the release binaries once, in the gate
A release gate runs `task check dist`, uploads dist/, and dist-zip packages
that instead of installing Go and Node and compiling the tree again.

plan resolves the commit and version once for the image jobs. agent-image is
skipped outside a release. dist-zip waits for archied-image. The image jobs
share one builder that is never removed, so the Dockerfiles' cache mounts
survive between runs.

Also: Node 24 in the gate like everywhere else, govulncheck pinned, and the
release notes carry the prerelease flag.
2026-11-10 10:56:55 +00:00

344 lines
13 KiB
YAML

name: deploy
on:
push:
branches: [main]
tags: ["v*"]
concurrency:
group: ${{ startsWith(github.ref, 'refs/tags/') && format('deploy-release-{0}', github.sha) || format('deploy-{0}', github.ref) }}
cancel-in-progress: true
permissions:
contents: read
packages: write
jobs:
plan:
runs-on: self-hosted
outputs:
archied_version: ${{ steps.release_tag.outputs.archied_version }}
run: ${{ steps.release_tag.outputs.run }}
sha: ${{ steps.release_tag.outputs.sha }}
component: ${{ steps.release_tag.outputs.component }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve archied tag at HEAD
id: release_tag
run: |
version="$(git tag --points-at HEAD --list 'v*' | sed -e 's|^v||' | sort -V | tail -1)"
echo "archied_version=$version" >> "$GITHUB_OUTPUT"
if [ -n "$version" ]; then
echo "archied release at HEAD: $version"
else
echo "no release tag at HEAD; distribution zip will be skipped"
fi
# An annotated tag makes GITHUB_SHA the tag object, so the commit is
# resolved from the ref: image tags pin it.
sha="$(git rev-parse "${GITHUB_REF}^{commit}")"
echo "sha=$sha" >> "$GITHUB_OUTPUT"
# A release reports its version; any other build of main names its commit.
echo "component=${version:-dev+${sha:0:12}}" >> "$GITHUB_OUTPUT"
run=true
case "$GITHUB_REF" in
refs/tags/*) ;;
*)
if [ -n "$version" ]; then
run=false
echo "the v$version tag push runs this commit; skipping the branch run"
fi
;;
esac
echo "run=$run" >> "$GITHUB_OUTPUT"
gate:
needs: plan
if: needs.plan.outputs.run == 'true'
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- uses: pnpm/action-setup@v4
with:
package_json_file: ui/package.json
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: "24"
- name: Install quality tools
run: |
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(cat .golangci-version)
go install mvdan.cc/gofumpt@v0.11.0
go install github.com/go-task/task/v3/cmd/task@v3.48.0
- name: Install protobuf tools
run: bash tools/proto.sh install
- name: Ensure contract baseline ref
run: |
if ! git show-ref --verify --quiet refs/heads/main; then
git branch main origin/main
fi
- name: Verify unprivileged user namespaces
run: unshare --user --map-root-user --net true
- name: Pull test container images
run: docker pull alpine:3
- name: Quality gate
env:
RELEASE_VERSION: ${{ needs.plan.outputs.archied_version }}
run: |
# 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.
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
- name: Vulnerability scan
run: |
go install golang.org/x/vuln/cmd/govulncheck@v1.9.0
govulncheck ./...
- name: Release tags must match changelogs
run: |
set -e
fail=0
for tag in $(git tag --points-at HEAD); do
case "$tag" in
v*)
ver="${tag#v}"
echo " release tag $tag -> looking for [$ver] in CHANGELOG.md"
grep -q "^## \\[$ver\\]" CHANGELOG.md || {
echo " FAIL: CHANGELOG.md has no [$ver] section"
fail=1
}
;;
esac
done
if [ $fail -ne 0 ]; then
echo
echo "A release tag points at this commit but its changelog does not"
echo "describe that version. Cut releases with the release workflow."
exit 1
fi
if ! git tag --points-at HEAD | grep -qE '^v[0-9]' ; then
echo "This commit isn't a release, so the images are published as :edge and sha-<sha>; :latest keeps naming the newest promoted release."
fi
- name: Package the release binaries
if: needs.plan.outputs.archied_version != ''
# tar keeps the executable bit, which an uploaded artifact drops.
run: tar -cf release-binaries.tar dist
- name: Upload the release binaries
if: needs.plan.outputs.archied_version != ''
uses: actions/upload-artifact@v4
with:
name: release-binaries
path: release-binaries.tar
if-no-files-found: error
retention-days: 1
archied-image:
needs: [plan, gate]
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# One named builder that is never removed, so the Dockerfiles' cache
# mounts are still there on the next run. Removing it at the end of
# a job would take it from under another run that is building.
name: archie-ci
cleanup: false
- name: Log in to the Gitea registry
run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin
- name: Build and push archied
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.archied
push: true
# The first line is empty for a build of main; empty lines are ignored.
tags: |
${{ needs.plan.outputs.archied_version != '' && format('git.catlow.cloud/sam/archied:v{0}', needs.plan.outputs.archied_version) || '' }}
git.catlow.cloud/sam/archied:edge
git.catlow.cloud/sam/archied:sha-${{ needs.plan.outputs.sha }}
build-args: |
GATEWAY_VERSION=${{ needs.plan.outputs.component }}
RUNTIME_VERSION=${{ needs.plan.outputs.component }}
cache-from: type=gha,scope=archied
cache-to: type=gha,mode=max,scope=archied
agent-image:
needs: [plan, gate]
# The agent image is only published with a release.
if: needs.plan.outputs.run == 'true' && needs.plan.outputs.archied_version != ''
outputs:
agent_digest: ${{ steps.agent.outputs.digest }}
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# One named builder that is never removed, so the Dockerfiles' cache
# mounts are still there on the next run. Removing it at the end of
# a job would take it from under another run that is building.
name: archie-ci
cleanup: false
- name: Log in to the Gitea registry
run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin
- name: Build and push archie-agent
id: agent
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: |
git.catlow.cloud/sam/archie-agent:v${{ needs.plan.outputs.archied_version }}
git.catlow.cloud/sam/archie-agent:sha-${{ needs.plan.outputs.sha }}
build-args: |
RUNTIME_VERSION=${{ needs.plan.outputs.archied_version }}
cache-from: type=gha,scope=archie-agent
cache-to: type=gha,mode=max,scope=archie-agent
dist-zip:
# archied-image is needed so a release never reaches the canary without it.
needs: [plan, gate, archied-image, agent-image]
if: needs.plan.outputs.run == 'true' && needs.plan.outputs.archied_version != ''
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
# The gate built these from the tree it checked; nothing is compiled here.
- name: Download the release binaries
uses: actions/download-artifact@v4
with:
name: release-binaries
- name: Unpack the release binaries
run: tar -xf release-binaries.tar
- name: Resolve archied version
id: version
run: echo "version=${{ needs.plan.outputs.archied_version }}" >> "$GITHUB_OUTPUT"
- name: Assemble distribution zip
id: zip
run: |
set -e
name="archie-core-archied-v${{ steps.version.outputs.version }}-linux-amd64"
mkdir -p "$name"
for cmd in $(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json); do
cp "dist/$cmd" "$name/"
done
cp deployments/INSTRUCTIONS.md CHANGELOG.md "$name/"
digest='${{ needs.agent-image.outputs.agent_digest }}'
test -n "$digest"
jq --arg image "git.catlow.cloud/sam/archie-agent@$digest" '. + {agent_image: $image}' release.json > "$name/release.json"
[ -f README.md ] && cp README.md "$name/"
zip -r "$name.zip" "$name"
echo "name=$name" >> "$GITHUB_OUTPUT"
- name: Upload distribution zip
uses: actions/upload-artifact@v4
with:
name: ${{ steps.zip.outputs.name }}
path: ${{ steps.zip.outputs.name }}.zip
retention-days: 90
- name: Log in to the Gitea registry
run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin
- name: Publish the signed release
env:
ARCHIE_RELEASE_SEED: ${{ secrets.RELEASE_SIGNING_KEY }}
run: |
set -e
version="${{ steps.version.outputs.version }}"
prerelease=false
case "$version" in *-*) prerelease=true ;; esac
./dist/archied release publish -source git.catlow.cloud/sam/archie \
-version "$version" -prerelease="$prerelease" \
-zip "${{ steps.zip.outputs.name }}.zip" \
-agent-image "git.catlow.cloud/sam/archie-agent@${{ needs.agent-image.outputs.agent_digest }}" \
-changelog "https://git.catlow.cloud/sam/archie/releases/tag/v$version"
- name: Publish the Gitea release notes
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: |
set -e
tag="v${{ steps.version.outputs.version }}"
version="${{ steps.version.outputs.version }}"
prerelease=false
case "$version" in *-*) prerelease=true ;; esac
notes="$(mktemp)"
awk -v hdr="## [$version]" '
index($0, hdr) == 1 { printing = 1 }
printing && /^## \[/ && index($0, hdr) != 1 { exit }
printing { print }
' CHANGELOG.md > "$notes"
if ! [ -s "$notes" ]; then
echo "no [$version] section extracted from CHANGELOG.md" >&2
exit 1
fi
api="https://git.catlow.cloud/api/v1"
repo="sam/archie"
auth="Authorization: token $DEPLOY_TOKEN"
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$version" --arg body "$(cat "$notes")" \
--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"
- name: Install the release on the canary
if: vars.CANARY_URL != ''
env:
ARCHIE_CANARY_TOKEN: ${{ secrets.CANARY_TOKEN }}
run: ./dist/archied release canary start -dashboard "${{ vars.CANARY_URL }}" -version "${{ steps.version.outputs.version }}"
- name: Link the packages to this repository
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: |
for name in archied archie-agent archie; do
curl -sS -o /dev/null -X POST -H "Authorization: token $DEPLOY_TOKEN" \
"https://git.catlow.cloud/api/v1/packages/sam/container/$name/-/link/archie" || true
done