From bc53b98d610e34ba1d145eee607f39b79bc4d151 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 27 Nov 2026 17:40:39 +0000 Subject: [PATCH] feat(scripts): add tag-plugin-releases.sh to cut per-plugin release tags Consumers pinning a holocron package (Renovate's apm manager, apm outdated) need a -v tag per plugin version; the repo-level v* tags match no plugin. The script derives each wanted tag from the ref's first-parent history of plugins/

/apm.yml, targeting the commit where the version first landed on main. It is a dry run by default (exit 1 when tags are missing); --apply creates the missing tags locally and prints the push command. It never pushes, fetches, moves, or deletes a tag. Refs: #223 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi --- scripts/tag-plugin-releases.sh | 356 ++++++++++++++++++++++++++++++ tests/test-tag-plugin-releases.sh | 238 ++++++++++++++++++++ 2 files changed, 594 insertions(+) create mode 100755 scripts/tag-plugin-releases.sh create mode 100755 tests/test-tag-plugin-releases.sh diff --git a/scripts/tag-plugin-releases.sh b/scripts/tag-plugin-releases.sh new file mode 100755 index 0000000..66f7250 --- /dev/null +++ b/scripts/tag-plugin-releases.sh @@ -0,0 +1,356 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Cuts the per-plugin release tags ADR-0033 requires: one annotated tag +# `-v` per version a plugin ships on main, on the commit where +# that version first landed. Consumers pin these (Renovate's apm manager, `apm +# outdated`); the repo-level v* tags match no plugin. +# +# Usage: scripts/tag-plugin-releases.sh [--apply] [--ref ] [--plugin ]... +# +# (no flags) dry run: print the table, create nothing. +# --apply create every MISSING tag locally, then print the exact +# `git push origin ...` line. Pushing is the maintainer's +# step; this script never pushes and never fetches. +# --ref the history to read (default origin/main, falling back to the +# local `main` with a staleness note). +# --plugin limit to these plugins (repeatable; default: every plugin). +# +# Run `git fetch origin --tags` first. The script reads only local refs, so a +# stale origin/main hides a merged bump and a missing remote tag reads MISSING. +# +# Everything is read from the ref's git objects (`git ls-tree`, `git show`), +# never the working tree, so a dirty checkout or another branch cannot change +# the answer. +# +# 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. +# - 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 +# 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 +# landed, never a feature-branch commit. +# - Wanted runs: with no `

-v` tag reachable from the ref, only the +# current run (the backfill). Otherwise every run from the newest such tag's +# run onward. A tag's run is the run it targets; a tag targeting no run +# 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. +# - 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). +# +# 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. +# +# 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. + +export LC_ALL=C + +# shellcheck source=scripts/lib/clean-git-env.sh +source "$(dirname "${BASH_SOURCE[0]}")/lib/clean-git-env.sh" + +usage() { + echo "Usage: $0 [--apply] [--ref ] [--plugin ]..." >&2 +} + +APPLY=false +REF="" +PLUGINS=() +while [[ $# -gt 0 ]]; do + case "$1" in + --apply) APPLY=true; shift ;; + --ref) + [[ $# -ge 2 && -n "$2" ]] || { usage; exit 2; } + REF="$2"; shift 2 ;; + --plugin) + [[ $# -ge 2 && -n "$2" ]] || { usage; exit 2; } + PLUGINS+=("$2"); shift 2 ;; + -h|--help) usage; exit 0 ;; + *) echo "FAIL: unknown argument: $1" >&2; usage; exit 2 ;; + esac +done + +if ! REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)"; then + echo "FAIL: not inside a git work tree." >&2 + exit 2 +fi +cd "$REPO_ROOT" + +if ! command -v python3 > /dev/null 2>&1; then + echo "FAIL: python3 is required to read apm.yml but was not found on PATH." >&2 + exit 2 +fi +if ! python3 -c 'import yaml' > /dev/null 2>&1; then + echo "FAIL: PyYAML is required to read apm.yml but is not importable by python3." >&2 + echo " Fix: python3 -m pip install PyYAML (or your distro's python3-yaml package)." >&2 + exit 2 +fi + +# A shallow clone truncates first-parent history, so the oldest commit of a run +# would be wrong without any error. Fail closed. +if [[ "$(git rev-parse --is-shallow-repository)" == "true" ]]; then + echo "FAIL: shallow clone; run targets cannot be computed from truncated history." >&2 + echo " Fix: git fetch --unshallow origin, then retry." >&2 + exit 2 +fi + +if [[ -n "$REF" ]]; then + if ! REF_COMMIT="$(git rev-parse --verify -q "$REF^{commit}")"; then + echo "FAIL: --ref $REF does not resolve to a commit." >&2 + exit 2 + fi +else + if REF_COMMIT="$(git rev-parse --verify -q "origin/main^{commit}")"; then + REF="origin/main" + elif REF_COMMIT="$(git rev-parse --verify -q "main^{commit}")"; then + REF="main" + echo "NOTE: origin/main does not resolve; reading local main, which may be behind the remote." >&2 + else + echo "FAIL: neither origin/main nor main resolves; pass --ref ." >&2 + exit 2 + fi +fi + +# Plugin directories at the ref: trees under plugins/ that carry apm.yml. +ALL_PLUGINS=() +while IFS= read -r path; do + p="${path#plugins/}" + if git cat-file -e "$REF_COMMIT:plugins/$p/apm.yml" 2>/dev/null; then + ALL_PLUGINS+=("$p") + fi +done < <(git ls-tree -d --name-only "$REF_COMMIT" plugins/) + +if [[ ${#PLUGINS[@]} -eq 0 ]]; then + PLUGINS=(${ALL_PLUGINS[@]+"${ALL_PLUGINS[@]}"}) +else + for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do + found=false + for q in ${ALL_PLUGINS[@]+"${ALL_PLUGINS[@]}"}; do + [[ "$p" == "$q" ]] && { found=true; break; } + done + if ! $found; then + echo "FAIL: --plugin $p: no plugins/$p/apm.yml at $REF." >&2 + exit 2 + fi + done +fi + +if [[ ${#PLUGINS[@]} -eq 0 ]]; then + echo "FAIL: no plugins//apm.yml found at $REF." >&2 + exit 2 +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 +# `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. +read_versions() { + python3 -c ' +import re, subprocess, sys, yaml +path = sys.argv[1] +commits = [l.strip() for l in sys.stdin if l.strip()] +p = subprocess.Popen(["git", "cat-file", "--batch"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) +SEMVER = re.compile(r"(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})") +for c in commits: + p.stdin.write(("%s:%s\n" % (c, path)).encode()); p.stdin.flush() + header = p.stdout.readline().decode().split() + if len(header) < 3 or header[-1] == "missing": + print(c, "ABSENT - -"); continue + if header[1] != "blob": + p.stdout.read(int(header[2])); p.stdout.readline() + print(c, "ABSENT - -"); continue + data = p.stdout.read(int(header[2])); p.stdout.readline() + try: + doc = yaml.safe_load(data.decode("utf-8-sig", errors="replace")) + except yaml.YAMLError: + 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\"") + if ver is not None and SEMVER.fullmatch(ver): + print(c, "OK", name, ver) + else: + print(c, "INVALID", name, "-") +p.stdin.close(); p.wait() +' "$1" +} + +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). +ROW_PLUGIN=(); ROW_VERSION=(); ROW_COMMIT=(); ROW_STATUS=(); ROW_DETAIL=() +add_row() { + ROW_PLUGIN+=("$1"); ROW_VERSION+=("$2"); ROW_COMMIT+=("$3"); ROW_STATUS+=("$4"); ROW_DETAIL+=("$5") +} + +for p in ${PLUGINS[@]+"${PLUGINS[@]}"}; do + apm="plugins/$p/apm.yml" + + # Oldest first. --first-parent with a path keeps each first-parent commit + # whose apm.yml differs from its first parent's: on main that is the merge + # or squash commit that brought the change in. + COMMITS=() + while IFS= read -r c; do COMMITS+=("$c"); done \ + < <(git rev-list --first-parent --reverse "$REF_COMMIT" -- "$apm") + + LINES=() + while IFS= read -r l; do LINES+=("$l"); done \ + < <(printf '%s\n' ${COMMITS[@]+"${COMMITS[@]}"} | read_versions "$apm") + if [[ ${#LINES[@]} -ne ${#COMMITS[@]} ]]; then + echo "FAIL: could not read $apm across $REF history (see error above)." >&2 + exit 2 + fi + + # 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" != "$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 + exit 2 + fi + + # Group into runs. A commit where the file is absent breaks contiguity. + RUN_VER=(); RUN_TARGET=(); RUN_VALID=() + prev="" + for l in ${LINES[@]+"${LINES[@]}"}; do + read -r c st _ v <<< "$l" + case "$st" in + ABSENT) prev=""; continue ;; + INVALID) key="INVALID" ;; + *) key="$v" ;; + esac + if [[ "$key" != "$prev" ]]; then + RUN_VER+=("$v"); RUN_TARGET+=("$c") + if [[ "$st" == OK ]]; then RUN_VALID+=(true); else RUN_VALID+=(false); fi + prev="$key" + fi + done + nruns=${#RUN_VER[@]} + + # Anchor: the newest run a reachable

