Skip to content

Commit f6f9dd9

Browse files
CrazyBaranclaude
andcommitted
fix(ci): diff the extension version guard against the merge commit's first parent
The guard diffed github.event.pull_request.base.sha against the checked-out pull-request merge commit. Those two are not built from the same base: the payload SHA is the base-branch tip from when the PR was opened and is not refreshed when the base moves, while refs/pull/N/merge is rebuilt against the current tip. Any base-branch drift between the two is then attributed to the PR. Observed on #4395 itself: base.sha was main as of Sep 1 (3eec154), the merge commit was built on main as of Sep 3 (db64869), and two unbumped bundled-extension changes merged in between (#4413 touching agent-context, #4286 touching git) failed the guard on a PR that never touched either. Fetch the merge commit with depth 2 so both parents are available and diff against HEAD^1, which is by construction the base the merge was built on. Fail loudly if HEAD is not a merge commit. The script's CLI is unchanged; a regression test reproduces the trap in a throwaway repo (the stale base blames the drift on the PR, HEAD^1 does not). Refs #4345 Assisted-by: Claude Code (model: claude-fable-5-1) Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 23f252b commit f6f9dd9

2 files changed

Lines changed: 47 additions & 8 deletions

File tree

‎.github/workflows/extension-version-guard.yml‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ jobs:
2424
- name: Checkout
2525
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2626
with:
27-
fetch-depth: 1
27+
# The pull_request checkout is GitHub's merge of the PR head into
28+
# the base tip. Depth 2 also fetches both parents of that merge
29+
# commit, so HEAD^1 - the base the merge was actually built on -
30+
# is available to diff against.
31+
fetch-depth: 2
2832

2933
- name: Set up Python
3034
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
@@ -34,13 +38,20 @@ jobs:
3438
- name: Install check dependencies
3539
run: python -m pip install --quiet pyyaml packaging
3640

37-
# For pull_request events the checkout is the merge of the PR head
38-
# into the base tip, so diffing base.sha against HEAD yields exactly
39-
# the PR's changes (same fetch pattern as lint.yml).
41+
# Diff against the merge commit's first parent, NOT against
42+
# github.event.pull_request.base.sha. The payload SHA is the base tip
43+
# from when the PR was opened and is not refreshed when the base branch
44+
# moves, while refs/pull/N/merge is rebuilt against the current tip.
45+
# Diffing the stale SHA against the fresh merge commit attributes
46+
# unrelated base-branch drift to the PR (observed on #4395: two
47+
# unbumped extension changes merged to main were blamed on a PR that
48+
# never touched them). HEAD^1 is by construction the base the merge
49+
# was built on.
4050
- name: Check bundled extension version bumps
41-
env:
42-
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
4351
run: |
4452
set -euo pipefail
45-
git fetch --no-tags --depth=1 origin "+${PR_BASE_SHA}:refs/checks/pr-base"
46-
python .github/scripts/check_extension_version_bump.py refs/checks/pr-base
53+
if ! git rev-parse --verify --quiet HEAD^2 >/dev/null; then
54+
echo "::error::HEAD is not the pull request merge commit; cannot determine the PR base"
55+
exit 1
56+
fi
57+
python .github/scripts/check_extension_version_bump.py HEAD^1

‎tests/contract/test_extension_version_guard_script.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,34 @@ def test_unbumped_non_ascii_filename_fails(guard_repo):
132132
assert "extensions/demo/extension.yml" in result.stdout
133133

134134

135+
def test_merge_commit_first_parent_ignores_base_branch_drift(guard_repo):
136+
"""The workflow diffs against HEAD^1 of GitHub's pull-request merge commit,
137+
not github.event.pull_request.base.sha. The payload SHA is the base tip
138+
from when the PR was opened and is never refreshed, while the merge ref
139+
is rebuilt against the current base tip; diffing the stale SHA against
140+
the fresh merge commit blames base-branch drift on the PR (seen on
141+
#4395). The merge commit's first parent is the base it was built on."""
142+
repo, stale_base = guard_repo
143+
_git(repo, "checkout", "-q", "-b", "pr")
144+
(repo / "README.md").write_text("pr change\n", encoding="utf-8")
145+
_commit_all(repo, "unrelated PR change")
146+
147+
# Base branch moves on after the PR branched off: an unbumped extension
148+
# change lands there. GitHub then rebuilds refs/pull/N/merge on top of it.
149+
_git(repo, "checkout", "-q", "-")
150+
_write_extension(repo, "demo", "1.0.0", "echo drifted on base")
151+
_commit_all(repo, "unbumped change on base after PR branched")
152+
_git(repo, "merge", "-q", "--no-ff", "--no-edit", "pr")
153+
154+
stale = _run_guard(repo, stale_base)
155+
assert stale.returncode == 1, stale.stdout + stale.stderr
156+
assert "did not increase" in stale.stdout # the trap: drift blamed on the PR
157+
158+
fresh = _run_guard(repo, "HEAD^1")
159+
assert fresh.returncode == 0, fresh.stdout + fresh.stderr
160+
assert "all invariants hold" in fresh.stdout
161+
162+
135163
def test_no_extension_changes_passes(guard_repo):
136164
"""The workflow runs on every pull request (a path-filtered required check
137165
would block PRs that skip it), so a PR touching nothing under extensions/

0 commit comments

Comments
 (0)