release: never cut a release from a stale or half-written dist/

`prepare` wrote `dist/` in place, copying the new tarball and sum over the
old ones and writing `release.env` last. An interrupted run therefore left a
new tarball beside the previous release's `release.env`, and `sign` trusts
that pair (env, sha256 and HEAD are all it checks) — the one way stale bytes
could actually leave the machine.

Assemble the handoff in a fresh `dist.staging.XXXXXX` and swap it into place
only once every file is written (release.env last), so `dist/` is either the
previous release or a complete new one, never half of each. The swap drops
the previous release's artifacts, so `dist/` holds one version at a time.

`sign` then pulls whenever `dist/` does not hold the version being signed
rather than only when `release.env` is absent, so a leftover from the
previous release is refreshed instead of dying with "release.env is for
0.9.1, not 0.9.2" — every release after the first used to start with a
manual `rm -rf dist`. `pull_dist` replaces `dist/` instead of merging into
it, so the two never mix.
This commit is contained in:
raucao committed 2026-12-01 13:08:20 +04:00
1 parent fe7a164201
commit b66a77dc7f
3 files changed
+45 -12

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
/_build*/
/dist/
/dist.staging.*
/target/
*.gresource
*.pkg.tar.*
+7
View File
@@ -66,6 +66,13 @@ the UI is tested. `build-aux/deploy-dev.sh` runs on the build host,
different tree than the tarball.
- **Only `dist/` travels between the machines.** The laptop pulls it from the
build host over SSH (`REGENT_BUILD_HOST`), so nothing has to be sent back.
`sign` pulls whenever `dist/` does not already hold the version being signed,
and a pull **replaces** `dist/` rather than merging into it, so the previous
release's artifacts cannot linger beside the current one.
- **`prepare` assembles `dist/` in a fresh staging directory and swaps it into
place at the end** (`release.env` written last), so an interrupted run leaves
the previous release intact instead of a new tarball beside an old
`release.env` — and `dist/` holds one version at a time.
- **The version exists in three dialects, derived in exactly one place**
(`release.sh`), because AppStream *and* pacman sort a `-`/`.`-separated
pre-release **above** the final release: `1.0.0-beta.1`
+37 -12
View File
@@ -16,15 +16,16 @@
# laptop$ build-aux/release.sh sign 0.9.0
# laptop$ build-aux/release.sh publish 0.9.0
#
# `sign` pulls dist/ from the build host over SSH when it is not there yet, so
# only the artifacts travel (build host -> laptop); nothing needs to come back.
# `sign` pulls dist/ from the build host over SSH when it does not already hold
# the version being signed, so only the artifacts travel (build host -> laptop);
# nothing needs to come back.
#
# Options:
# --draft publish: open the Gitea release as a draft
# --no-push prepare/publish: do not push commits or tags
# --no-aur publish: do not update the AUR
# --no-nostr publish: do not publish the Nostr release (ngit)
# --no-pull sign: fail instead of pulling dist/ from the build host
# --no-pull sign: fail if dist/ does not hold the version being signed
#
# Environment:
# REGENT_SSH_SIGNING_KEY SSH public key for the release commit (prepare)
@@ -55,6 +56,7 @@ AUR_GIT=${REGENT_AUR_GIT:-ssh://aur@aur.archlinux.org/regent-git.git}
BUILD_DIR=${REGENT_BUILD_DIR:-_build}
DIST=dist
AUR_TMP=
STAGING=
# --- arguments ---------------------------------------------------------------
@@ -105,6 +107,14 @@ PKGVER=$(arch_version "$version")
require_tools() { for t in "$@"; do command -v "$t" >/dev/null || die "$t not found"; done; }
env_value() { [ -f "$DIST/release.env" ] && sed -n "s/^$1=//p" "$DIST/release.env" | head -1 || true; }
# Whether dist/ holds the handoff for $version. `sign` pulls when it does not, so
# a dist/ left over from the previous release is refreshed rather than reported
# as a version mismatch.
dist_has_version() {
[ -f "$DIST/release.env" ] || return 1
[ "$(env_value version)" = "$version" ]
}
require_clean_main() {
local branch
branch=$(git symbolic-ref --short -q HEAD || true)
@@ -174,11 +184,14 @@ verify_tarball() {
}
pull_dist() {
[ "$pull" = yes ] || die "$DIST/release.env is missing and --no-pull was given"
[ -n "${REGENT_BUILD_HOST:-}" ] || die "$DIST/release.env is missing; set REGENT_BUILD_HOST to pull it, or copy dist/ over"
[ "$pull" = yes ] || die "$DIST does not hold $version and --no-pull was given"
[ -n "${REGENT_BUILD_HOST:-}" ] || die "$DIST does not hold $version; set REGENT_BUILD_HOST to pull it, or copy dist/ over"
require_tools ssh tar
local repo=${REGENT_REPO_PATH:-~/src/regent}
log "pulling dist/ from $REGENT_BUILD_HOST:$repo"
# Replace, not merge: the previous release's artifacts must not linger beside
# the one being signed.
rm -rf "$DIST"
mkdir -p "$DIST"
ssh "$REGENT_BUILD_HOST" "cd $repo && tar -C dist -cf - ." | tar -C "$DIST" -xf -
}
@@ -249,14 +262,21 @@ PY
fi
meson dist -C "$BUILD_DIR" ${dist_args[@]+"${dist_args[@]}"} >&2
local tarball="regent-$version.tar.xz"
mkdir -p "$DIST"
rm -f "$DIST/$tarball" "$DIST/$tarball.sha256sum"
cp "$BUILD_DIR/meson-dist/$tarball" "$BUILD_DIR/meson-dist/$tarball.sha256sum" "$DIST/"
( cd "$DIST" && sha256sum -c "$tarball.sha256sum" ) >&2
python3 build-aux/gen-metainfo-releases.py --notes "$version" CHANGELOG.md > "$DIST/notes.md"
# Assemble the handoff in a fresh staging directory and swap it into place only
# once every file is written, release.env last. Editing dist/ in place could
# leave a new tarball beside the previous release's release.env if prepare were
# interrupted, and `sign` trusts that pair; a fresh tree makes dist/ either the
# previous release or a complete new one, never half of each. The swap also
# drops the previous release's artifacts, so dist/ holds one version at a time.
STAGING=$(mktemp -d "$DIST.staging.XXXXXX")
trap '[ -n "${STAGING:-}" ] && rm -rf "$STAGING"' EXIT
cp "$BUILD_DIR/meson-dist/$tarball" "$BUILD_DIR/meson-dist/$tarball.sha256sum" "$STAGING/"
( cd "$STAGING" && sha256sum -c "$tarball.sha256sum" ) >&2
python3 build-aux/gen-metainfo-releases.py --notes "$version" CHANGELOG.md > "$STAGING/notes.md"
hdr "recording the handoff"
cat > "$DIST/release.env" <<EOF
cat > "$STAGING/release.env" <<EOF
version=$version
tag=$tag
prerelease=$prerelease
@@ -264,6 +284,11 @@ appstream=$APPSTREAM
pkgver=$PKGVER
commit=$(git rev-parse HEAD)
EOF
rm -rf "$DIST"
mv "$STAGING" "$DIST"
STAGING=
trap - EXIT
log "tarball $DIST/$tarball (sha256 $(cut -d' ' -f1 "$DIST/$tarball.sha256sum"))"
log "prepared $version at commit $(git rev-parse --short HEAD)"
@@ -285,7 +310,7 @@ EOF
stage_sign() {
hdr "preflight"
require_tools git gpg sha256sum sed
[ -f "$DIST/release.env" ] || pull_dist
dist_has_version || pull_dist
load_release_env
verify_tarball