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 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
1 parent
8b54a60fc8
commit
f677698887
2 files changed
+215
-33
No files matched your search
@@ -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/<p>/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: `<p>-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 "<commit>" lines on stdin and, for plugin path $1, prints one line per
|
||||
# commit: "<commit> OK <name> <version>", "<commit> INVALID <name|-> -" when
|
||||
# the version is not strict semver or the YAML does not parse, or
|
||||
# "<commit> ABSENT - -" when the commit has no such file. Blobs come from one
|
||||
# "<commit> ABSENT - -" when the commit has no such file. A name containing
|
||||
# whitespace prints as "<whitespace>", 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 = "<whitespace>"
|
||||
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" == "<whitespace>" ]]; 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<version>')." >&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
|
||||
Reference in new issue
Block a user