Skip to content

Commit a29136f

Browse files
authored
ci: accept API break approvals only after the published release (stable/9) (#474)
* ci: accept API break approvals only after the published release git log tag..HEAD also lists commits from histories that diverged before the published tag. After a stable branch reset, a labelled merge there could approve dropping API that only the published release had. --ancestry-path keeps only descendants of the tag; the manual override still covers an intentional rollback. Closes #471 * chore: count API break approvals only on the release line git log --ancestry-path tag..HEAD still accepts a labelled merge when a reset release branch reaches the published tag only through a second parent: every later merge descends from the tag, though none was made on the line it was released from. Require the tag on HEAD's first-parent history and list only first-parent commits after it; otherwise only the manual override can approve the release.
1 parent cec96ba commit a29136f

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

‎scripts/api-break-approvals.sh‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@
33
#
44
# Prints `#N <merge-sha>` for each PR labelled api-break-approved that was merged into
55
# <release-branch> after <baseline-tag>, newest merge first. A label on a PR merged elsewhere
6-
# (say `main`, whose commits a backport shares) or before the baseline approves nothing here.
6+
# (say `main`, whose commits a backport shares) or before the baseline approves nothing here,
7+
# and nothing does unless the tag is on HEAD's first-parent line (a reset or merged-back
8+
# release branch); the manual override still covers that.
79
# Exits non-zero if a lookup fails, so the caller can tell "none" from "unknown".
810
set -euo pipefail
911

1012
tag="$1"
1113
branch="$2"
12-
shas=$(git log --format=%H "${tag}..HEAD")
14+
tag_sha=$(git rev-parse --verify "${tag}^{commit}")
15+
line=$(git rev-list --first-parent HEAD)
16+
if ! grep -qx "$tag_sha" <<<"$line"; then
17+
echo "::notice::${tag} is not on the first-parent history of HEAD; no label can approve this release." >&2
18+
exit 0
19+
fi
20+
shas=$(git log --first-parent --format=%H "${tag}..HEAD")
1321

1422
# A file, not `$(...)`: command substitution does not inherit `set -e`, so a failed lookup
1523
# on any but the last commit would be swallowed.

‎tests/acceptance/test_api_compat.py‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,9 @@ def test_describe_output_is_json_serialisable(baseline: Any) -> None:
10211021
"git": """
10221022
case "$1 $2" in
10231023
"rev-parse --show-toplevel") echo "$FAKE_STATE" ;;
1024-
"rev-parse HEAD"|"rev-parse --short") echo abc123 ;;
1025-
"log --format=%H") [ -z "${FAKE_GIT_LOG_FAIL:-}" ] || exit 128; echo abc123 ;;
1024+
"rev-parse HEAD"|"rev-parse --short"|"rev-parse --verify") echo abc123 ;;
1025+
"rev-list --first-parent") echo abc123 ;;
1026+
"log --first-parent") [ -z "${FAKE_GIT_LOG_FAIL:-}" ] || exit 128; echo abc123 ;;
10261027
"log -1") echo "fix: something" ;;
10271028
"merge-base "*) exit 1 ;;
10281029
esac
@@ -1282,6 +1283,38 @@ def test_approval_search_scope(
12821283
assert bool(proc.stdout.strip()) == approves, proc.stdout
12831284

12841285

1286+
@pytest.mark.skipif(not shutil.which("jq"), reason="the gh stub applies --jq with jq")
1287+
def test_approval_search_ignores_merges_outside_the_published_history(
1288+
search_repo: dict[str, Any],
1289+
) -> None:
1290+
# A reset or recreated release branch: the published tag is not an ancestor of HEAD.
1291+
repo, head = search_repo["repo"], search_repo["second"]
1292+
published = _git(
1293+
repo, "-c", "user.name=t", "-c", "user.email=t@t",
1294+
"commit-tree", "HEAD^{tree}", "-p", f"{search_repo['first']}^", "-m", "published",
1295+
)
1296+
_git(repo, "tag", "-f", "v10.1.5", published)
1297+
proc = _search(search_repo, **{head: json.dumps([_pr(1, "stable/10", head)])})
1298+
assert (proc.returncode, proc.stdout) == (0, ""), proc.stderr
1299+
1300+
1301+
@pytest.mark.skipif(not shutil.which("jq"), reason="the gh stub applies --jq with jq")
1302+
def test_approval_search_ignores_a_tag_reached_only_through_a_second_parent(
1303+
search_repo: dict[str, Any],
1304+
) -> None:
1305+
# A reset release branch that merged the published history back in: every later merge
1306+
# descends from the tag, but none was made on the line the tag was released from.
1307+
repo, first = search_repo["repo"], search_repo["first"]
1308+
git = ("-c", "user.name=t", "-c", "user.email=t@t", "commit-tree", "HEAD^{tree}")
1309+
published = _git(repo, *git, "-p", f"{first}^", "-m", "published")
1310+
_git(repo, "tag", "-f", "v10.1.5", published)
1311+
merged = _git(repo, *git, "-p", "HEAD", "-p", published, "-m", "merge old history")
1312+
approved = _git(repo, *git, "-p", merged, "-m", "labelled PR")
1313+
_git(repo, "reset", "-q", "--hard", approved)
1314+
proc = _search(search_repo, **{approved: json.dumps([_pr(9, "stable/10", approved)])})
1315+
assert (proc.returncode, proc.stdout) == (0, ""), proc.stderr
1316+
1317+
12851318
@pytest.mark.skipif(not shutil.which("jq"), reason="the gh stub applies --jq with jq")
12861319
def test_approval_search_lists_newest_merge_first(search_repo: dict[str, Any]) -> None:
12871320
first, second = search_repo["first"], search_repo["second"]

0 commit comments

Comments
 (0)