Learning center

Which commit did the pull request's tests run on?

For a GitHub Actions workflow on the pull_request event, the default is a merge commit, and that commit is on neither branch. Give the next engineer the head, the base and the merge commit, or they may try to reproduce a failure on code that CI never ran.

Three commits#

GitHub's documentation says that for pull_request, GITHUB_REF is refs/pull/PULL_REQUEST_NUMBER/merge and GITHUB_SHA is the merge commit on that branch. Events that trigger workflows

CommitHolds
HeadThe author's branch
BaseThe target branch at the moment the merge was computed
MergeBoth, combined by GitHub

Head can pass locally while merge fails in CI, and both results are right. A typical cause is a function that changed on the base after the author branched.

Record them in the job#

- run: |
    git log -1 --format='tested %H parents %P'
    echo "head ${{ github.event.pull_request.head.sha }}"
    echo "base ${{ github.event.pull_request.base.sha }}"

With the default checkout, the first line shows a commit with two parents. The parents are what was merged. Prefer them to the event's base.sha, which describes the pull request when the event fired and can trail the base that was merged in. If the checkout depth hides the parents, git cat-file -p HEAD still prints their IDs.

A workflow can check out the head instead, with ref: ${{ github.event.pull_request.head.sha }}. Then the line shows the head, and CI no longer tests the combination. Read the output and not the assumption.

Reproduce the one that failed#

From the two parents, where P1 is the base and P2 the head:

git fetch origin P1 P2
git switch --detach P1
git merge --no-ff --no-commit P2
git write-tree

Compare the tree with git rev-parse MERGE^{tree} if you can still fetch the merge commit. Equal trees mean that you have the same tracked files, whatever the commit IDs.

Do not fetch refs/pull/NUMBER/merge a day later and assume it is the tested commit. The ref moves when either side moves.

Decide#

Head aloneMergeThe next step belongs to
PassesFailsWhoever knows both changes. Bisecting the base's new commits narrows it
FailsFailsThe author
FailsPassesThe author still. The base may already fix it, so update the branch and confirm
PassesPasses locally, failed in CIThe environment or an intermittent failure. Compare inputs before rerunning

Worked example#

This example is fictional. Ben cannot reproduce a red check on Ana's branch. The log's first line shows parents c41… and 9be…. The second is Ana's head, and the first is a base commit from that morning. Merging the two locally fails at once, with an argument missing in a call that Ana's branch added. The base commit had added a required parameter. The fix is one argument, and nobody reran the job to find it.

QA has the same question about squash merges. Return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading