# Builds and pushes the archied and archie-agent images to the Gitea # registry on every merge to main, and publishes the distribution zip as a # release on this repository. Gitea Actions reads this .github/workflows/ # directory. name: deploy on: push: branches: [main] tags: ["v*"] # Rapid successive pushes to main (a release commit right after its # preceding fix, say) previously queued a full gate+build for each one, # several minutes apiece, with no caching -- so a burst of pushes left # three deploys racing in parallel for the same runner capacity. Only the # last one's images matter (each job pushes its image tags), so cancel a # superseded run rather than let it fight for resources it can't use. # # Keyed on the commit, not github.ref: a release push lands main and its # tag in one go, both pointing at the same commit -- on.push matches # branches and tags both, so a single release push otherwise fires # redundant builds of identical content that a ref-keyed group can't see # as the same work. concurrency: group: deploy-${{ github.sha }} cancel-in-progress: true permissions: contents: read packages: write jobs: gate: runs-on: self-hosted outputs: archied_version: ${{ steps.release_tag.outputs.archied_version }} steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # Read the release from the commit, not from github.ref. One release # push carries main and both tags at the same SHA, and only one of # those refs survives the concurrency group, so a ref-derived version # is whatever won the race. The tag at HEAD is the same either way. - 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 - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod # The self-hosted runner keeps the Go caches on disk between jobs, and # archiving them for the Actions cache takes minutes. 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: "22" - 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 # ripgrep and the unprivileged-userns sysctl are provisioned on the host. # A self-hosted runner should not need sudo, and installing a package on # every run is not the gate's job. - name: Verify unprivileged user namespaces run: unshare --user --map-root-user --net true # The gate's uncached `go test ./...` runs the Docker-backed tests that # -short skips, and those start a container from alpine:3. A fresh runner # has no such image, so the suite failed on "No such image: alpine:3". - name: Pull test container images run: docker pull alpine:3 # One definition of the gate, in the Taskfile. TEST_FLAGS is the one # difference: the release runs the whole suite, uncached and including # the Docker-backed tests -short skips. The diff after it asserts # `task fmt` changed nothing. - name: Quality gate run: | task check TEST_FLAGS=-count=1 git diff --exit-code - name: Vulnerability scan run: | go install golang.org/x/vuln/cmd/govulncheck@latest 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-; :latest keeps naming the newest promoted release." fi archied-image: needs: gate runs-on: self-hosted steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # Deliberately NOT `github.sha`. On a tag push that is the ref's OBJECT id, # and every release tag in this repo is annotated, so it names a tag object # that cannot be checked out. Dereference it to the commit. - name: Resolve the commit this ref points at id: commit run: | sha="$(git rev-parse "${GITHUB_REF}^{commit}")" echo "sha=$sha" >> "$GITHUB_OUTPUT" echo "short=${sha:0:12}" >> "$GITHUB_OUTPUT" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to the Gitea registry run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin - name: Resolve component versions id: versions run: | # One release stream: a `v*` tag names both components' versions. RELEASE_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -1)" GATEWAY_VERSION="${RELEASE_TAG#v}" RUNTIME_VERSION="${RELEASE_TAG#v}" # `dev+` is what a build that is NOT a release reports, and it is # honest now that such a build no longer publishes :latest: the version # names the commit it came from, and the sha- tag makes it # restorable. Before, this same string reached :latest minutes after a # release and made the release's own stamping read as dev # (archie-core-i5nb). (On an untagged push GITHUB_SHA IS the commit — # the tag case is handled by the dereference above.) [ -n "$GATEWAY_VERSION" ] || GATEWAY_VERSION="dev+${GITHUB_SHA:0:12}" [ -n "$RUNTIME_VERSION" ] || RUNTIME_VERSION="dev+${GITHUB_SHA:0:12}" echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT" echo "gateway=$GATEWAY_VERSION" >> "$GITHUB_OUTPUT" echo "runtime=$RUNTIME_VERSION" >> "$GITHUB_OUTPUT" # :latest names the newest PROMOTED release, so a release publishes # :v and canary promotion moves :latest to it. A push to # main publishes :edge (mutable, newest main) and sha- # (immutable), so an ordinary commit never overwrites a release's # stamping. # # `if` blocks rather than `[ -n "$X" ] && echo`: the latter returns # non-zero when the test fails, and these steps run under `set -e`. { echo "archied_tags<> "$GITHUB_OUTPUT" - name: Build and push archied uses: docker/build-push-action@v6 with: context: . file: Dockerfile.archied push: true tags: ${{ steps.versions.outputs.archied_tags }} build-args: | GATEWAY_VERSION=${{ steps.versions.outputs.gateway }} RUNTIME_VERSION=${{ steps.versions.outputs.runtime }} cache-from: type=gha,scope=archied cache-to: type=gha,mode=max,scope=archied agent-image: outputs: agent_digest: ${{ steps.agent.outputs.digest }} needs: gate runs-on: self-hosted steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # Annotated tags: dereference to the commit, as archied-image does. - name: Resolve the commit this ref points at id: commit run: | sha="$(git rev-parse "${GITHUB_REF}^{commit}")" echo "sha=$sha" >> "$GITHUB_OUTPUT" echo "short=${sha:0:12}" >> "$GITHUB_OUTPUT" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to the Gitea registry run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u "${{ github.actor }}" --password-stdin - name: Resolve runtime version id: versions run: | RELEASE_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -1)" RUNTIME_VERSION="${RELEASE_TAG#v}" echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT" echo "runtime=$RUNTIME_VERSION" >> "$GITHUB_OUTPUT" - name: Build and push archie-agent id: agent if: steps.versions.outputs.release_tag != '' uses: docker/build-push-action@v6 with: context: . file: Dockerfile push: true tags: | git.catlow.cloud/sam/archie-agent:${{ steps.versions.outputs.release_tag }} git.catlow.cloud/sam/archie-agent:sha-${{ steps.commit.outputs.sha }} build-args: | RUNTIME_VERSION=${{ steps.versions.outputs.runtime }} cache-from: type=gha,scope=archie-agent cache-to: type=gha,mode=max,scope=archie-agent # Packages every host-run binary (archied, archie-gateway, # archie-state-store, archie-ui, archie-messaging) as a # linux/amd64 zip for a # non-Docker install, plus archie-agent: it has no unit, but a Kit run # mounts it from archied's directory, so a host without it parks them. # It waits only for the agent image, whose digest # release.json pins. dist-zip: needs: [gate, agent-image] # Not gated on github.ref. A release is pushed as main plus both tags at # one SHA, the concurrency group below collapses those into a single run, # and the survivor is whichever ref happened to start last -- for # v1.23.0 that was refs/heads/main, so this job was skipped and no zip # was ever produced. Resolve the tag from the commit instead of trusting # the ref that won the race, and skip only when there is genuinely no # archied tag at HEAD. if: needs.gate.outputs.archied_version != '' runs-on: self-hosted steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod # The self-hosted runner keeps the Go caches on disk between jobs, and # archiving them for the Actions cache takes minutes. 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" # archied and archie-ui embed the dashboard. - name: Build the dashboard working-directory: ui run: | pnpm install --frozen-lockfile pnpm run build - name: Resolve archied version id: version run: echo "version=${{ needs.gate.outputs.archied_version }}" >> "$GITHUB_OUTPUT" - name: Build linux/amd64 binaries env: GOOS: linux GOARCH: amd64 CGO_ENABLED: "0" run: | set -e # Every process in the documented deployment ships in the zip, and # every one of them carries the archied version it was cut from: # they are one release, and an operator matching binaries by eye # needs each to say so. # # That claim is load-bearing and this list is the whole of it: the # v1.30.0 messaging extraction moved Telegram/email/webhook out of # archied and nothing added archie-messaging here, so a host install # ran on with a dead Telegram bot and no error anywhere # (archie-core-1c01). TestDistZipShipsEveryHostCommand fails if this # list and the copy list below stop matching the commands in cmd/. ldflags="-X github.com/samcharles93/archie-core/internal/installtype.buildType=binary -X github.com/samcharles93/archie-core/internal/buildinfo.Version=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/buildinfo.Runtime=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/app/agentworker.version=${{ steps.version.outputs.version }}" mkdir -p dist # Units first, then the binaries that run beside them without one. # The agentworker stamp only lands in archie-agent; the linker # ignores -X for a symbol a binary does not import. for cmd in $(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json); do go build -ldflags "$ldflags" -o "dist/$cmd" "./cmd/$cmd" done - 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" # README.md doesn't exist yet in this repo; include it once it does # rather than fail the release on its absence. [ -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 # Installs and updates take a release from the signed artifact in the # registry, so this is what publishes it: the statement signed with # RELEASE_SIGNING_KEY and the zip, tagged v and next. stable # moves only when canary.yml promotes it. - 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" # The release page carries this version's changelog section, the # release's own reviewed prose; the signed statement links to it. - 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 }}" 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" # Idempotent: a re-run replaces the release on the tag. 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")" \ '{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')" \ "$api/repos/$repo/releases" >/dev/null echo "published release notes for $tag" # The canary host follows the `next` channel. canary.yml then judges the # release installed on the canary and decides whether it is promoted to # stable or the canary is rolled back. The start is queue-safe: a release # published while the canary still judges a newer one is queued behind # it and picked up by the next check, so the running window isn't # restarted under a different release. - 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 }}" # A Gitea package belongs to its owner, not a repository, so the ones this # workflow publishes are linked here. Linking is per package and a no-op # once done, so an already linked package is not an error. - 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