Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout fails on pull request closed event #136

Closed
jwnx opened this issue Jan 11, 2020 · 5 comments · Fixed by #141
Closed

Checkout fails on pull request closed event #136

jwnx opened this issue Jan 11, 2020 · 5 comments · Fixed by #141
Assignees
Labels
bug Something isn't working

Comments

@jwnx
Copy link

jwnx commented Jan 11, 2020

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

@jwnx
Copy link
Author

jwnx commented Jan 11, 2020

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.

@ericsciple ericsciple changed the title checkout@v2: A branch or tag with the name 'master' could not be found Checkout fails on pull request closed event Jan 13, 2020
@ericsciple
Copy link
Contributor

Updated title

@ericsciple ericsciple self-assigned this Jan 13, 2020
@ericsciple ericsciple added the bug Something isn't working label Jan 13, 2020
lee-dohm added a commit to lee-dohm/atom-style-tweaks that referenced this issue Jan 17, 2020
@GMNGeoffrey
Copy link

GMNGeoffrey commented Jan 17, 2020

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).

@haya14busa
Copy link

+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 }}

@GMNGeoffrey
Copy link

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
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants