From 75b29e1e097859e2fe6ae8a260c93c243d68d40e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 01:25:57 +0000 Subject: [PATCH] Release check: refuse a tag without a dated CHANGELOG heading tools/check_release.sh vX.Y.Z checks that Cargo.toml's version is the tag's and that CHANGELOG.md's newest heading is '## [X.Y.Z] - YYYY-MM-DD' with a real date. The release workflow runs it first on tags (nothing is built if it fails) and as a notice on pull requests. 2.0.2 and 2.1.0 both shipped with '- unreleased'. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QXjQsiWnwLMndr5XU9g5LJ --- .github/workflows/release.yml | 15 ++++++++++- docs/OFFLINE.md | 10 +++++++- tools/check_release.sh | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100755 tools/check_release.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 21c9e8b..f23b2fa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,9 @@ # dyode--src.tar.gz source + Cargo.lock + vendored crates # # Runs on tags, by hand ("Run workflow"), and on pull requests that change -# the installer or the build tools. +# the installer or the build tools. On a tag it first runs +# tools/check_release.sh: the tag, Cargo.toml and a dated CHANGELOG.md +# heading must agree, or nothing is built. name: Release / offline bundle on: @@ -40,6 +42,17 @@ jobs: version: ${{ steps.v.outputs.version }} steps: - uses: actions/checkout@v4 + # Before anything is built: Cargo.toml and a dated CHANGELOG heading + # must match the tag (a release once shipped as "- unreleased"). + - name: Release check (tag, Cargo.toml, CHANGELOG.md) + if: startsWith(github.ref, 'refs/tags/') + run: tools/check_release.sh "${GITHUB_REF_NAME}" + - name: Release check preview (does not fail a pull request) + if: "!startsWith(github.ref, 'refs/tags/')" + run: | + v="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)" + tools/check_release.sh "v$v" || + echo "::notice::tagging v$v now would fail the release check: date its CHANGELOG.md heading first" - uses: dtolnay/rust-toolchain@stable - id: v run: echo "version=$(sed -n 's/^version = \"\(.*\)\"/\1/p' Cargo.toml | head -1)" >> "$GITHUB_OUTPUT" diff --git a/docs/OFFLINE.md b/docs/OFFLINE.md index a02de53..58970ae 100644 --- a/docs/OFFLINE.md +++ b/docs/OFFLINE.md @@ -77,7 +77,11 @@ is a one-line change to `tools/build_binary.sh`. `.github/workflows/release.yml`, on every tag (and by hand, and on pull requests that touch the installer or tools): -1. **source** -- `cargo generate-lockfile` (if needed) and `cargo vendor`, into +1. **source** -- on a tag, first `tools/check_release.sh`: the tag, + Cargo.toml's version and a *dated* CHANGELOG.md heading + (`## [2.1.0] - 2026-10-28`, the newest one) must agree, or nothing is + built. Pull requests get the same check as a notice only. Then + `cargo generate-lockfile` (if needed) and `cargo vendor`, into `dyode--src.tar.gz`. 2. **binary** -- the binaries are built *from that vendored source with `--offline`*, in a Debian 12 container with no network, on native amd64 @@ -93,6 +97,10 @@ requests that touch the installer or tools): 6. **publish** (tags only) -- the bundle, the source tarball and the bare binaries are attached to the release, with `SHA256SUMS`. +To release: set the version in Cargo.toml, date its CHANGELOG.md heading, +merge, check locally with `tools/check_release.sh vX.Y.Z`, then tag +`vX.Y.Z` on main. + By hand, on a machine with internet and Docker: ```bash diff --git a/tools/check_release.sh b/tools/check_release.sh new file mode 100755 index 0000000..6ad5838 --- /dev/null +++ b/tools/check_release.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Check that a release is ready to publish, before anything is built: +# +# tools/check_release.sh v2.1.0 (the release workflow passes the tag) +# +# - Cargo.toml's version is the tag's version; +# - CHANGELOG.md has a dated heading for it, "## [2.1.0] - 2026-10-28", +# not "- unreleased", with a real date; +# - that heading is the newest versioned one (only "## [Unreleased]" may +# come before it). +# +# Exits 1 with a message naming what to fix. +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +CHANGELOG="${CHANGELOG:-$ROOT/CHANGELOG.md}" +CARGO="${CARGO_TOML:-$ROOT/Cargo.toml}" + +[ $# -eq 1 ] || { echo "usage: $0 vX.Y.Z" >&2; exit 2; } +version="${1#refs/tags/}" +version="${version#v}" +fail=0 +err() { printf 'release check: %s\n' "$*" >&2; fail=1; } + +[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]] || { err "tag '$1' is not vX.Y.Z"; exit 1; } + +cargo_version="$(sed -n 's/^version = "\(.*\)"/\1/p' "$CARGO" | head -1)" +[ "$cargo_version" = "$version" ] || + err "Cargo.toml says version $cargo_version, the tag says $version" + +esc="${version//./\\.}" +heading="$(grep -E "^## \[$esc\]" "$CHANGELOG" | head -1 || true)" +if [ -z "$heading" ]; then + err "CHANGELOG.md has no '## [$version] - YYYY-MM-DD' heading" +else + date="$(sed -nE 's/^## \[[^]]+\] - ([0-9]{4}-[0-9]{2}-[0-9]{2})[[:space:]]*$/\1/p' <<<"$heading")" + if [ -z "$date" ]; then + err "CHANGELOG.md heading '$heading' has no date: write '## [$version] - $(date -u +%F)'" + elif ! date -u -d "$date" +%F >/dev/null 2>&1 || [ "$(date -u -d "$date" +%F)" != "$date" ]; then + err "CHANGELOG.md heading '$heading': $date is not a real date" + fi + first="$(grep -E '^## \[' "$CHANGELOG" | grep -viE '^## \[unreleased\]' | head -1)" + [ "$first" = "$heading" ] || + err "'$heading' is not the newest release in CHANGELOG.md (the first is '$first')" +fi + +[ "$fail" -eq 0 ] && echo "release check: $version ready (Cargo.toml and CHANGELOG.md agree, dated $date)" +exit "$fail"