From f677698887b3393cdbc34c0deeaa0401a86a5dbd Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 27 Nov 2026 17:55:47 +0000 Subject: [PATCH] fix(scripts): release a recurring version once, at its first landing A reverted bump left a run whose tag peeled to an earlier landing, which the script reported as ERROR. Because --apply is all-or-nothing, that ERROR stayed in the wanted set forever and blocked every other plugin's tag. A version is now released once, at its first landing. A run whose tag peels to an earlier run of the same version, or whose untagged version already appears earlier in the wanted set, reports RELEASED with a note and never blocks other rows. A tag on no landing of its version remains ERROR. Also: preflight every new tag name with git check-ref-format; report the tags already created, with their push line, and exit 2 if git tag fails mid-run; reject whitespace in apm.yml name and version. New tests cover the revert, in-set repeats, delete and re-add, an off-history tag, an invalid version in the wanted set, origin/main default resolution, and --apply with --plugin and --ref. Refs: #223 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi --- scripts/tag-plugin-releases.sh | 106 ++++++++++++++++------ tests/test-tag-plugin-releases.sh | 142 ++++++++++++++++++++++++++++-- 2 files changed, 215 insertions(+), 33 deletions(-) diff --git a/scripts/tag-plugin-releases.sh b/scripts/tag-plugin-releases.sh index 66f7250..ab44c3f 100755 --- a/scripts/tag-plugin-releases.sh +++ b/scripts/tag-plugin-releases.sh @@ -25,7 +25,8 @@ set -euo pipefail # # Per plugin (a directory under plugins/ carrying apm.yml at the ref): # - apm.yml `name` must equal the directory and `version` must be strict -# MAJOR.MINOR.PATCH at the ref; otherwise exit 2. +# MAJOR.MINOR.PATCH at the ref, neither containing whitespace; otherwise +# exit 2. # - Walk the ref's FIRST-PARENT history over commits touching # plugins/

/apm.yml, oldest first, and group contiguous equal-version # commits into runs. An apm.yml edit that leaves the version alone extends @@ -38,20 +39,27 @@ set -euo pipefail # counts as the last run whose target is its ancestor, so a mis-cut tag # widens the wanted set rather than hiding runs. The anchor run itself is # re-checked, so a mis-cut tag surfaces as an ERROR. +# - A version is released once, at its FIRST landing. When a version recurs +# (a revert, or apm.yml deleted and re-added), the later run is not tagged +# again: it reports RELEASED. # - Status per wanted run: MISSING (no tag), OK (annotated, peels to the -# target), ERROR (lightweight, peels elsewhere, invalid version in history, -# or the same version in two wanted runs — one immutable tag cannot mark -# both; a human tags the right one by hand and the anchor moves past it). +# target), RELEASED (the tag peels to an earlier run of the same version, +# or the version is untagged and an earlier wanted run carries it, so that +# run is the one tagged), ERROR (lightweight, peels to no landing of that +# version, invalid version in history, or a tag name git rejects). +# RELEASED never blocks other rows and never changes the exit code. # # Tag matching is anchored: `

