checkout: Checking out wrong commit?

I just introduced a failing test into the main branch of a project; the failing tests (introduced in the commit triggering the build) appeared not to have run in the PR build.

When I look at the actions/checkout output, I am surprised by what I see.

Specifically, the build is running on commit 2dca06e – however, actions/checkout appears to be merging the prior commit – c0121d5 – (without the tests) into the project’s main branch.

Is this expected?

Screen Shot 2020-07-10 at 9 55 09 PM

The project’s checkout configuration is completely vanilla: https://github.com/golangci/golangci-lint/blob/master/.github/workflows/pr.yml#L46

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 47
  • Comments: 25 (5 by maintainers)

Commits related to this issue

Most upvoted comments

This looks quite serious (allows to sneak not validated code as valid)

@ericsciple is there any specific timeline for this?

I was able to use the following work-around:

[... trimmed ...]
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          # Check out pull request's HEAD commit instead of the merge commit to
          # work-around an issue where wrong a commit is being checked out.
          # For more details, see:
          # https://github.com/actions/checkout/issues/299.
          ref: ${{ github.event.pull_request.head.sha }}
[... trimmed ...]

I believe this is a dupe of #237, please see my comment here: https://github.com/actions/checkout/issues/237#issuecomment-667158637

@ericsciple which issue should we follow this one (#299) or #237?

This issue [or one very similar] bit me today while using actions/checkout@v4 and got me extremely confused. Looked like some ghost merge commit was sitting on top of mine and making me think I was going nuts.

At first I noticed that HEAD wasn’t the same as the HEAD on my PR

$ git rev-parse --short HEAD
c7e92e65a9

This commit was nowhere to be found on my branch or local repo.

Found it on the public repo here, unattached to anything…: Image

Looking a bit deeper ->

$ git show -s --format=raw HEAD
commit c7e92e65a99c531dbc3a16e6ffff5b58368196e4
tree 62d4ddfd7f526e63ea23be15b3e9537fa7f07f71
parent fcea7e4af940999a4068ef6981e945e0ac3ec36b
parent 46bb1463593dfedf9ef61a075eb3a74ffd5aabf5
author Maxime Beauchemin <maximebeauchemin@gmail.com> 1747261433 +0000
committer GitHub <noreply@github.com> 1747261433 +0000
gpgsig

What is committer GitHub here? Where was that commit coming from?

For the record, I was able to fix the issue by adding:

with:
  ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

Now should I add this to all my GHAs to make sure it doesn’t bite us again?

I had the same problem in the pull-request.

Fix with:

- uses: actions/checkout@v2
  with:
    ref: ${{ github.event.pull_request.head.sha }}

Beware: this checks out the current head of the branch, whereas by default the action checks out the merge commit. By using this workaround, you will no longer catch conflicting changes in the base branch.

Is there a way to check out the correct merge commit without race conditions? There’s the merge_commit_sha field, but the docs indicate that that may be null if mergeability has not yet been computed.

@andymckay I was introducing CI in one branch and it started complaining about code from another, but they were mutex.

I had a couple of branches running at that point so don’t want to send it in and it turns out it was PEBKAC so I don’t waste your time. If it happens again, I’ll be sure to let you know. Thanks.

We just ran into what I think is another instance of this issue in https://github.com/DFHack/scripts/runs/910104637?check_suite_focus=true#step:4:375 This check ran on https://github.com/DFHack/scripts/commit/5177a127b32631fbcedc4b0e93e0c5c05a124388, but ended up running on a merge between master and the previous commit on that branch (https://github.com/DFHack/scripts/commit/1ec3d9b1a14c6b39b1bf0b907108a3e313eed955, as seen in the actions/checkout output), which produced a lot of irrelevant errors that the newer commit was intended to address. This issue repeated itself when we re-ran the check, so it appears to be reproducible in this case, but I’m not seeing an obvious reason why - the newer commit in that PR was pushed well after the checks run on the older commit failed, and we haven’t seen this in other PRs. Update: we’ve seen this in at least two PRs so far.

About 2 minutes after re-running the check reproduced the issue, I ran this locally, which resulted in fetching a correct merge, so I’m pretty sure the issue is on the action’s end:

$ git fetch origin refs/pull/159/merge
$ git show FETCH_HEAD 
commit 5be19d326c828ac38ce307eb6db068e691504a7e
Merge: ad67c79 5177a12