fix(scripts): validate every release tag and gate --apply on origin/main

A mis-cut tag could serve as the start point and silently drop the runs
before it: x-v9.9.9 or a lightweight x-v1.0.1 on a later landing hid an
untagged 1.1.0 and --apply succeeded. Every reachable <p>-v<semver> tag is
now validated (annotated, peels to a landing of its own version); an
invalid one is an ERROR row naming it, blocks --apply, and is never the
start point.

Also from review:
- --apply needs origin/main and a ref on it; no local-main fallback.
- A version with literal quotes is invalid, not stripped.
- Plugin dirs are listed NUL-separated; a leading-dash name exits 2.
- With no tags, the backfill starts at the current version's first
  landing, so a recurring version is released once, there (Case 2, 12d).
- expect_row ERE-escapes plugin and version.

ADR-0033 updated to match.

Refs: #223

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-11-27 18:14:23 +00:00
1 parent b3cdcc9bbb
commit b3fd1f2f0c
3 files changed
+194 -37

No files matched your search

@@ -38,7 +38,9 @@ Two facts limit where enforcement can live:
landed on `main`, never a feature-branch commit. An `apm.yml` edit that leaves `version:` alone landed on `main`, never a feature-branch commit. An `apm.yml` edit that leaves `version:` alone
does not start a new run. does not start a new run.
- **Immutability.** Tags are never moved, overwritten or silently re-cut. A tag that is lightweight - **Immutability.** Tags are never moved, overwritten or silently re-cut. A tag that is lightweight
or that peels to no landing of its version is reported as an error for a human to resolve. or that peels to no landing of its version is reported as an error for a human to resolve. Every
reachable `<plugin>-v*` tag is checked this way, not only those of the wanted runs, and an
invalid one never decides where the wanted runs start, so it cannot hide the versions before it.
- **A version is released once, at its first landing.** When a version comes back (a reverted - **A version is released once, at its first landing.** When a version comes back (a reverted
bump, or an `apm.yml` deleted and re-added), the later run is not tagged again: its tag already bump, or an `apm.yml` deleted and re-added), the later run is not tagged again: its tag already
exists on the earlier run, so the script reports that run `RELEASED` and it blocks nothing. An exists on the earlier run, so the script reports that run `RELEASED` and it blocks nothing. An
@@ -47,14 +49,17 @@ Two facts limit where enforcement can live:
- **Mechanism.** `scripts/tag-plugin-releases.sh` computes the targets from `origin/main`'s - **Mechanism.** `scripts/tag-plugin-releases.sh` computes the targets from `origin/main`'s
history and cuts the tags after merge. Without arguments it is a dry run: it prints a history and cuts the tags after merge. Without arguments it is a dry run: it prints a
`plugin version commit status` table and exits 1 if any tag is missing. `--apply` creates the `plugin version commit status` table and exits 1 if any tag is missing. `--apply` creates the
missing tags locally, and only when no error exists anywhere (all or nothing). It then prints the missing tags locally, and only when no error exists anywhere (all or nothing) and the commit read
is on `origin/main`; it never falls back to the local `main`. It then prints the
exact `git push origin <tag>…` line, naming each tag explicitly and never using `--tags`. The exact `git push origin <tag>…` line, naming each tag explicitly and never using `--tags`. The
script never fetches and never pushes. No hook gates any of this. script never fetches and never pushes. No hook gates any of this.
- **Which versions are wanted.** If a plugin already has a `<plugin>-v*` tag reachable from - **Which versions are wanted.** If a plugin already has a valid `<plugin>-v*` tag reachable from
`main`, the script wants every version run from the newest such tag onward, including a reverted `main`, the script wants every version run from the newest such tag onward, including a reverted
version's run, which then reports `RELEASED` as above. If it has none, the script wants only the version's run, which then reports `RELEASED` as above. If it has none, the script wants every run
current run. That second rule is the backfill: older history is not from the first landing of the current version onward, so the current version is tagged at its
tagged retroactively. first landing anywhere in history and any later run of it reports `RELEASED`; when the current
version never recurred, that is the current run alone. That second rule is the backfill: older
history is not tagged retroactively.
- **One deliberate exception to the backfill: git's previous version, `git-v1.3.8`, is also - **One deliberate exception to the backfill: git's previous version, `git-v1.3.8`, is also
tagged**, on `32fbe39fb8923854ca8e743a0d2cad81720c736c`, where 1.3.8 first landed on `main`. This tagged**, on `32fbe39fb8923854ca8e743a0d2cad81720c736c`, where 1.3.8 first landed on `main`. This
gives a consumer pinned to an older git tag something real to check `apm outdated` against. It is gives a consumer pinned to an older git tag something real to check `apm outdated` against. It is
+91 -23
View File
@@ -11,9 +11,12 @@ set -euo pipefail
# (no flags) dry run: print the table, create nothing. # (no flags) dry run: print the table, create nothing.
# --apply create every MISSING tag locally, then print the exact # --apply create every MISSING tag locally, then print the exact
# `git push origin <tag>...` line. Pushing is the maintainer's # `git push origin <tag>...` line. Pushing is the maintainer's
# step; this script never pushes and never fetches. # step; this script never pushes and never fetches. Requires
# --ref <rev> the history to read (default origin/main, falling back to the # origin/main to resolve and the ref to be on it (an ancestor
# local `main` with a staleness note). # of, or equal to, origin/main); otherwise exit 2.
# --ref <rev> the history to read (default origin/main; a dry run falls
# back to the local `main` with a staleness note, --apply
# never does).
# --plugin <n> limit to these plugins (repeatable; default: every plugin). # --plugin <n> limit to these plugins (repeatable; default: every plugin).
# #
# Run `git fetch origin --tags` first. The script reads only local refs, so a # Run `git fetch origin --tags` first. The script reads only local refs, so a
@@ -33,12 +36,14 @@ set -euo pipefail
# the current run; it never starts a new one. A run's target is its oldest # the current run; it never starts a new one. A run's target is its oldest
# commit: the merge or squash commit on main where the version first # commit: the merge or squash commit on main where the version first
# landed, never a feature-branch commit. # landed, never a feature-branch commit.
# - Wanted runs: with no `<p>-v<semver>` tag reachable from the ref, only the # - Every `<p>-v<semver>` tag reachable from the ref is validated: it must be
# current run (the backfill). Otherwise every run from the newest such tag's # annotated and peel to a run target carrying its own version. Any other
# run onward. A tag's run is the run it targets; a tag targeting no run # such tag is an ERROR row naming it, and it never serves as the start
# counts as the last run whose target is its ancestor, so a mis-cut tag # point, so a mis-cut tag can neither hide runs nor go unreported.
# widens the wanted set rather than hiding runs. The anchor run itself is # - Wanted runs: every run from the newest validly tagged run onward. With
# re-checked, so a mis-cut tag surfaces as an ERROR. # no valid tag (the backfill), every run from the FIRST landing of the
# current version onward; when the current version never recurred, that is
# the current run alone. Older history is not tagged retroactively.
# - A version is released once, at its FIRST landing. When a version recurs # - 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 # (a revert, or apm.yml deleted and re-added), the later run is not tagged
# again: it reports RELEASED. # again: it reports RELEASED.
@@ -47,6 +52,8 @@ set -euo pipefail
# or the version is untagged and an earlier wanted run carries it, so that # 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 # run is the one tagged), ERROR (lightweight, peels to no landing of that
# version, invalid version in history, or a tag name git rejects). # version, invalid version in history, or a tag name git rejects).
# - A plugin directory whose name starts with `-` is rejected (exit 2): its
# tag name would parse as an option.
# RELEASED never blocks other rows and never changes the exit code. # RELEASED never blocks other rows and never changes the exit code.
# #
# Tag matching is anchored: `<p>-v` followed by a strict semver and nothing # Tag matching is anchored: `<p>-v` followed by a strict semver and nothing
@@ -59,7 +66,8 @@ set -euo pipefail
# #
# Exit: 0 nothing missing (or --apply created all of it); 1 dry run found # 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, # MISSING tags; 2 any ERROR, bad input, shallow clone, unresolvable ref,
# missing python3/PyYAML, or a `git tag` failure during --apply. # --apply off origin/main, missing python3/PyYAML, or a `git tag` failure
# during --apply.
export LC_ALL=C export LC_ALL=C
@@ -111,6 +119,8 @@ if [[ "$(git rev-parse --is-shallow-repository)" == "true" ]]; then
exit 2 exit 2
fi fi
is_ancestor() { git merge-base --is-ancestor "$1" "$2" 2>/dev/null; }
if [[ -n "$REF" ]]; then if [[ -n "$REF" ]]; then
if ! REF_COMMIT="$(git rev-parse --verify -q "$REF^{commit}")"; then if ! REF_COMMIT="$(git rev-parse --verify -q "$REF^{commit}")"; then
echo "FAIL: --ref $REF does not resolve to a commit." >&2 echo "FAIL: --ref $REF does not resolve to a commit." >&2
@@ -128,14 +138,28 @@ else
fi fi
fi fi
# --apply tags only commits on origin/main: never a feature-branch commit, and
# never the local `main`, which may hold unpushed work.
if $APPLY; then
if ! ORIGIN_MAIN="$(git rev-parse --verify -q "origin/main^{commit}")"; then
echo "FAIL: --apply needs origin/main, which does not resolve; run git fetch origin --tags first." >&2
exit 2
fi
if ! is_ancestor "$REF_COMMIT" "$ORIGIN_MAIN"; then
echo "FAIL: --apply: $REF (${REF_COMMIT:0:7}) is not on origin/main; release tags go only on main's history." >&2
exit 2
fi
fi
# Plugin directories at the ref: trees under plugins/ that carry apm.yml. # Plugin directories at the ref: trees under plugins/ that carry apm.yml.
# NUL-separated, so unusual names are read verbatim, never quoted.
ALL_PLUGINS=() ALL_PLUGINS=()
while IFS= read -r path; do while IFS= read -r -d '' path; do
p="${path#plugins/}" p="${path#plugins/}"
if git cat-file -e "$REF_COMMIT:plugins/$p/apm.yml" 2>/dev/null; then if git cat-file -e "$REF_COMMIT:plugins/$p/apm.yml" 2>/dev/null; then
ALL_PLUGINS+=("$p") ALL_PLUGINS+=("$p")
fi fi
done < <(git ls-tree -d --name-only "$REF_COMMIT" plugins/) done < <(git ls-tree -z -d --name-only "$REF_COMMIT" plugins/)
if [[ ${#PLUGINS[@]} -eq 0 ]]; then if [[ ${#PLUGINS[@]} -eq 0 ]]; then
PLUGINS=(${ALL_PLUGINS[@]+"${ALL_PLUGINS[@]}"}) PLUGINS=(${ALL_PLUGINS[@]+"${ALL_PLUGINS[@]}"})
@@ -157,6 +181,14 @@ if [[ ${#PLUGINS[@]} -eq 0 ]]; then
exit 2 exit 2
fi fi
# A leading dash would make the tag name `-x-v1.0.0` parse as an option.
for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
if [[ "$p" == -* ]]; then
echo "ERROR: plugins/$p: a plugin name must not start with '-' (its tag would parse as an option)." >&2
exit 2
fi
done
# Reads "<commit>" lines on stdin and, for plugin path $1, prints one line per # Reads "<commit>" lines on stdin and, for plugin path $1, prints one line per
# commit: "<commit> OK <name> <version>", "<commit> INVALID <name|-> -" when # commit: "<commit> OK <name> <version>", "<commit> INVALID <name|-> -" when
# the version is not strict semver or the YAML does not parse, or # the version is not strict semver or the YAML does not parse, or
@@ -191,7 +223,7 @@ for c in commits:
name = "-" if name is None else (str(name) or "-") name = "-" if name is None else (str(name) or "-")
if re.search(r"\s", name): if re.search(r"\s", name):
name = "<whitespace>" name = "<whitespace>"
ver = None if ver is None else str(ver).strip("\x27\"") ver = None if ver is None else str(ver)
if ver is not None and SEMVER.fullmatch(ver): if ver is not None and SEMVER.fullmatch(ver):
print(c, "OK", name, ver) print(c, "OK", name, ver)
else: else:
@@ -202,8 +234,6 @@ p.stdin.close(); p.wait()
SEMVER_RE='^(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})$' SEMVER_RE='^(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})$'
is_ancestor() { git merge-base --is-ancestor "$1" "$2" 2>/dev/null; }
# Result rows, index-matched (bash 3.2 has no declare -A). # Result rows, index-matched (bash 3.2 has no declare -A).
ROW_PLUGIN=(); ROW_VERSION=(); ROW_COMMIT=(); ROW_STATUS=(); ROW_DETAIL=() ROW_PLUGIN=(); ROW_VERSION=(); ROW_COMMIT=(); ROW_STATUS=(); ROW_DETAIL=()
add_row() { add_row() {
@@ -261,26 +291,53 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
done done
nruns=${#RUN_VER[@]} nruns=${#RUN_VER[@]}
# Anchor: the newest run a reachable <p>-v<semver> tag belongs to. # Start point: the newest run a VALID reachable <p>-v<semver> tag peels to.
# Every such tag is validated first: annotated, and peeling to a run target
# carrying its own version. Any other is recorded as bad: it is reported and
# never serves as the start point, so it cannot hide the runs before it.
anchor=-1 anchor=-1
BAD_TAG=(); BAD_VER=(); BAD_COMMIT=(); BAD_DETAIL=()
while IFS= read -r tagname; do while IFS= read -r tagname; do
[[ "$tagname" == "$p-v"* ]] || continue [[ "$tagname" == "$p-v"* ]] || continue
[[ "${tagname#"$p-v"}" =~ $SEMVER_RE ]] || continue tv="${tagname#"$p-v"}"
peeled="$(git rev-parse --verify -q "refs/tags/$tagname^{commit}")" || continue [[ "$tv" =~ $SEMVER_RE ]] || continue
if ! peeled="$(git rev-parse --verify -q "refs/tags/$tagname^{commit}")"; then
BAD_TAG+=("$tagname"); BAD_VER+=("$tv"); BAD_COMMIT+=("-")
BAD_DETAIL+=("$tagname does not peel to a commit")
continue
fi
is_ancestor "$peeled" "$REF_COMMIT" || continue is_ancestor "$peeled" "$REF_COMMIT" || continue
if [[ "$(git cat-file -t "refs/tags/$tagname")" != "tag" ]]; then
BAD_TAG+=("$tagname"); BAD_VER+=("$tv"); BAD_COMMIT+=("$peeled")
BAD_DETAIL+=("$tagname is a lightweight tag; it must be annotated")
continue
fi
pos=-1 pos=-1
for ((i = 0; i < nruns; i++)); do for ((i = 0; i < nruns; i++)); do
[[ "${RUN_TARGET[i]}" == "$peeled" ]] && pos=$i if [[ "${RUN_TARGET[i]}" == "$peeled" && "${RUN_VALID[i]}" == true && "${RUN_VER[i]}" == "$tv" ]]; then pos=$i; fi
done done
if [[ $pos -lt 0 ]]; then if [[ $pos -lt 0 ]]; then
for ((i = 0; i < nruns; i++)); do BAD_TAG+=("$tagname"); BAD_VER+=("$tv"); BAD_COMMIT+=("$peeled")
is_ancestor "${RUN_TARGET[i]}" "$peeled" && pos=$i BAD_DETAIL+=("$tagname peels to ${peeled:0:7}, which is no landing of $tv on the first-parent history")
done continue
fi fi
[[ $pos -gt $anchor ]] && anchor=$pos [[ $pos -gt $anchor ]] && anchor=$pos
done < <(git for-each-ref --format='%(refname:strip=2)' "refs/tags/$p-v*") done < <(git for-each-ref --format='%(refname:strip=2)' "refs/tags/$p-v*")
if [[ $anchor -lt 0 ]]; then first=$((nruns - 1)); else first=$anchor; fi if [[ $anchor -ge 0 ]]; then
first=$anchor
else
# Backfill: start at the current version's first landing, so it is
# released once, there; a later run of it then reports RELEASED.
cur_ver="${RUN_VER[nruns - 1]}"
first=$((nruns - 1))
for ((i = 0; i < nruns; i++)); do
if [[ "${RUN_VALID[i]}" == true && "${RUN_VER[i]}" == "$cur_ver" ]]; then first=$i; break; fi
done
fi
# Tags the run loop below reports itself, so the bad-tag rows skip them.
REPORTED=()
for ((i = first; i < nruns; i++)); do for ((i = first; i < nruns; i++)); do
v="${RUN_VER[i]}"; target="${RUN_TARGET[i]}" v="${RUN_VER[i]}"; target="${RUN_TARGET[i]}"
@@ -309,6 +366,7 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
fi fi
if [[ "$(git cat-file -t "refs/tags/$tag")" != "tag" ]]; then if [[ "$(git cat-file -t "refs/tags/$tag")" != "tag" ]]; then
add_row "$p" "$v" "$target" ERROR "$tag is a lightweight tag; it must be annotated" add_row "$p" "$v" "$target" ERROR "$tag is a lightweight tag; it must be annotated"
REPORTED+=("$tag")
continue continue
fi fi
peeled="$(git rev-parse --verify -q "refs/tags/$tag^{commit}" || true)" peeled="$(git rev-parse --verify -q "refs/tags/$tag^{commit}" || true)"
@@ -327,6 +385,16 @@ for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do
continue continue
fi fi
add_row "$p" "$v" "$target" ERROR "$tag peels to ${peeled:0:7}, not ${target:0:7} or any earlier landing of $v" add_row "$p" "$v" "$target" ERROR "$tag peels to ${peeled:0:7}, not ${target:0:7} or any earlier landing of $v"
REPORTED+=("$tag")
done
# Bad tags no wanted run reported: one ERROR row each, naming the tag.
for ((k = 0; k < ${#BAD_TAG[@]}; k++)); do
seen=false
for r in ${REPORTED[@]+"${REPORTED[@]}"}; do
[[ "$r" == "${BAD_TAG[k]}" ]] && { seen=true; break; }
done
$seen || add_row "$p" "${BAD_VER[k]}" "${BAD_COMMIT[k]}" ERROR "${BAD_DETAIL[k]}"
done done
done done
+92 -8
View File
@@ -44,6 +44,8 @@ write_apm() {
commit() { (cd "$1" && git add -A && git commit -q -m "${2:-change}"); } commit() { (cd "$1" && git add -A && git commit -q -m "${2:-change}"); }
head_sha() { git -C "$1" rev-parse HEAD; } head_sha() { git -C "$1" rev-parse HEAD; }
# --apply needs origin/main; point it at local main (no remote needed).
sync_origin() { git -C "$1" update-ref refs/remotes/origin/main refs/heads/main; }
# run <repo> [args...]: stdout+stderr, exit code in RC. # run <repo> [args...]: stdout+stderr, exit code in RC.
run() { run() {
@@ -57,10 +59,13 @@ expect_rc() {
if [[ "$RC" -eq "$want" ]]; then pass "$desc (exit $want)"; else fail "$desc: exit $RC, want $want"; echo "$OUT" | sed 's/^/ /'; fi if [[ "$RC" -eq "$want" ]]; then pass "$desc (exit $want)"; else fail "$desc: exit $RC, want $want"; echo "$OUT" | sed 's/^/ /'; fi
} }
# ERE-escape $1 so a version's dots match only dots.
ere_quote() { sed 's/[][\\.*^$+?(){}|/]/\\&/g' <<< "$1"; }
# expect_row <desc> <plugin> <version> <sha> <status> # expect_row <desc> <plugin> <version> <sha> <status>
expect_row() { expect_row() {
local desc="$1" re local desc="$1" re
re="^$2 +$3 +${4:0:7} +$5\$" re="^$(ere_quote "$2") +$(ere_quote "$3") +${4:0:7} +$5\$"
if grep -Eq "$re" <<< "$OUT"; then pass "$desc"; else fail "$desc: no row '$2 $3 ${4:0:7} $5'"; echo "$OUT" | sed 's/^/ /'; fi if grep -Eq "$re" <<< "$OUT"; then pass "$desc"; else fail "$desc: no row '$2 $3 ${4:0:7} $5'"; echo "$OUT" | sed 's/^/ /'; fi
} }
@@ -95,16 +100,25 @@ run "$R" --ref main
expect_row "reads the ref, not the working tree" alpha 1.1.0 "$MERGE_A" MISSING expect_row "reads the ref, not the working tree" alpha 1.1.0 "$MERGE_A" MISSING
(cd "$R" && git checkout -q -- .) (cd "$R" && git checkout -q -- .)
echo "Case 2: version goes X -> Y -> X -- only the current run is backfilled" echo "Case 2: version goes X -> Y -> X with no tags -- backfill starts at X's first landing"
R="$(new_repo)" R="$(new_repo)"
write_apm "$R" gamma 0.9.0; commit "$R" z; ZERO="$(head_sha "$R")"
write_apm "$R" gamma 1.0.0; commit "$R" a; FIRST="$(head_sha "$R")" write_apm "$R" gamma 1.0.0; commit "$R" a; FIRST="$(head_sha "$R")"
write_apm "$R" gamma 1.1.0; commit "$R" b write_apm "$R" gamma 1.1.0; commit "$R" b; SECOND="$(head_sha "$R")"
write_apm "$R" gamma 1.0.0; commit "$R" c; THIRD="$(head_sha "$R")" write_apm "$R" gamma 1.0.0; commit "$R" c; THIRD="$(head_sha "$R")"
run "$R" --ref main run "$R" --ref main
expect_rc "X->Y->X dry run" 1 expect_rc "X->Y->X dry run" 1
expect_row "target is the third run's commit" gamma 1.0.0 "$THIRD" MISSING expect_row "X is MISSING at its first landing" gamma 1.0.0 "$FIRST" MISSING
expect_rows "exactly one wanted row" gamma 1 expect_row "Y after it is MISSING" gamma 1.1.0 "$SECOND" MISSING
if ! grep -q "${FIRST:0:7}" <<< "$OUT"; then pass "first X run not named"; else fail "first X run named"; fi expect_row "X's later run is RELEASED" gamma 1.0.0 "$THIRD" RELEASED
expect_rows "three wanted rows" gamma 3
if ! grep -q "${ZERO:0:7}" <<< "$OUT"; then pass "history before X's first landing not named"; else fail "older run named"; fi
sync_origin "$R"
run "$R" --ref main --apply
expect_rc "backfill --apply" 0
if [[ "$(git -C "$R" rev-parse "gamma-v1.0.0^{commit}" 2>/dev/null)" == "$FIRST" ]]; then pass "gamma-v1.0.0 on the first landing"; else fail "gamma-v1.0.0 misplaced"; fi
run "$R" --ref main
expect_rc "dry run after backfill is clean (idempotent)" 0
echo "Case 3: non-bump edit to apm.yml does not start a new run" echo "Case 3: non-bump edit to apm.yml does not start a new run"
R="$(new_repo)" R="$(new_repo)"
@@ -184,6 +198,7 @@ expect_rows "older 1.0.0 not wanted" eta 3
if ! grep -q "${V10:0:7}" <<< "$OUT"; then pass "1.0.0 commit not named"; else fail "1.0.0 named"; fi if ! grep -q "${V10:0:7}" <<< "$OUT"; then pass "1.0.0 commit not named"; else fail "1.0.0 named"; fi
echo "Case 10: --apply creates annotated tags, prints explicit push line, is idempotent" echo "Case 10: --apply creates annotated tags, prints explicit push line, is idempotent"
sync_origin "$R"
run "$R" --ref main --apply run "$R" --ref main --apply
expect_rc "--apply" 0 expect_rc "--apply" 0
for pair in "1.2.0:$V12" "1.3.0:$V13"; do for pair in "1.2.0:$V12" "1.3.0:$V13"; do
@@ -205,6 +220,7 @@ R="$(new_repo)"
write_apm "$R" theta 1.0.0; write_apm "$R" iota 1.0.0; commit "$R" a; A="$(head_sha "$R")" write_apm "$R" theta 1.0.0; write_apm "$R" iota 1.0.0; commit "$R" a; A="$(head_sha "$R")"
write_apm "$R" iota 1.0.0 iota "Reworded."; commit "$R" b write_apm "$R" iota 1.0.0 iota "Reworded."; commit "$R" b
(cd "$R" && git tag iota-v1.0.0 "$A") (cd "$R" && git tag iota-v1.0.0 "$A")
sync_origin "$R"
run "$R" --ref main --apply run "$R" --ref main --apply
expect_rc "ERROR blocks --apply" 2 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 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
@@ -222,6 +238,7 @@ 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 "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 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 if grep -q "first landing ${KB:0:7}" <<< "$OUT"; then pass "note names the first landing"; else fail "no first-landing note"; fi
sync_origin "$R"
run "$R" --ref main --apply run "$R" --ref main --apply
expect_rc "--apply with a recurring version" 0 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 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
@@ -242,6 +259,7 @@ expect_rc "dry run: only bb is missing" 1
expect_row "aa 1.1.0 OK" aa 1.1.0 "$A2" OK 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 "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 expect_row "bb 1.2.0 MISSING" bb 1.2.0 "$B2" MISSING
sync_origin "$R"
run "$R" --ref main --apply run "$R" --ref main --apply
expect_rc "--apply after a revert" 0 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 "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
@@ -260,8 +278,9 @@ write_apm "$R" nu 1.0.0; write_apm "$R" xi 1.0.0; commit "$R" a; N1="$(head_sha
rm -r "$R/plugins/nu"; commit "$R" delete rm -r "$R/plugins/nu"; commit "$R" delete
write_apm "$R" nu 1.0.0; commit "$R" readd; N3="$(head_sha "$R")" write_apm "$R" nu 1.0.0; commit "$R" readd; N3="$(head_sha "$R")"
run "$R" --ref main --plugin nu run "$R" --ref main --plugin nu
expect_rows "untagged: one wanted row" nu 1 expect_rows "untagged: two wanted rows" nu 2
expect_row "untagged: target is the re-add" nu 1.0.0 "$N3" MISSING expect_row "untagged: first landing is MISSING" nu 1.0.0 "$N1" MISSING
expect_row "untagged: re-add is RELEASED" nu 1.0.0 "$N3" RELEASED
(cd "$R" && git tag -a nu-v1.0.0 -m x "$N1") (cd "$R" && git tag -a nu-v1.0.0 -m x "$N1")
run "$R" --ref main --plugin nu run "$R" --ref main --plugin nu
expect_rc "tagged before the delete" 0 expect_rc "tagged before the delete" 0
@@ -301,10 +320,15 @@ if grep -q "whitespace" <<< "$OUT"; then pass "message names whitespace"; else f
printf 'name: mu\nversion: "1.0.0 "\n' > "$R/plugins/mu/apm.yml"; commit "$R" b printf 'name: mu\nversion: "1.0.0 "\n' > "$R/plugins/mu/apm.yml"; commit "$R" b
run "$R" --ref main run "$R" --ref main
expect_rc "trailing space in version" 2 expect_rc "trailing space in version" 2
printf "name: mu\nversion: \"'1.0.0'\"\n" > "$R/plugins/mu/apm.yml"; commit "$R" c
run "$R" --ref main
expect_rc "literal quotes in version are invalid, not stripped" 2
if grep -q "no strict MAJOR.MINOR.PATCH" <<< "$OUT"; then pass "message names the invalid version"; else fail "no invalid-version message"; fi
echo "Case 12h: a tag name git rejects is an ERROR and nothing is created" echo "Case 12h: a tag name git rejects is an ERROR and nothing is created"
R="$(new_repo)" R="$(new_repo)"
write_apm "$R" rho 1.0.0; write_apm "$R" "a..b" 1.0.0; commit "$R" a write_apm "$R" rho 1.0.0; write_apm "$R" "a..b" 1.0.0; commit "$R" a
sync_origin "$R"
run "$R" --ref main --apply run "$R" --ref main --apply
expect_rc "invalid ref name blocks --apply" 2 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 grep -q "check-ref-format" <<< "$OUT"; then pass "message names check-ref-format"; else fail "no check-ref-format message"; fi
@@ -314,6 +338,7 @@ echo "Case 12i: a git tag failure mid --apply reports what was created"
R="$(new_repo)" R="$(new_repo)"
write_apm "$R" sa 1.0.0; write_apm "$R" sb 1.0.0; commit "$R" a 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" mkdir -p "$R/.git/refs/tags" && : > "$R/.git/refs/tags/sb-v1.0.0.lock"
sync_origin "$R"
run "$R" --ref main --apply run "$R" --ref main --apply
expect_rc "mid-run git tag failure" 2 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 [[ -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
@@ -322,6 +347,7 @@ if grep -qx "git push origin sa-v1.0.0" <<< "$OUT"; then pass "push line names w
echo "Case 12j: --apply with --plugin creates only that plugin's tag" echo "Case 12j: --apply with --plugin creates only that plugin's tag"
R="$(new_repo)" R="$(new_repo)"
write_apm "$R" ta 1.0.0; write_apm "$R" tb 1.0.0; commit "$R" a write_apm "$R" ta 1.0.0; write_apm "$R" tb 1.0.0; commit "$R" a
sync_origin "$R"
run "$R" --ref main --plugin ta --apply run "$R" --ref main --plugin ta --apply
expect_rc "--apply --plugin ta" 0 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 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
@@ -330,6 +356,7 @@ echo "Case 12k: --ref <older> --plugin <p> --apply tags that plugin's older vers
R="$(new_repo)" 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.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")" write_apm "$R" ua 1.1.0; write_apm "$R" ub 1.1.0; commit "$R" b; U2="$(head_sha "$R")"
sync_origin "$R"
run "$R" --ref "$U1" --plugin ua --apply run "$R" --ref "$U1" --plugin ua --apply
expect_rc "one-off older tag" 0 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" 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
@@ -350,6 +377,63 @@ expect_rc "default ref" 1
expect_row "reads origin/main's version" va 1.0.0 "$V1" MISSING 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 if ! grep -q "reading local main" <<< "$OUT"; then pass "no staleness note when origin/main resolves"; else fail "staleness note printed"; fi
echo "Case 12m: an invalid tag is never the start point and is reported"
R="$(new_repo)"
write_apm "$R" x 1.0.0; commit "$R" a; X10="$(head_sha "$R")"
write_apm "$R" x 1.1.0; commit "$R" b; X11="$(head_sha "$R")"
write_apm "$R" x 1.2.0; commit "$R" c; X12="$(head_sha "$R")"
write_apm "$R" x 1.3.0; commit "$R" d
(cd "$R" && git tag -a x-v1.0.0 -m x "$X10" && git tag -a x-v9.9.9 -m x "$X12")
sync_origin "$R"
run "$R" --ref main
expect_rc "wrong-version tag on a later landing" 2
expect_row "row names the wrong-version tag" x 9.9.9 "$X12" ERROR
if grep -q "x-v9.9.9 peels to ${X12:0:7}" <<< "$OUT"; then pass "message names x-v9.9.9"; else fail "x-v9.9.9 not named"; fi
expect_row "1.1.0 is still wanted (start point is x-v1.0.0)" x 1.1.0 "$X11" MISSING
run "$R" --ref main --apply
expect_rc "--apply blocked by the wrong-version tag" 2
if [[ "$(git -C "$R" tag -l | tr '\n' ' ')" == "x-v1.0.0 x-v9.9.9 " ]]; then pass "nothing created"; else fail "tags created: $(git -C "$R" tag -l | tr '\n' ' ')"; fi
(cd "$R" && git tag -d x-v9.9.9 > /dev/null && git tag x-v1.0.1 "$X12")
run "$R" --ref main
expect_rc "lightweight tag as start point" 2
expect_row "row names the lightweight tag" x 1.0.1 "$X12" ERROR
if grep -q "x-v1.0.1 is a lightweight tag" <<< "$OUT"; then pass "message names x-v1.0.1"; else fail "x-v1.0.1 not named"; fi
expect_row "1.1.0 is still wanted" x 1.1.0 "$X11" MISSING
run "$R" --ref main --apply
expect_rc "--apply blocked by the lightweight tag" 2
echo "Case 12n: --apply only tags history on origin/main"
R="$(new_repo)"
write_apm "$R" wa 1.0.0; commit "$R" a
(cd "$R" && git checkout -q -b feat)
write_apm "$R" wa 1.1.0; commit "$R" b; FEAT="$(head_sha "$R")"
(cd "$R" && git checkout -q main)
run "$R" --ref "$FEAT" --apply
expect_rc "--apply with no origin/main" 2
if [[ -z "$(git -C "$R" tag -l)" ]]; then pass "no tag without origin/main"; else fail "tag created without origin/main"; fi
run "$R" --apply
expect_rc "--apply refuses the local-main fallback" 2
sync_origin "$R"
run "$R" --ref "$FEAT" --apply
expect_rc "--apply --ref <feature-branch commit>" 2
if grep -q "not on origin/main" <<< "$OUT"; then pass "message names origin/main"; else fail "no origin/main message"; fi
if [[ -z "$(git -C "$R" tag -l)" ]]; then pass "no tag on a feature-branch commit"; else fail "tag created off main"; fi
run "$R" --ref "$FEAT"
expect_rc "dry run may still read a feature-branch ref" 1
echo "Case 12o: a plugin name starting with '-' exits 2"
R="$(new_repo)"
write_apm "$R" ok 1.0.0; write_apm "$R" "-x" 1.0.0; commit "$R" a
sync_origin "$R"
run "$R" --ref main --apply
expect_rc "leading-dash plugin" 2
if grep -q "must not start with '-'" <<< "$OUT"; then pass "message names the leading dash"; else fail "no leading-dash message"; fi
if [[ -z "$(git -C "$R" tag -l)" ]]; then pass "nothing created"; else fail "tags created"; fi
echo "Case 12p: expect_row matches a version's dots literally"
OUT="zz 1x0x0 abcdef0 OK"
if ! grep -Eq "^zz +$(ere_quote 1.0.0) +abcdef0 +OK\$" <<< "$OUT"; then pass "1.0.0 does not match 1x0x0"; else fail "unescaped dots"; fi
echo "Case 13: bad input exits 2" echo "Case 13: bad input exits 2"
run "$R" --ref no-such-ref run "$R" --ref no-such-ref
expect_rc "unresolvable --ref" 2 expect_rc "unresolvable --ref" 2