Why the checks stay green#
A check run belongs to a commit, the pull request's head. Retargeting leaves the head where it was, so the checks that ran against the old base still describe that head and GitHub keeps showing them.
GitHub's documentation for pull_request says that by default a workflow runs only for the opened, synchronize and reopened activity types. A base change is an edited event, so no workflow runs unless the workflow lists edited. Events that trigger workflows
The pull request page shows the same green whichever base the merge commit had. A branch rule that requires branches to be up to date blocks the merge only while the head is behind the new base. Even then, the checks that remain visible were computed against the old base.
Read which base a check merged#
For a pull_request run with the default checkout, the tested commit is a merge commit and its first parent is the base that was merged. Read it from the run:
gh api repos/OWNER/REPO/actions/runs/RUN_ID \
--jq '.event, .head_sha, .created_at'
head_sha is the pull request's head, not the merge commit. To read the base, print the parents in the job itself:
- run: git log -1 --format='tested %H parents %P'
Then compare the first parent with the new base:
git fetch origin NEW_BASE_BRANCH
git merge-base --is-ancestor FIRST_PARENT origin/NEW_BASE_BRANCH \
&& echo "the tested base is in the new branch" \
|| echo "the tested base is not in the new branch"
If the first parent is not in the new base's history, the run tested a combination that the merge will never produce.
Run again when the base changes#
Add edited to the workflow's types and skip edits that did not change the base. The edited payload carries changes.base only when the base moved. Webhook events and payloads
on:
pull_request:
types: [opened, synchronize, reopened, edited]
jobs:
test:
if: github.event.action != 'edited' || github.event.changes.base != null
A title edit then starts nothing, and a retarget starts a run on a new merge commit. Without this change, a reviewer can push an empty commit or close and reopen the pull request. Both start a run, but neither leaves a reason in the history.
Keep a receipt that tells the bases apart#
A receipt that names only the head cannot distinguish the two runs. Record the base as well:
| Field | Old run | New run |
|---|---|---|
| Run and attempt | 7101 / 1 | 7188 / 1 |
| Head | 4e2a9c1 | 4e2a9c1 |
| Base branch | main | release-2.4 |
| Merged base commit | b07d3f2 | 91c5e08 |
| Tested merge commit | e3310aa | 5af0c7d |
| Result | pass | fail |
Reuse a result only when the head and the merged base match the commit you intend to merge.
Worked example#
This example is fictional. Ana's branch was cut from main after a fix that adds a timeout guard to the payment client. Her change relies on the guard, and the checks pass. The release manager retargets the pull request to release-2.4, which does not have the guard yet. The page still shows green, because the head did not change.
Ben reads the parents line in the old run, b07d3f2 4e2a9c1, and git merge-base --is-ancestor b07d3f2 origin/release-2.4 reports that the commit is not in the release branch. He triggers a run. The merge commit with release-2.4 fails the client test that relies on the guard. The fix is to backport the guard first. The old green check only showed that Ana's change worked with the guard present.
For how a merge commit is built, read which commit the tests ran on. Return to handing over evidence.