Two defects, both from consuming a ref's object id as if it were a commit.
1. IMMUTABLE IDENTITY. Both images published only `:latest`, so a deployed
artifact could not be traced to a commit or restored. Each build now also
publishes `sha-<commit>`. The commit is 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 (archied/
v1.36.0 points at 6720bc42 and dereferences to e08ff1b4). So the new step
resolves `git rev-parse "${GITHUB_REF}^{commit}"` and the tags use that.
Annotated tags are the right thing for the producer to create; the consumer
stops guessing rather than the tag type being downgraded.
2. NO BARE dev STAMP. `[ -n "$GATEWAY_VERSION" ] || GATEWAY_VERSION=dev` made a
main build indistinguishable from any other, and is why a release's stamping
looked transient: the next commit to main republished :latest as plain `dev`.
The fallback is now `dev+<short sha>`, so an unreleased build is identifiable
and visibly not a release. The warning at the gate now states the consequence
it previously only implied.
Scope: this file only. Nothing else in the checkout was touched.
352 lines
15 KiB
YAML
352 lines
15 KiB
YAML
# Builds and pushes the archied and archie-agent images to GHCR on every
|
|
# merge to main. Mirrors .gitea/workflows/deploy.yml, which remains the
|
|
# production build path against git.catlow.cloud until that's cut over.
|
|
name: deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ["archied/v*", "archie/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 (both jobs push :latest), so cancel a
|
|
# superseded run rather than let it fight for resources it can't use.
|
|
#
|
|
# Keyed on the commit, not github.ref: `git push --follow-tags` pushes
|
|
# main plus both archied/v* and archie/v* tags in one go, and all three
|
|
# refs point at the same commit -- on.push matches branches and tags
|
|
# both, so a single release push otherwise fires three 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: ubuntu-latest
|
|
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*' | sed 's|^archied/v||' | sort -V | tail -1)"
|
|
echo "archied_version=$version" >> "$GITHUB_OUTPUT"
|
|
if [ -n "$version" ]; then
|
|
echo "archied release at HEAD: $version"
|
|
else
|
|
echo "no archied tag at HEAD; distribution zip will be skipped"
|
|
fi
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- 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@v2.13.2
|
|
go install mvdan.cc/gofumpt@v0.11.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: Install ripgrep
|
|
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends ripgrep
|
|
|
|
- name: Quality gate
|
|
run: |
|
|
go fix ./...
|
|
golangci-lint fmt
|
|
git diff --exit-code
|
|
bash tools/proto.sh lint
|
|
bash tools/proto.sh check
|
|
go vet ./...
|
|
golangci-lint run ./...
|
|
go build ./...
|
|
go test ./... -count=1
|
|
|
|
- name: Vulnerability scan
|
|
run: |
|
|
go install golang.org/x/vuln/cmd/govulncheck@latest
|
|
govulncheck ./...
|
|
|
|
# The dashboard suite runs in CI too, or it only ever runs when
|
|
# someone remembers to; the Go steps above never touch it.
|
|
- name: Dashboard tests
|
|
run: |
|
|
npm ci --prefix ui || npm install --prefix ui
|
|
npm test --prefix ui
|
|
|
|
- name: Release tags must match changelogs
|
|
run: |
|
|
set -e
|
|
fail=0
|
|
for tag in $(git tag --points-at HEAD); do
|
|
case "$tag" in
|
|
archied/v*)
|
|
# Strip the "v" too: tags are archied/vX.Y.Z, changelog
|
|
# sections are "## [X.Y.Z]" (see tools/release.sh).
|
|
ver="${tag#archied/v}"
|
|
echo " archied tag $tag -> looking for [$ver] in CHANGELOG.archied.md"
|
|
grep -q "^## \\[$ver\\]" CHANGELOG.archied.md || {
|
|
echo " FAIL: CHANGELOG.archied.md has no [$ver] section"
|
|
fail=1
|
|
}
|
|
;;
|
|
archie/v*)
|
|
ver="${tag#archie/v}"
|
|
echo " archie tag $tag -> looking for [$ver] in CHANGELOG.archie.md"
|
|
grep -q "^## \\[$ver\\]" CHANGELOG.archie.md || {
|
|
echo " FAIL: CHANGELOG.archie.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 'archie' ; then
|
|
echo "::warning ::No release tags at HEAD, so this build publishes :latest for a commit that is not a release. It is stamped dev+<sha> and tagged sha-<sha> so it stays traceable and restorable, but it supersedes the previous release's :latest stamping until the next release is cut."
|
|
fi
|
|
|
|
build-and-push:
|
|
needs: gate
|
|
runs-on: ubuntu-latest
|
|
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 GHCR
|
|
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -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)"
|
|
GATEWAY_VERSION="${GATEWAY_TAG#archied/}"
|
|
RUNTIME_VERSION="${RUNTIME_TAG#archie/}"
|
|
# Not a bare `dev`. A literal dev tells an operator nothing about which
|
|
# build they are running, and it is what made a release's stamping look
|
|
# transient: the next commit to main republished :latest as `dev`. The
|
|
# commit is appended so a main build is identifiable and is visibly not
|
|
# a release. (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:
|
|
# gateway-only releases must not rebuild the runtime image as dev.
|
|
echo "gateway_tag=$GATEWAY_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "runtime_tag=$RUNTIME_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "gateway=$GATEWAY_VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "runtime=$RUNTIME_VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and push archied
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: Dockerfile.archied
|
|
push: true
|
|
tags: |
|
|
ghcr.io/samcharles93/archied:latest
|
|
ghcr.io/samcharles93/archied:sha-${{ steps.commit.outputs.sha }}
|
|
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
|
|
|
|
- name: Build and push archie-agent
|
|
if: steps.versions.outputs.runtime_tag != ''
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
tags: |
|
|
ghcr.io/samcharles93/archie-agent:latest
|
|
ghcr.io/samcharles93/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, archie-playbooks) as a
|
|
# linux/amd64 zip for a
|
|
# non-Docker install. Independent of build-and-push: it never touches the
|
|
# archied/archie-agent image jobs, and a gateway-only release (no
|
|
# archie/v* tag) still produces this zip -- it's keyed to the archied tag
|
|
# alone. archie-agent is deliberately excluded: it only ever runs inside
|
|
# the Docker image build-and-push already publishes, never as a host
|
|
# binary (archie-core-8cda.4.7.1).
|
|
dist-zip:
|
|
needs: gate
|
|
# 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: ubuntu-latest
|
|
# Least privilege: the workflow default is contents:read, and only this
|
|
# job needs to write, to create the Release and attach the zip to it.
|
|
permissions:
|
|
contents: write
|
|
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/app/archied.gatewayVersion=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/installtype.buildType=binary -X github.com/samcharles93/archie-core/internal/buildinfo.Version=${{ steps.version.outputs.version }}"
|
|
mkdir -p dist
|
|
for cmd in archied archie-gateway archie-state-store archie-ui archie-messaging archie-playbooks; 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"
|
|
cp dist/archied dist/archie-gateway dist/archie-state-store dist/archie-ui dist/archie-messaging dist/archie-playbooks "$name/"
|
|
cp deployments/INSTRUCTIONS.md CHANGELOG.md CHANGELOG.archied.md CHANGELOG.archie.md "$name/"
|
|
# 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
|
|
|
|
# A Release is what an operator can actually download from; the
|
|
# artifact above is reachable only from the run's page, behind an
|
|
# Actions login, and expires after 90 days. Until this step existed the
|
|
# zip was produced and then stranded -- the only Release on this repo
|
|
# (archied/v1.22.0) was created by hand and carries no asset at all.
|
|
#
|
|
# Attached to the *archied* tag because the zip is named and versioned
|
|
# for archied, and `--follow-tags` pushes both tags at one commit.
|
|
# --generate-notes is deliberately not used: the changelog section is
|
|
# the release's own reviewed prose, and the tag/changelog gate above
|
|
# already guarantees it describes this version.
|
|
- name: Publish GitHub Release with the distribution zip
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
set -e
|
|
tag="archied/v${{ steps.version.outputs.version }}"
|
|
version="${{ steps.version.outputs.version }}"
|
|
# The release body is this version's changelog section, not the whole
|
|
# file: from its "## [x.y.z]" heading to the next "## [" heading.
|
|
# Extracting rather than inlining keeps the changelog the single
|
|
# source of truth, and the tag/changelog gate above has already
|
|
# proven that section exists.
|
|
notes="$(mktemp)"
|
|
awk -v hdr="## [$version]" '
|
|
index($0, hdr) == 1 { printing = 1 }
|
|
printing && /^## \[/ && index($0, hdr) != 1 { exit }
|
|
printing { print }
|
|
' CHANGELOG.archied.md > "$notes"
|
|
if ! [ -s "$notes" ]; then
|
|
echo "no [$version] section extracted from CHANGELOG.archied.md" >&2
|
|
exit 1
|
|
fi
|
|
# Idempotent: --clobber replaces the asset and leaves the notes
|
|
# alone, so a re-run of this job (a retried or superseded deploy)
|
|
# cannot fail on an existing Release or duplicate the zip.
|
|
if gh release view "$tag" >/dev/null 2>&1; then
|
|
gh release upload "$tag" "${{ steps.zip.outputs.name }}.zip" --clobber
|
|
else
|
|
gh release create "$tag" \
|
|
--title "archied v$version" \
|
|
--notes-file "$notes" \
|
|
"${{ steps.zip.outputs.name }}.zip"
|
|
fi
|
|
echo "published $tag with ${{ steps.zip.outputs.name }}.zip"
|