-v` followed by a strict semver and nothing # else, so git, gitea and gitops never claim each other's tags. # # Tags are immutable: this script never moves, deletes or overwrites one. -# --apply is all-or-nothing: any ERROR anywhere creates nothing. +# --apply is all-or-nothing: any ERROR anywhere creates nothing. If `git tag` +# still fails mid-run, the tags already created are listed with their push +# line and the script exits 2. # # Exit: 0 nothing missing (or --apply created all of it); 1 dry run found -# MISSING tags; 2 any ERROR, bad input, shallow clone, unresolvable ref, or -# missing python3/PyYAML. +# MISSING tags; 2 any ERROR, bad input, shallow clone, unresolvable ref, +# missing python3/PyYAML, or a `git tag` failure during --apply. export LC_ALL=C @@ -152,7 +160,9 @@ fi # Reads "" lines on stdin and, for plugin path $1, prints one line per # commit: " OK ", " INVALID -" when # the version is not strict semver or the YAML does not parse, or -# " ABSENT - -" when the commit has no such file. Blobs come from one +# " ABSENT - -" when the commit has no such file. A name containing +# whitespace prints as "", which never equals a directory name; a +# version containing whitespace is INVALID. Blobs come from one # `git cat-file --batch`, so the cost is one python3 start per plugin, not per # commit. A crash prints nothing for the remaining commits; the caller checks # the count. @@ -178,8 +188,10 @@ for c in commits: doc = None name = doc.get("name") if isinstance(doc, dict) else None ver = doc.get("version") if isinstance(doc, dict) else None - name = "-" if name is None else (str(name).strip() or "-").replace(" ", "_") - ver = None if ver is None else str(ver).strip().strip("\x27\"") + name = "-" if name is None else (str(name) or "-") + if re.search(r"\s", name): + name = "" + ver = None if ver is None else str(ver).strip("\x27\"") if ver is not None and SEMVER.fullmatch(ver): print(c, "OK", name, ver) else: @@ -218,12 +230,16 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do # The ref's own copy is authoritative for name and current version. read -r _ cur_status cur_name _ <<< "$(printf '%s\n' "$REF_COMMIT" | read_versions "$apm")" + if [[ "$cur_name" == "" ]]; then + echo "FAIL: $apm at $REF has whitespace in its name; it must equal the directory name '$p'." >&2 + exit 2 + fi if [[ "$cur_name" != "$p" ]]; then echo "FAIL: $apm at $REF has name '$cur_name'; it must equal the directory name '$p' (the tag is '$p-v')." >&2 exit 2 fi if [[ "$cur_status" != "OK" ]]; then - echo "FAIL: $apm at $REF has no strict MAJOR.MINOR.PATCH version." >&2 + echo "FAIL: $apm at $REF has no strict MAJOR.MINOR.PATCH version (no whitespace allowed)." >&2 exit 2 fi @@ -272,16 +288,22 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do add_row "$p" "INVALID" "$target" ERROR "$apm version at ${target:0:7} is not MAJOR.MINOR.PATCH" continue fi - dup=false - for ((j = first; j < nruns; j++)); do - [[ $j -ne $i && "${RUN_VALID[j]}" == true && "${RUN_VER[j]}" == "$v" ]] && dup=true - done tag="$p-v$v" - if $dup; then - add_row "$p" "$v" "$target" ERROR "version $v recurs in separate runs; tag the right commit by hand" - continue - fi if ! git rev-parse --verify -q "refs/tags/$tag" > /dev/null; then + # Untagged: the version is released at its first landing in the wanted + # set, so a later run of the same version is not tagged again. + earlier="" + for ((j = first; j < i; j++)); do + if [[ "${RUN_VALID[j]}" == true && "${RUN_VER[j]}" == "$v" ]]; then earlier="${RUN_TARGET[j]}"; break; fi + done + if [[ -n "$earlier" ]]; then + add_row "$p" "$v" "$target" RELEASED "$v is released at its first landing ${earlier:0:7}" + continue + fi + if ! git check-ref-format "refs/tags/$tag"; then + add_row "$p" "$v" "$target" ERROR "'$tag' is not a valid tag name (git check-ref-format)" + continue + fi add_row "$p" "$v" "$target" MISSING "" continue fi @@ -290,11 +312,21 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do continue fi peeled="$(git rev-parse --verify -q "refs/tags/$tag^{commit}" || true)" - if [[ "$peeled" != "$target" ]]; then - add_row "$p" "$v" "$target" ERROR "$tag peels to ${peeled:0:7}, not ${target:0:7}" + if [[ "$peeled" == "$target" ]]; then + add_row "$p" "$v" "$target" OK "" continue fi - add_row "$p" "$v" "$target" OK "" + # Tagged elsewhere: fine only if it peels to an EARLIER run of the same + # version (the first landing, e.g. before a revert brought $v back). + landing=-1 + for ((j = 0; j < i; j++)); do + if [[ "${RUN_TARGET[j]}" == "$peeled" && "${RUN_VALID[j]}" == true && "${RUN_VER[j]}" == "$v" ]]; then landing=$j; fi + done + if [[ $landing -ge 0 ]]; then + add_row "$p" "$v" "$target" RELEASED "$tag already released at ${peeled:0:7}" + continue + fi + add_row "$p" "$v" "$target" ERROR "$tag peels to ${peeled:0:7}, not ${target:0:7} or any earlier landing of $v" done done @@ -314,6 +346,14 @@ for ((i = 0; i < ${#ROW_STATUS[@]}; i++)); do esac done +report_released() { + local i + for ((i = 0; i < ${#ROW_STATUS[@]}; i++)); do + [[ "${ROW_STATUS[i]}" == RELEASED ]] && echo "NOTE: ${ROW_PLUGIN[i]}: ${ROW_DETAIL[i]}; nothing to tag at ${ROW_COMMIT[i]:0:7}." >&2 + done + return 0 +} + report_errors() { local i for ((i = 0; i < ${#ROW_STATUS[@]}; i++)); do @@ -324,6 +364,7 @@ report_errors() { if ! $APPLY; then print_table + report_released if [[ $ERRORS -gt 0 ]]; then report_errors; exit 2; fi if [[ $MISSING -gt 0 ]]; then echo "$MISSING tag(s) missing at $REF. Re-run with --apply to create them." >&2 @@ -334,23 +375,34 @@ fi if [[ $ERRORS -gt 0 ]]; then print_table + report_released report_errors echo "Nothing created: --apply is all-or-nothing." >&2 exit 2 fi CREATED=() +print_push() { + [[ ${#CREATED[@]} -gt 0 ]] || return 0 + echo "Created ${#CREATED[@]} tag(s) locally. Push them (maintainer's step, ADR-0033):" + echo "git push origin ${CREATED[*]}" +} + for ((i = 0; i < ${#ROW_STATUS[@]}; i++)); do [[ "${ROW_STATUS[i]}" == MISSING ]] || continue tag="${ROW_PLUGIN[i]}-v${ROW_VERSION[i]}" - git tag -a "$tag" -m "${ROW_PLUGIN[i]} ${ROW_VERSION[i]}" "${ROW_COMMIT[i]}" + if ! git tag -a "$tag" -m "${ROW_PLUGIN[i]} ${ROW_VERSION[i]}" "${ROW_COMMIT[i]}"; then + ROW_STATUS[i]=ERROR + print_table + echo "ERROR: git tag $tag failed (see above); stopped there." >&2 + print_push + exit 2 + fi ROW_STATUS[i]=CREATED CREATED+=("$tag") done print_table -if [[ ${#CREATED[@]} -gt 0 ]]; then - echo "Created ${#CREATED[@]} tag(s) locally. Push them (maintainer's step, ADR-0033):" - echo "git push origin ${CREATED[*]}" -fi +report_released +print_push exit 0 diff --git a/tests/test-tag-plugin-releases.sh b/tests/test-tag-plugin-releases.sh index 07eae4b..dda9516 100755 --- a/tests/test-tag-plugin-releases.sh +++ b/tests/test-tag-plugin-releases.sh @@ -209,16 +209,146 @@ run "$R" --ref main --apply expect_rc "ERROR blocks --apply" 2 if [[ -z "$(git -C "$R" tag -l 'theta-v*')" ]]; then pass "nothing created for the clean plugin"; else fail "theta tag created despite ERROR"; fi -echo "Case 12: version recurring inside the wanted set is an ERROR" +echo "Case 12: untagged version recurring inside the wanted set is tagged at its first landing" R="$(new_repo)" write_apm "$R" kappa 0.9.0; commit "$R" a; K0="$(head_sha "$R")" -write_apm "$R" kappa 1.0.0; commit "$R" b -write_apm "$R" kappa 1.1.0; commit "$R" c -write_apm "$R" kappa 1.0.0; commit "$R" d +write_apm "$R" kappa 1.0.0; commit "$R" b; KB="$(head_sha "$R")" +write_apm "$R" kappa 1.1.0; commit "$R" c; KC="$(head_sha "$R")" +write_apm "$R" kappa 1.0.0; commit "$R" d; KD="$(head_sha "$R")" (cd "$R" && git tag -a kappa-v0.9.0 -m x "$K0") run "$R" --ref main -expect_rc "recurring version" 2 -if grep -q "recurs" <<< "$OUT"; then pass "message names the recurrence"; else fail "no recurrence message"; fi +expect_rc "recurring version is not an error" 1 +expect_row "first landing of 1.0.0 is MISSING" kappa 1.0.0 "$KB" MISSING +expect_row "later landing of 1.0.0 is RELEASED" kappa 1.0.0 "$KD" RELEASED +expect_row "1.1.0 MISSING" kappa 1.1.0 "$KC" MISSING +if grep -q "first landing ${KB:0:7}" <<< "$OUT"; then pass "note names the first landing"; else fail "no first-landing note"; fi +run "$R" --ref main --apply +expect_rc "--apply with a recurring version" 0 +if [[ "$(git -C "$R" rev-parse "kappa-v1.0.0^{commit}" 2>/dev/null)" == "$KB" ]]; then pass "kappa-v1.0.0 cut at the first landing"; else fail "kappa-v1.0.0 not on the first landing"; fi +run "$R" --ref main +expect_rc "dry run after --apply" 0 +expect_row "later landing RELEASED via the tag" kappa 1.0.0 "$KD" RELEASED +if grep -q "already released at ${KB:0:7}" <<< "$OUT"; then pass "note names where it was released"; else fail "no already-released note"; fi + +echo "Case 12b: a revert after tagging does not wedge other plugins" +R="$(new_repo)" +write_apm "$R" aa 1.0.0; write_apm "$R" bb 1.0.0; commit "$R" a; A1="$(head_sha "$R")" +write_apm "$R" aa 1.1.0; commit "$R" b; A2="$(head_sha "$R")" +(cd "$R" && git tag -a aa-v1.0.0 -m x "$A1" && git tag -a aa-v1.1.0 -m x "$A2" && git tag -a bb-v1.0.0 -m x "$A1") +write_apm "$R" aa 1.0.0; commit "$R" revert; A3="$(head_sha "$R")" +write_apm "$R" bb 1.2.0; commit "$R" c; B2="$(head_sha "$R")" +run "$R" --ref main +expect_rc "dry run: only bb is missing" 1 +expect_row "aa 1.1.0 OK" aa 1.1.0 "$A2" OK +expect_row "reverted aa 1.0.0 is RELEASED" aa 1.0.0 "$A3" RELEASED +expect_row "bb 1.2.0 MISSING" bb 1.2.0 "$B2" MISSING +run "$R" --ref main --apply +expect_rc "--apply after a revert" 0 +if [[ "$(git -C "$R" rev-parse "bb-v1.2.0^{commit}" 2>/dev/null)" == "$B2" ]]; then pass "bb-v1.2.0 created"; else fail "bb-v1.2.0 not created"; fi +if [[ "$(git -C "$R" rev-parse "aa-v1.0.0^{commit}")" == "$A1" ]]; then pass "aa-v1.0.0 left where it was"; else fail "aa-v1.0.0 moved"; fi +if grep -qx "git push origin bb-v1.2.0" <<< "$OUT"; then pass "push line names only bb-v1.2.0"; else fail "push line wrong"; echo "$OUT" | sed 's/^/ /'; fi + +echo "Case 12c: a tag on no landing of its version stays an ERROR" +(cd "$R" && git tag -d aa-v1.0.0 > /dev/null && git tag -a aa-v1.0.0 -m x "$A2") +run "$R" --ref main +expect_rc "tag on another version's landing" 2 +expect_row "row is ERROR" aa 1.0.0 "$A3" ERROR + +echo "Case 12d: apm.yml deleted and re-added starts a new run" +R="$(new_repo)" +write_apm "$R" nu 1.0.0; write_apm "$R" xi 1.0.0; commit "$R" a; N1="$(head_sha "$R")" +rm -r "$R/plugins/nu"; commit "$R" delete +write_apm "$R" nu 1.0.0; commit "$R" readd; N3="$(head_sha "$R")" +run "$R" --ref main --plugin nu +expect_rows "untagged: one wanted row" nu 1 +expect_row "untagged: target is the re-add" nu 1.0.0 "$N3" MISSING +(cd "$R" && git tag -a nu-v1.0.0 -m x "$N1") +run "$R" --ref main --plugin nu +expect_rc "tagged before the delete" 0 +expect_row "original landing OK" nu 1.0.0 "$N1" OK +expect_row "re-added landing RELEASED" nu 1.0.0 "$N3" RELEASED + +echo "Case 12e: invalid version inside the wanted set is an ERROR" +R="$(new_repo)" +write_apm "$R" omi 1.0.0; commit "$R" a; O1="$(head_sha "$R")" +write_apm "$R" omi 1.1; commit "$R" b; O2="$(head_sha "$R")" +write_apm "$R" omi 1.2.0; commit "$R" c +(cd "$R" && git tag -a omi-v1.0.0 -m x "$O1") +run "$R" --ref main +expect_rc "invalid version in history" 2 +expect_row "row is ERROR" omi INVALID "$O2" ERROR + +echo "Case 12f: a tag outside the ref's history is not an anchor" +R="$(new_repo)" +write_apm "$R" pi 1.0.0; commit "$R" a; P1="$(head_sha "$R")" +write_apm "$R" pi 1.1.0; commit "$R" b; P2="$(head_sha "$R")" +(cd "$R" && git checkout -q -b side "$P1" && git commit -q --allow-empty -m side && git tag -a pi-v1.0.0 -m x HEAD && git checkout -q main) +run "$R" --ref main +expect_rc "off-history tag ignored" 1 +expect_rows "only the current run is wanted" pi 1 +expect_row "pi 1.1.0 MISSING" pi 1.1.0 "$P2" MISSING +(cd "$R" && git tag -a pi-v1.1.0 -m x side) +run "$R" --ref main +expect_rc "current version tagged off-history" 2 +expect_row "row is ERROR" pi 1.1.0 "$P2" ERROR + +echo "Case 12g: whitespace in name or version exits 2" +R="$(new_repo)" +mkdir -p "$R/plugins/mu"; printf 'name: "mu\\t"\nversion: 1.0.0\n' > "$R/plugins/mu/apm.yml"; commit "$R" a +run "$R" --ref main +expect_rc "tab in name" 2 +if grep -q "whitespace" <<< "$OUT"; then pass "message names whitespace"; else fail "no whitespace message"; fi +printf 'name: mu\nversion: "1.0.0 "\n' > "$R/plugins/mu/apm.yml"; commit "$R" b +run "$R" --ref main +expect_rc "trailing space in version" 2 + +echo "Case 12h: a tag name git rejects is an ERROR and nothing is created" +R="$(new_repo)" +write_apm "$R" rho 1.0.0; write_apm "$R" "a..b" 1.0.0; commit "$R" a +run "$R" --ref main --apply +expect_rc "invalid ref name blocks --apply" 2 +if grep -q "check-ref-format" <<< "$OUT"; then pass "message names check-ref-format"; else fail "no check-ref-format message"; fi +if [[ -z "$(git -C "$R" tag -l)" ]]; then pass "nothing created"; else fail "tags created despite invalid name"; fi + +echo "Case 12i: a git tag failure mid --apply reports what was created" +R="$(new_repo)" +write_apm "$R" sa 1.0.0; write_apm "$R" sb 1.0.0; commit "$R" a +mkdir -p "$R/.git/refs/tags" && : > "$R/.git/refs/tags/sb-v1.0.0.lock" +run "$R" --ref main --apply +expect_rc "mid-run git tag failure" 2 +if [[ -n "$(git -C "$R" tag -l sa-v1.0.0)" ]]; then pass "sa-v1.0.0 was created first"; else fail "sa-v1.0.0 missing"; fi +if grep -qx "git push origin sa-v1.0.0" <<< "$OUT"; then pass "push line names what was created"; else fail "no push line for created tags"; echo "$OUT" | sed 's/^/ /'; fi + +echo "Case 12j: --apply with --plugin creates only that plugin's tag" +R="$(new_repo)" +write_apm "$R" ta 1.0.0; write_apm "$R" tb 1.0.0; commit "$R" a +run "$R" --ref main --plugin ta --apply +expect_rc "--apply --plugin ta" 0 +if [[ -n "$(git -C "$R" tag -l ta-v1.0.0)" && -z "$(git -C "$R" tag -l 'tb-v*')" ]]; then pass "only ta tagged"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi + +echo "Case 12k: --ref --plugin

--apply tags that plugin's older version only" +R="$(new_repo)" +write_apm "$R" ua 1.0.0; write_apm "$R" ub 1.0.0; commit "$R" a; U1="$(head_sha "$R")" +write_apm "$R" ua 1.1.0; write_apm "$R" ub 1.1.0; commit "$R" b; U2="$(head_sha "$R")" +run "$R" --ref "$U1" --plugin ua --apply +expect_rc "one-off older tag" 0 +if [[ "$(git -C "$R" tag -l)" == "ua-v1.0.0" ]]; then pass "only ua-v1.0.0 created"; else fail "wrong tags: $(git -C "$R" tag -l | tr '\n' ' ')"; fi +if [[ "$(git -C "$R" rev-parse "ua-v1.0.0^{commit}")" == "$U1" ]]; then pass "ua-v1.0.0 on the older commit"; else fail "ua-v1.0.0 misplaced"; fi +run "$R" --ref main +expect_rows "ua anchored at the one-off tag" ua 2 +expect_row "ua 1.1.0 MISSING after the one-off" ua 1.1.0 "$U2" MISSING + +echo "Case 12l: default ref is origin/main, not local main" +R="$(new_repo)" +write_apm "$R" va 1.0.0; commit "$R" a; V1="$(head_sha "$R")" +B="$(mktemp -d)"; CLEANUP_DIRS+=("$B") +git init -q --bare "$B/r.git" +(cd "$R" && git remote add origin "$B/r.git" && git push -q origin main 2>/dev/null) +write_apm "$R" va 2.0.0; commit "$R" local-only +run "$R" +expect_rc "default ref" 1 +expect_row "reads origin/main's version" va 1.0.0 "$V1" MISSING +if ! grep -q "reading local main" <<< "$OUT"; then pass "no staleness note when origin/main resolves"; else fail "staleness note printed"; fi echo "Case 13: bad input exits 2" run "$R" --ref no-such-ref