ci(release): cut releases from [Unreleased] by workflow dispatch (#1716)
deploy / gate (push) Successful in 7m17s
Quality / check (push) Canceled after 9m13s
deploy / archied-image (push) Successful in 2m56s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped

This commit is contained in:
sam committed 2026-10-31 21:30:33 +11:00
1 parent 812d9004a7
commit a7f6e517ad
4 files changed
+79 -237

No files matched your search

+1 -2
View File
@@ -134,8 +134,7 @@ jobs:
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>"
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
+51
View File
@@ -0,0 +1,51 @@
# Cuts a release from main: [Unreleased] in CHANGELOG.md becomes the version's
# section, then the commit and its tag are pushed together. The tag push starts
# deploy.yml, which publishes the release to `next` for the canary.
name: release
on:
workflow_dispatch:
inputs:
release:
description: "major, minor, patch, or an exact version such as 1.57.0"
required: true
default: minor
concurrency:
group: release
permissions:
contents: write
jobs:
cut:
runs-on: self-hosted
steps:
# DEPLOY_TOKEN rather than the job token: a push made with the job token
# does not start workflows, and the tag push must start deploy.yml.
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.DEPLOY_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install Task
run: go install github.com/go-task/task/v3/cmd/task@v3.48.0
- name: Cut the release
env:
RELEASE: ${{ inputs.release }}
run: |
git config user.name "Sam Catlow"
git config user.email "sam@catlow.tech"
task release RELEASE="$RELEASE"
# Atomic: a commit without its tag would build images stamped dev.
- name: Push the release
run: git push --atomic origin main "$(git describe --exact-match --match 'v*' HEAD)"
+27 -18
View File
@@ -299,23 +299,32 @@ tasks:
- task: test:ui
- task: ui:check
release:preview:
desc: "Show the release notes that would be generated (VERSION=1.2.0)"
cmds:
- tools/release.sh --version {{.VERSION}} --dry-run
requires:
vars: [VERSION]
release:prepare:
desc: Prepare changelog notes for editing (VERSION=1.2.0)
cmds:
- tools/release.sh --version {{.VERSION}} --prepare
requires:
vars: [VERSION]
release:
desc: Commit and tag the prepared release (VERSION=1.2.0)
cmds:
- tools/release.sh --version {{.VERSION}} --tag
desc: "Turn [Unreleased] into a release, then commit and tag it (RELEASE=major|minor|patch|1.2.3)"
requires:
vars: [VERSION]
vars: [RELEASE]
cmds:
- |
set -euo pipefail
die() { echo "release: $*" >&2; exit 1; }
[ "$(git rev-parse --abbrev-ref HEAD)" = main ] || die "releases are cut from main"
[ -z "$(git status --porcelain)" ] || die "the working tree is dirty"
last="$(git tag --list 'v*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 || true)"
IFS=. read -r major minor patch <<<"${last#v}"
case "{{.RELEASE}}" in
major) version="$((major + 1)).0.0" ;;
minor) version="$major.$((minor + 1)).0" ;;
patch) version="$major.$minor.$((patch + 1))" ;;
*) version="$(echo "{{.RELEASE}}" | sed 's/^v//')" ;;
esac
echo "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$' || die "$version is not a version"
! git rev-parse -q --verify "refs/tags/v$version" >/dev/null || die "v$version already exists"
awk '/^## \[Unreleased\]/ { u = 1; next } u && /^## \[/ { exit } u && /^- / { found = 1 } END { exit !found }' CHANGELOG.md ||
die "[Unreleased] in CHANGELOG.md has no entries"
awk -v hdr="## [$version] - $(date -u +%F)" '{ print } /^## \[Unreleased\]/ { print ""; print hdr }' CHANGELOG.md >CHANGELOG.md.tmp
mv CHANGELOG.md.tmp CHANGELOG.md
go -C tools run -mod=readonly ./newsgen --repo-root ..
git add CHANGELOG.md docs/news
git commit -q -m "chore(release): v$version"
git tag -a "v$version" -m "v$version"
echo "tagged v$version"
-217
View File
@@ -1,217 +0,0 @@
#!/usr/bin/env bash
# Cuts a release in two steps, so the generated notes can be edited before
# they are frozen into a tag -- the same review window release-please gives
# you with its release PR.
#
# tools/release.sh --version 1.2.0 --dry-run # preview
# tools/release.sh --version 1.2.0 --prepare # write, then edit
# tools/release.sh --version 1.2.0 --tag # commit + tag
#
# There is one release stream: CHANGELOG.md carries every release section,
# one generated page per version, and one tag names the release. A release is
# one version covering whatever changed; per-component detail is a labelled
# section inside it, not a separate number.
#
# Exit codes: 0 released (or previewed/prepared); 1 failure; 3 nothing to
# release -- a commit set that justifies no version is a result, not an error,
# so a pipeline can finish green without tagging.
set -euo pipefail
cd "$(dirname "$0")/.."
NOTHING_TO_RELEASE=3
MODE=""
VERSION=""
die() {
echo "release: $*" >&2
exit 1
}
while [ $# -gt 0 ]; do
case "$1" in
--version) VERSION="${2:-}"; shift 2 ;;
--dry-run) MODE="dry-run"; shift ;;
--prepare) MODE="prepare"; shift ;;
--tag) MODE="tag"; shift ;;
*) die "unknown argument: $1" ;;
esac
done
[ -n "$VERSION" ] || die "--version <version> is required"
[ -n "$MODE" ] || die "one of --dry-run, --prepare or --tag is required"
if [ "$MODE" != "dry-run" ]; then
branch="$(git rev-parse --abbrev-ref HEAD)"
[ "$branch" = "main" ] || die "releases are cut from main, not $branch"
fi
if [ "$MODE" = "prepare" ]; then
[ -z "$(git status --porcelain)" ] || die "working tree is dirty; commit or stash first"
fi
# component_dirs <cmd-path> -- repo-relative dirs of every package the binary
# links, plus the files that build only that binary. go.mod and go.sum pin the
# dependencies every binary links, so a dependency bump changes them all.
component_dirs() {
go list -deps -f '{{.Dir}}' "$1" 2>/dev/null |
grep -F "$PWD/" |
sed "s|^$PWD/||"
printf '%s\n' go.mod go.sum
}
# matches <changed-files> <dirs> -- true when any changed file lives in one
# of the component's directories.
matches() {
local files="$1" dirs="$2" f d
while read -r f; do
[ -n "$f" ] || continue
while read -r d; do
[ -n "$d" ] || continue
case "$f" in
"$d"/*) return 0 ;;
"$d") return 0 ;;
esac
done <<<"$dirs"
done <<<"$files"
return 1
}
# The host bundle IS the archied artifact: the distribution zip is named and
# versioned by the release, and every process it ships carries that version.
# The paths below are named rather than whole directories, so a packaging-only
# change is attributed to archied deliberately and not every CI or script edit.
archied_dirs() {
component_dirs ./cmd/archied
# Every process the host bundles ships in this release, so a change to a
# package only one of them links still lands in the changelog. Without
# these, messaging-only and state-store-only packages closed
# over no component and the release silently omitted them (the telegram fence
# fix was dropped this way). The gap is pre-existing -- the old two-file
# closures named only cmd/archied and cmd/archie-agent -- but it grew teeth
# when the Messaging Service was severed from archied in 1.35.0.
component_dirs ./cmd/archie-messaging
component_dirs ./cmd/archie-state-store
component_dirs ./cmd/archie-ui
printf '%s\n' "cmd/archied" "Dockerfile.archied" "cmd/archie-ui" "internal/app/archieui" \
"Taskfile.yml" ".github/workflows/deploy.yml" "install.sh" \
"deployments/INSTRUCTIONS.md"
}
# The UI Service ships with the archied release on purpose (archie-ui shares
# internal/webui with archied), hence archied_dirs' extra paths above.
runtime_dirs() {
component_dirs ./cmd/archie-agent
printf '%s\n' "cmd/archie-agent" "Dockerfile"
}
# changelog_body -- labelled per-component sections for every releasable commit
# since the last release. Empty output means nothing to release: a commit set
# that justifies no version produces no body, and the caller reports that
# rather than inventing one.
changelog_body() {
local last range archied runtime
last="$(git describe --tags --abbrev=0 2>/dev/null || true)"
range="HEAD"
if [ -n "$last" ]; then
range="$last..HEAD"
fi
archied="$(archied_dirs)"
runtime="$(runtime_dirs)"
local sha subject files in_archied="" in_runtime=""
while read -r sha; do
[ -n "$sha" ] || continue
subject="$(git log -1 --pretty=%s "$sha")"
# Conventional commits only; release commits are not news.
case "$subject" in
feat:* | feat\(*|fix:* | fix\(*|perf:* | perf\(*|refactor:* | refactor\(*) ;;
*) continue ;;
esac
files="$(git show --pretty=format: --name-only "$sha")"
if matches "$files" "$archied"; then
in_archied="$in_archied- $subject"$'\n'
fi
if matches "$files" "$runtime"; then
in_runtime="$in_runtime- $subject"$'\n'
fi
done < <(git log --no-merges --pretty=%H --reverse "$range")
if [ -n "$in_archied" ]; then
printf '### archied\n\n%s\n' "$in_archied"
fi
if [ -n "$in_runtime" ]; then
printf '### archie-agent\n\n%s\n' "$in_runtime"
fi
}
# prepend <version> <body-file> -- insert the new section after the title and
# any [Unreleased] block, which stays at the top, and above every release.
prepend() {
local version="$1" bodyfile="$2" tmp line
line="$(grep -n '^## \[' CHANGELOG.md | grep -v '## \[Unreleased\]' | head -1 | cut -d: -f1)"
if [ -z "$line" ]; then
line="$(($(wc -l <CHANGELOG.md) + 1))"
fi
tmp="$(mktemp)"
{
head -n "$((line - 1))" CHANGELOG.md
echo "## [$version] - $(date +%F)"
echo
cat "$bodyfile"
echo
tail -n "+$line" CHANGELOG.md
} >"$tmp"
mv "$tmp" CHANGELOG.md
}
body="$(changelog_body)"
if [ -z "$body" ]; then
last="$(git describe --tags --abbrev=0 2>/dev/null || echo 'the beginning')"
echo "nothing to release: no releasable commits since $last" >&2
exit "$NOTHING_TO_RELEASE"
fi
echo "==> release $VERSION"
echo "$body" | sed 's/^/ /'
if [ "$MODE" = "dry-run" ]; then
echo
echo "dry run: no files written, no commits, no tags"
exit 0
fi
bodyfile="$(mktemp)"
printf '%s\n' "$body" >"$bodyfile"
if [ "$MODE" = "prepare" ]; then
prepend "$VERSION" "$bodyfile"
rm -f "$bodyfile"
echo
echo "CHANGELOG.md updated and left uncommitted. Edit it -- generated notes"
echo "are a starting point, not the release -- then freeze it with:"
echo
echo " tools/release.sh --version $VERSION --tag"
exit 0
fi
# --tag: the changelog must already describe this release.
grep -q "^## \\[$VERSION\\]" CHANGELOG.md ||
die "CHANGELOG.md has no [$VERSION] section; run --prepare first"
# The published release notes are derived from the changelog, so regenerate
# them after the maintainer's edit and ship them in the same commit as the
# section they describe. newsgen skips a file whose bytes already match, so a
# re-run leaves the tree clean.
go -C tools run -mod=readonly ./newsgen --repo-root ..
git add CHANGELOG.md docs/news
git commit -m "chore(release): v$VERSION"
git tag -a "v$VERSION" -m "v$VERSION"
echo
echo "tagged. push with:"
echo " git push --atomic origin main v$VERSION"
echo
echo "The deploy workflow reads the tags pointing at HEAD, so the commit and"
echo "its tag must land together; --atomic pushes both or neither."