435 lines
19 KiB
YAML
435 lines
19 KiB
YAML
# 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: ["archied/v*", "archie/v*", "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 'archied/v*' --list 'v*' | sed -e 's|^archied/v||' -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
|
|
|
|
- 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. This step used to inline
|
|
# its own list, which drifted weaker than `task check`: it ran no
|
|
# db:check, news:check or ui:check, so a release could ship stale
|
|
# generated SQL, a stale ui/dist, or release notes that disagree with
|
|
# CHANGELOG.md. It also ran the dashboard suite here rather than in the
|
|
# gate, where test:ui runs it with the type check. 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
|
|
}
|
|
;;
|
|
archied/v* | archie/v*)
|
|
# Legacy per-component tags. History is not re-tagged, and the
|
|
# merged CHANGELOG.md carries every component's versions, so the
|
|
# section is found there rather than in a component file.
|
|
ver="${tag#*/v}"
|
|
echo " legacy 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. Run: task release:prepare VERSION=<ver>"
|
|
echo "edit the generated notes, then: task release VERSION=<ver>"
|
|
exit 1
|
|
fi
|
|
if ! git tag --points-at HEAD | grep -qE '^(v[0-9]|archied/v|archie/v)' ; then
|
|
echo "This commit is not a release, so the images are published as :edge and sha-<sha>; :latest keeps naming the newest 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 — measured, 80 of 80
|
|
# `archied/v*` and `archie/v*` tags are tag objects — so it names something
|
|
# that cannot be checked out. `archied/v1.36.0` is an instance: it points at
|
|
# 6720bc42 (a tag object) and dereferences to commit c25f8d39. The producer
|
|
# is right to create annotated tags; the consumer stops guessing.
|
|
- 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: |
|
|
GATEWAY_TAG="$(git tag --points-at HEAD --list 'archied/v*' | sort -V | tail -1)"
|
|
RUNTIME_TAG="$(git tag --points-at HEAD --list 'archie/v*' | sort -V | tail -1)"
|
|
# One release stream: a `v*` tag covers the whole release, so it names
|
|
# both components' versions. Legacy per-component tags still win where
|
|
# they exist, because history is not re-tagged.
|
|
RELEASE_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -1)"
|
|
GATEWAY_VERSION="${GATEWAY_TAG#archied/}"
|
|
RUNTIME_VERSION="${RUNTIME_TAG#archie/}"
|
|
[ -n "$GATEWAY_VERSION" ] || GATEWAY_VERSION="${RELEASE_TAG#v}"
|
|
[ -n "$RUNTIME_VERSION" ] || RUNTIME_VERSION="${RELEASE_TAG#v}"
|
|
# `dev+<sha>` 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-<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}"
|
|
# Keep the raw tag presence separate from the version fallback: a
|
|
# LEGACY gateway-only release (archied/v* and no archie/v*) must not
|
|
# rebuild the runtime image as dev. A one-stream `v*` release is not
|
|
# gateway-only -- one version covers the runtime too -- so it does
|
|
# rebuild it, and release_tag is what tells the two apart.
|
|
echo "gateway_tag=$GATEWAY_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "runtime_tag=$RUNTIME_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "gateway=$GATEWAY_VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "runtime=$RUNTIME_VERSION" >> "$GITHUB_OUTPUT"
|
|
# :latest names the newest RELEASE, so only a commit that IS one
|
|
# publishes it. A push to main publishes :edge (mutable, newest main)
|
|
# and sha-<sha> (immutable) instead. That is what stops a release's
|
|
# :latest stamping from being overwritten minutes later by the next
|
|
# ordinary commit, which left a host reporting dev and made the update
|
|
# path unable to tell current from stale (archie-core-i5nb).
|
|
#
|
|
# `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<<EOF"
|
|
if [ -n "$RELEASE_TAG" ]; then
|
|
echo "git.catlow.cloud/sam/archied:latest"
|
|
fi
|
|
echo "git.catlow.cloud/sam/archied:edge"
|
|
echo "git.catlow.cloud/sam/archied:sha-${{ steps.commit.outputs.sha }}"
|
|
echo "EOF"
|
|
} >> "$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: |
|
|
RUNTIME_TAG="$(git tag --points-at HEAD --list 'archie/v*' | sort -V | tail -1)"
|
|
RELEASE_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -1)"
|
|
RUNTIME_VERSION="${RUNTIME_TAG#archie/}"
|
|
[ -n "$RUNTIME_VERSION" ] || RUNTIME_VERSION="${RELEASE_TAG#v}"
|
|
echo "runtime_tag=$RUNTIME_TAG" >> "$GITHUB_OUTPUT"
|
|
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.runtime_tag != '' || steps.versions.outputs.release_tag != ''
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
tags: |
|
|
git.catlow.cloud/sam/archie-agent:latest
|
|
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
|
|
|
|
- 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<version>, next, and stable
|
|
# unless it is a prerelease.
|
|
- 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"
|