-v tag belongs to. + anchor=-1 + while IFS= read -r tagname; do + [[ "$tagname" == "$p-v"* ]] || continue + [[ "${tagname#"$p-v"}" =~ $SEMVER_RE ]] || continue + peeled="$(git rev-parse --verify -q "refs/tags/$tagname^{commit}")" || continue + is_ancestor "$peeled" "$REF_COMMIT" || continue + pos=-1 + for ((i = 0; i < nruns; i++)); do + [[ "${RUN_TARGET[i]}" == "$peeled" ]] && pos=$i + done + if [[ $pos -lt 0 ]]; then + for ((i = 0; i < nruns; i++)); do + is_ancestor "${RUN_TARGET[i]}" "$peeled" && pos=$i + done + fi + [[ $pos -gt $anchor ]] && anchor=$pos + 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 + + for ((i = first; i < nruns; i++)); do + v="${RUN_VER[i]}"; target="${RUN_TARGET[i]}" + if [[ "${RUN_VALID[i]}" != true ]]; then + 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 + add_row "$p" "$v" "$target" MISSING "" + continue + fi + 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" + 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}" + continue + fi + add_row "$p" "$v" "$target" OK "" + done +done + +print_table() { + local i + printf '%-12s %-10s %-8s %s\n' PLUGIN VERSION COMMIT STATUS + for ((i = 0; i < ${#ROW_PLUGIN[@]}; i++)); do + printf '%-12s %-10s %-8s %s\n' "${ROW_PLUGIN[i]}" "${ROW_VERSION[i]}" "${ROW_COMMIT[i]:0:7}" "${ROW_STATUS[i]}" + done +} + +ERRORS=0; MISSING=0 +for ((i = 0; i < ${#ROW_STATUS[@]}; i++)); do + case "${ROW_STATUS[i]}" in + ERROR) ERRORS=$((ERRORS + 1)) ;; + MISSING) MISSING=$((MISSING + 1)) ;; + esac +done + +report_errors() { + local i + for ((i = 0; i < ${#ROW_STATUS[@]}; i++)); do + [[ "${ROW_STATUS[i]}" == ERROR ]] && echo "ERROR: ${ROW_PLUGIN[i]}: ${ROW_DETAIL[i]}" >&2 + done + echo "Tags are immutable: fix by hand only after deciding which commit each version belongs to (ADR-0033)." >&2 +} + +if ! $APPLY; then + print_table + 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 + exit 1 + fi + exit 0 +fi + +if [[ $ERRORS -gt 0 ]]; then + print_table + report_errors + echo "Nothing created: --apply is all-or-nothing." >&2 + exit 2 +fi + +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]}" + 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 +exit 0 diff --git a/tests/test-tag-plugin-releases.sh b/tests/test-tag-plugin-releases.sh new file mode 100755 index 0000000..07eae4b --- /dev/null +++ b/tests/test-tag-plugin-releases.sh @@ -0,0 +1,238 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Tests for scripts/tag-plugin-releases.sh (ADR-0033). Every case builds its +# own throwaway repo; none touches this repo's tags. + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +SCRIPT="$REPO_ROOT/scripts/tag-plugin-releases.sh" +PASS=0 +FAIL=0 + +pass() { echo " PASS: $1"; PASS=$((PASS + 1)); } +fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); } + +if ! python3 -c 'import yaml' 2>/dev/null; then + echo "SKIP: python3 with PyYAML is required" >&2 + exit 77 +fi + +# Fixtures must not inherit the caller's repo (see tests/run-tests.sh, #204). +unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR + +# Output assertions use here-strings, never `echo | grep -q` (pipefail race; +# see docs/spec/gates.md, Tests). + +CLEANUP_DIRS=() +trap 'rm -rf ${CLEANUP_DIRS[@]+"${CLEANUP_DIRS[@]}"}' EXIT + +new_repo() { + local dir + dir="$(mktemp -d)" + CLEANUP_DIRS+=("$dir") + (cd "$dir" && git init -q -b main && git config user.email t@t.t && git config user.name t \ + && git config tag.gpgSign false && git config commit.gpgSign false) + echo "$dir" +} + +# write_apm

[name] [description] +write_apm() { + local repo="$1" dir="$2" ver="$3" name="${4:-$2}" desc="${5:-A plugin.}" + mkdir -p "$repo/plugins/$dir" + printf 'name: %s\nversion: %s\ndescription: %s\n' "$name" "$ver" "$desc" > "$repo/plugins/$dir/apm.yml" +} + +commit() { (cd "$1" && git add -A && git commit -q -m "${2:-change}"); } +head_sha() { git -C "$1" rev-parse HEAD; } + +# run [args...]: stdout+stderr, exit code in RC. +run() { + local dir="$1"; shift + RC=0 + OUT="$(cd "$dir" && bash "$SCRIPT" "$@" 2>&1)" || RC=$? +} + +expect_rc() { + local desc="$1" want="$2" + if [[ "$RC" -eq "$want" ]]; then pass "$desc (exit $want)"; else fail "$desc: exit $RC, want $want"; echo "$OUT" | sed 's/^/ /'; fi +} + +# expect_row +expect_row() { + local desc="$1" re + re="^$2 +$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 +} + +# expect_rows +expect_rows() { + local n + n="$(grep -Ec "^$2 " <<< "$OUT" || true)" + if [[ "$n" -eq "$3" ]]; then pass "$1"; else fail "$1: $n rows for $2, want $3"; echo "$OUT" | sed 's/^/ /'; fi +} + +echo "Case 1: merge commit vs squash -- target is the commit on main's first-parent line" +R="$(new_repo)" +write_apm "$R" alpha 1.0.0; write_apm "$R" beta 1.0.0; commit "$R" init +(cd "$R" && git checkout -q -b feat-a) +write_apm "$R" alpha 1.1.0; commit "$R" "bump alpha" +BRANCH_A="$(head_sha "$R")" +(cd "$R" && git checkout -q main && git merge -q --no-ff -m "merge a" feat-a) +MERGE_A="$(head_sha "$R")" +(cd "$R" && git checkout -q -b feat-b) +write_apm "$R" beta 1.1.0; commit "$R" "bump beta" +(cd "$R" && git checkout -q main && git merge -q --squash feat-b > /dev/null && git commit -q -m "squash b") +SQUASH_B="$(head_sha "$R")" +run "$R" +expect_rc "dry run with missing tags" 1 +expect_row "merge: alpha 1.1.0 targets the merge commit" alpha 1.1.0 "$MERGE_A" MISSING +expect_row "squash: beta 1.1.0 targets the squash commit" beta 1.1.0 "$SQUASH_B" MISSING +if ! grep -q "${BRANCH_A:0:7}" <<< "$OUT"; then pass "feature-branch commit is never a target"; else fail "feature-branch commit named"; fi +if grep -q "reading local main" <<< "$OUT"; then pass "falls back to local main with a staleness note"; else fail "no staleness note"; fi +(cd "$R" && git checkout -q -b elsewhere && git checkout -q main) +write_apm "$R" alpha 9.9.9 > /dev/null; # working-tree edit must not count +run "$R" --ref main +expect_row "reads the ref, not the working tree" alpha 1.1.0 "$MERGE_A" MISSING +(cd "$R" && git checkout -q -- .) + +echo "Case 2: version goes X -> Y -> X -- only the current run is backfilled" +R="$(new_repo)" +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.0.0; commit "$R" c; THIRD="$(head_sha "$R")" +run "$R" --ref main +expect_rc "X->Y->X dry run" 1 +expect_row "target is the third run's commit" gamma 1.0.0 "$THIRD" MISSING +expect_rows "exactly one wanted row" gamma 1 +if ! grep -q "${FIRST:0:7}" <<< "$OUT"; then pass "first X run not named"; else fail "first X run named"; fi + +echo "Case 3: non-bump edit to apm.yml does not start a new run" +R="$(new_repo)" +write_apm "$R" delta 2.0.0; commit "$R" a; BUMP="$(head_sha "$R")" +write_apm "$R" delta 2.0.0 delta "Reworded."; commit "$R" b; EDIT="$(head_sha "$R")" +run "$R" --ref main +expect_row "target stays on the bump commit" delta 2.0.0 "$BUMP" MISSING +expect_rows "one row only" delta 1 +if ! grep -q "${EDIT:0:7}" <<< "$OUT"; then pass "edit commit not a target"; else fail "edit commit named"; fi + +echo "Case 4: existing lightweight tag is an ERROR" +(cd "$R" && git tag delta-v2.0.0 "$BUMP") +run "$R" --ref main +expect_rc "lightweight tag" 2 +expect_row "row is ERROR" delta 2.0.0 "$BUMP" ERROR +if grep -q "lightweight" <<< "$OUT"; then pass "message names lightweight"; else fail "no lightweight message"; fi + +echo "Case 5: annotated tag on the wrong commit is an ERROR" +(cd "$R" && git tag -d delta-v2.0.0 > /dev/null && git tag -a delta-v2.0.0 -m x "$EDIT") +run "$R" --ref main +expect_rc "tag on a later commit" 2 +expect_row "row is ERROR" delta 2.0.0 "$BUMP" ERROR +if grep -q "peels to ${EDIT:0:7}" <<< "$OUT"; then pass "message names where it peels"; else fail "no peel message"; fi +(cd "$R" && git tag -d delta-v2.0.0 > /dev/null && git tag -a delta-v2.0.0 -m x "$BUMP") +run "$R" --ref main +expect_rc "same tag on the right commit" 0 +expect_row "row is OK" delta 2.0.0 "$BUMP" OK + +echo "Case 6: shallow clone exits 2" +S="$(mktemp -d)"; CLEANUP_DIRS+=("$S") +git clone -q --depth 1 "file://$R" "$S/c" 2>/dev/null +run "$S/c" +expect_rc "shallow clone" 2 +if grep -q "shallow" <<< "$OUT"; then pass "message names shallow"; else fail "no shallow message"; fi + +echo "Case 7: apm.yml name differs from directory exits 2" +R="$(new_repo)" +write_apm "$R" eps 1.0.0 epsilon; commit "$R" a +run "$R" --ref main +expect_rc "name != dir" 2 +if grep -q "must equal the directory" <<< "$OUT"; then pass "message names the mismatch"; else fail "no mismatch message"; fi + +echo "Case 7b: non-semver current version exits 2" +R="$(new_repo)" +write_apm "$R" zeta 1.0; commit "$R" a +run "$R" --ref main +expect_rc "version 1.0" 2 + +echo "Case 8: prefix-sharing names (git, gitea) never claim each other's tags" +R="$(new_repo)" +write_apm "$R" git 0.1.0; write_apm "$R" gitea 1.0.0; commit "$R" a; C1="$(head_sha "$R")" +write_apm "$R" git 0.2.0; write_apm "$R" gitea 1.1.0; commit "$R" b; C2="$(head_sha "$R")" +(cd "$R" && git tag -a gitea-v1.0.0 -m x "$C1") +run "$R" --ref main +expect_rows "git: gitea's tag is not its anchor -- current run only" git 1 +expect_row "git 0.2.0 MISSING" git 0.2.0 "$C2" MISSING +expect_rows "gitea: anchored at its own tag" gitea 2 +expect_row "gitea 1.0.0 OK" gitea 1.0.0 "$C1" OK +expect_row "gitea 1.1.0 MISSING" gitea 1.1.0 "$C2" MISSING +run "$R" --ref main --plugin git +expect_rows "--plugin git lists no gitea row" gitea 0 +expect_rows "--plugin git lists git" git 1 + +echo "Case 9: every run after the newest tag is wanted" +R="$(new_repo)" +write_apm "$R" eta 1.0.0; commit "$R" a; V10="$(head_sha "$R")" +write_apm "$R" eta 1.1.0; commit "$R" b; V11="$(head_sha "$R")" +write_apm "$R" eta 1.2.0; commit "$R" c; V12="$(head_sha "$R")" +write_apm "$R" eta 1.3.0; commit "$R" d; V13="$(head_sha "$R")" +(cd "$R" && git tag -a eta-v1.1.0 -m x "$V11") +run "$R" --ref main +expect_rc "later runs missing" 1 +expect_row "anchor 1.1.0 OK" eta 1.1.0 "$V11" OK +expect_row "1.2.0 MISSING" eta 1.2.0 "$V12" MISSING +expect_row "1.3.0 MISSING" eta 1.3.0 "$V13" MISSING +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 + +echo "Case 10: --apply creates annotated tags, prints explicit push line, is idempotent" +run "$R" --ref main --apply +expect_rc "--apply" 0 +for pair in "1.2.0:$V12" "1.3.0:$V13"; do + v="${pair%%:*}"; sha="${pair#*:}" + if [[ "$(git -C "$R" cat-file -t "refs/tags/eta-v$v" 2>/dev/null)" == tag ]]; then pass "eta-v$v is annotated"; else fail "eta-v$v not annotated"; fi + if [[ "$(git -C "$R" rev-parse "eta-v$v^{commit}" 2>/dev/null)" == "$sha" ]]; then pass "eta-v$v peels to its target"; else fail "eta-v$v wrong target"; fi +done +if [[ "$(git -C "$R" tag -l --format='%(contents:subject)' eta-v1.3.0)" == "eta 1.3.0" ]]; then pass "tag message is '

'"; else fail "tag message wrong"; fi +if grep -qx "git push origin eta-v1.2.0 eta-v1.3.0" <<< "$OUT"; then pass "push line names each tag"; else fail "push line wrong"; echo "$OUT" | sed 's/^/ /'; fi +if ! grep -q -- "--tags" <<< "$OUT"; then pass "push line never uses --tags"; else fail "--tags printed"; fi +run "$R" --ref main --apply +expect_rc "second --apply" 0 +if ! grep -q "git push" <<< "$OUT"; then pass "second --apply creates nothing"; else fail "second --apply printed a push line"; fi +run "$R" --ref main +expect_rc "dry run after --apply" 0 + +echo "Case 11: --apply is all-or-nothing" +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" iota 1.0.0 iota "Reworded."; commit "$R" b +(cd "$R" && git tag iota-v1.0.0 "$A") +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" +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 +(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 + +echo "Case 13: bad input exits 2" +run "$R" --ref no-such-ref +expect_rc "unresolvable --ref" 2 +run "$R" --ref main --plugin nope +expect_rc "unknown --plugin" 2 +run "$R" --bogus +expect_rc "unknown flag" 2 +R="$(new_repo)" +write_apm "$R" lam 1.0.0; commit "$R" a +(cd "$R" && git branch -q -m trunk) +run "$R" +expect_rc "no origin/main or main" 2 + +echo +echo "Results: $PASS passed, $FAIL failed" +[[ $FAIL -eq 0 ]]