Skip to content

Checkout fails on pull request closed event #136

Closed

Description

@jwnx

Hello everyone,

So, I have a .github/workflow/docker.yml like this:

name: Maybe update Docker image

on:
  pull_request:
    types: [closed]

jobs:
  maybe_update:
    runs-on: ubuntu-latest

    if: github.event.pull_request.merged == true

    steps:
    - name: Checkout
      uses: actions/checkout@v2

Which is pretty basic. The goal is to run this on master after a pull request is merged. It does find the lastest commit on master (be3c9f9), as seen here:

/usr/bin/git config --local gc.auto 0
/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader
/usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic ***
/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin be3c9f9d09e54097321f92f452923a91435b63ac

But when it comes to checking out, it cant:

From https://github.com/...
 * branch            be3c9f9d09e54097321f92f452923a91435b63ac -> FETCH_HEAD
/usr/bin/git branch --list --remote origin/master
/usr/bin/git tag --list master
Removed matchers: 'checkout-git'
##[error]A branch or tag with the name 'master' could not be found
##[error]Node run failed with exit code 1

We also tried tying it explicitly to master, like this:

name: Maybe update Docker image

on:
  pull_request:
    branches: [master]
    types: [closed]    

But the same problem occurs. Any ideas? (:

cheers

Activity

  1. jwnx commented on Jan 11, 2020

    @jwnx
    Author

    I was able to solve this by using:

    - uses: actions/checkout@v2
      with:
        ref: master
    

    Now, I thought ref: master was the default behaviour. The fact that I had to explicitly use ref: master makes me think this is a bug. I will wait til someone confirms in order to close this.

  2. changed the title [-]checkout@v2: A branch or tag with the name 'master' could not be found[/-] [+]Checkout fails on pull request closed event[/+] on Jan 13, 2020
  3. ericsciple commented on Jan 13, 2020

    @ericsciple
    Contributor

    Updated title

  4. self-assigned this
    on Jan 13, 2020
  5. added
    bug
    on Jan 13, 2020
  6. added a commit that references this issue on Jan 17, 2020
  7. GMNGeoffrey commented on Jan 17, 2020

    @GMNGeoffrey

    Master is only the default if it's checking out another repository, I think. Otherwise it defaults to whatever triggered the event.

    From the README:

    # The branch, tag or SHA to checkout. When checking out the repository that
    # triggered a workflow, this defaults to the reference or SHA for that event.
    # Otherwise, defaults to `master`.

    But the readme also gives this as the recipe for checking out a closed pull request, which seems wrong:

    on:
      pull_request:
        branches: [master]
        types: [opened, synchronize, closed]
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2

    @jwnx, I think your workaround is going to run into race conditions if there's another push to master in the meantime. We just run things on push to master, which I think should achieve the same result? Unless you don't want to run if someone pushes straight to master and only for merged pull requests for some reason?

    on:
      push:
        branches: [master]
    

    I am experiencing the same error in a slightly different context though (apologies if this should be in a different issue). Our automation force pushes to a PR branch before merging and this triggers another run of the workflow, which fails with that same error message because the PR is already closed (e.g. https://github.com/google/iree/runs/395655503). Could the handling for closed pull requests be better overall?

    Is there a way to get the action to always check out a valid commit, or abort if the PR has already been closed? (We run the relevant things on pushes to master anyway).

  8. haya14busa commented on Jan 19, 2020

    @haya14busa

    +1. I think a correct workaround is to use github.ref.
    I hope it will be solved by default though.

    on:
      pull_request:
        types: [closed]
    jobs:
      release:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
            with:
              ref: ${{ github.ref }}
  9. GMNGeoffrey commented on Jan 22, 2020

    @GMNGeoffrey

    Thanks for fixing. The spurious status failures have gone away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions