From b26f91ae1bfdef1dbb528dc870036a154ad9053e Mon Sep 17 00:00:00 2001 From: leemour Date: Fri, 16 Oct 2026 18:49:48 +0200 Subject: [PATCH] fix(release): rerun bin/release once when the release brings a newer one The changelog fold (cli-dev changelog fold --land) fast-forwards main, and so does the version raise through land() where the script has one. sh reads bin/release as it goes, so a newer bin/release on main ran half old, half new. bin/release now hashes itself at start and, after those steps, re-execs ./bin/release with the same arguments if the file changed. WIRECAT_RELEASE_RERUN allows one re-exec; a second change stops with "run it again". The restart uses ./bin/release from the repository root, not "$0", which is wrong after cd when the script was started from another folder by a relative path. The release lock is taken again by the second run. Same fix as WireCatLabs/cli-base#173. Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 9 +++++++++ bin/release | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9267dd..388867c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,15 @@ Notable changes to `@wirecat/tg-cli`. One section per version, newest first; ver - **The MCP server loads only when MCP is served** (cli-core 0.300.0), so other commands start with about a tenth fewer files to load. +### Fixed + +- **`bin/release` restarts itself once when the release brings a newer `bin/release`**: folding the changelog and + raising the version both fast-forward `main`, and the shell went on reading the old script from the byte it had + reached, so the rest of the run was a mix of old and new text. It now starts the new script over with the same + arguments; a second change during that run stops it with `run it again`. The restart also works when + `bin/release` was started from another folder by a relative path. Only the repository's own release is affected; + the published package does not change. + ## 0.63.0 — 16.10.2026 ### What's new diff --git a/bin/release b/bin/release index 07299b5..7c796e0 100755 --- a/bin/release +++ b/bin/release @@ -11,6 +11,16 @@ set -eu cd "$(dirname "$0")/.." +self=$(git hash-object bin/release) +# The fold and land() fast-forward main, and sh reads this file as it goes: a newer bin/release would run half old, +# half new. Run the new one from the start instead: the second run finds the fold and the raise already on main. +rerun_if_changed() { + [ "$(git hash-object bin/release)" != "$self" ] || return 0 + [ -z "${WIRECAT_RELEASE_RERUN:-}" ] || { echo "bin/release changed again while releasing — run it again" >&2; exit 1; } + echo "bin/release changed on main — running the new one" + export WIRECAT_RELEASE_RERUN=1 + exec ./bin/release "$@" +} package=@wirecat/tg-cli mode=ci @@ -26,7 +36,7 @@ git fetch -q origin before=$(git rev-parse HEAD) git merge -q --ff-only origin/main # The shell keeps running the file it read before the merge; max-cli published with a stale copy. -[ "$(git rev-parse HEAD)" = "$before" ] || exec "$0" "$@" +[ "$(git rev-parse HEAD)" = "$before" ] || exec ./bin/release "$@" # The workflow publishes origin/main, so a local commit not pushed yet would silently not ship. [ "$(git rev-parse HEAD)" = "$(git rev-parse origin/main)" ] || { echo "main is ahead of origin/main — push first" >&2; exit 1; } # One release at a time on this machine, across every package: two sessions published at once on 2026-10-08. @@ -73,6 +83,7 @@ land() { folded="" published || folded=$(npx -y -p @wirecat/cli-base@0.36.0 cli-dev changelog fold --land --version "$version") [ -z "$folded" ] || echo "$folded" +rerun_if_changed "$@" # Two sessions preparing the same number is normal; the second takes the next free one (2026-09-29). latest=$(npm view "$package" version --prefer-online 2>/dev/null || true) @@ -92,6 +103,7 @@ if [ "$next" != "$version" ]; then else swap("CHANGELOG.md", `\n## ${o} — `, `\n## ${n} — `)' "$version" "$next" "$taken" body="bin/release: $why. Only the number changes: package.json, src/version.ts, the CHANGELOG heading." land "release/$next" "chore(release): $next" "$body" + rerun_if_changed "$@" version=$next fi if published; then