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

Keeps on failing: fatal: ref HEAD is not a symbolic ref #142

Closed
qdm12 opened this issue Mar 27, 2020 · 8 comments · Fixed by #526
Closed

Keeps on failing: fatal: ref HEAD is not a symbolic ref #142

qdm12 opened this issue Mar 27, 2020 · 8 comments · Fixed by #526

Comments

@qdm12
Copy link

qdm12 commented Mar 27, 2020

I have the following Github workflow

name: Misspells
on: [pull_request,push]
jobs:
  misspell:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/create-pull-request@v2.4.4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos
          branch-suffix: timestamp

But unfortunately it fails with the logs when a pull request is made:

Target repository set to qdm12/pingodown
  stderr: 'fatal: ref HEAD is not a symbolic ref'
##[error]The checked out ref is not a valid base for a pull request. Unable to continue. Exiting.
##[error]The process '/opt/hostedtoolcache/Python/3.8.2/x64/bin/python' failed with exit code 1
/usr/bin/git config --local --add http.https://github.com/.extraheader AUTHORIZATION: basic ***

Full log

Example of PR from typo branch

Any help would be greatly appreciated as I would ideally like to use this action for other workflows as well! 👍

@peter-evans
Copy link
Owner

Hi @qdm12

The issue is that pull_request events checkout a merge commit. If you want to raise a pull request to merge into an existing pull request you need to checkout the head_ref. See the documentation here:
https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#pull-request-events

Also, push should only run on master so that you aren't creating two PRs for pull request branches.

name: Misspells
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  misspell:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout on push
        if: github.event_name == 'push'
        uses: actions/checkout@v2
      - name: Checkout on pull_request
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/create-pull-request@v2.4.4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos
          branch-suffix: timestamp

When using branch-suffix: timestamp, you might end up with a lot of PRs created if your repo has a lot of activity. It can be a bit awkward to use this action well on pull_request events. Personally, I would avoid if possible and just make the solution simpler by running on push to master only. That way you can use the fixed-branch strategy easier.

name: Misspells
on:
  push:
    branches:
      - master
jobs:
  misspell:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/create-pull-request@v2.4.4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos

@peter-evans
Copy link
Owner

peter-evans commented Mar 27, 2020

If you want to perform operations on PRs (like correcting typos, formatting) I recommend using a slash command instead of raising another PR to merge into the PR branch. See slash-command-dispatch, and in particular, the ChatOps in Pull Requests demo.

@qdm12
Copy link
Author

qdm12 commented Mar 28, 2020

Thanks so much for the detailed help!

I'll stick with the PR approach for now (not too much activity yet / not too much spelling mistakes 😆 ), although your other slash command action is quite exciting as well.

Have a great weekend!!

@qdm12 qdm12 closed this as completed Mar 28, 2020
@qdm12
Copy link
Author

qdm12 commented Mar 28, 2020

Hi again,

Actually would you know the checkout step so that it would work for PR from forked repositories? In my case it's this log I obtain, using this workflow file - almost the same as yours I think.

Thank you so much 👍

@peter-evans
Copy link
Owner

Apparently, this will work for both local PRs and PRs from forks. I will update the docs to this snippet instead of the one I mentioned above.

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

@qdm12
Copy link
Author

qdm12 commented Mar 29, 2020

Actually using this format gives the same error as before 😢 (log), workflow was:

name: Misspells
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  misspell:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout on push
        if: github.event_name == 'push'
        uses: actions/checkout@v2
      - name: Checkout on pull_request
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: reviewdog fixer
        uses: reviewdog/action-misspell@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          locale: "US"
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/create-pull-request@v2.4.4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos
          branch-suffix: timestamp

@qdm12 qdm12 reopened this Mar 29, 2020
@peter-evans
Copy link
Owner

Sorry @qdm12. I didn't think about this long enough before I replied with this comment. I've tried a lot of this in the past and essentially gave up. Basically, what you are trying to do is not possible with PRs from forks (or the workaround is so complicated it's undesirable). The PR branch lives in the fork. Most likely you have no access to the fork. So when you think about it, what is this workflow trying to do? You want to create a pull request in the fork to update the PR branch? The only way you could do that is if you have write access to the fork, or, you create a fork of the fork and raise a PR back to update it.

So one option would be to only run on pull_request events when the PR is local and not from a fork. This would still check when the fork PRs are merged to master.

name: Misspells
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  misspell:
+   # Check if the PR is not from a fork
+   if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    steps:
      - name: Checkout on push
        if: github.event_name == 'push'
        uses: actions/checkout@v2
      - name: Checkout on pull_request
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        with:
-         ref: ${{ github.event.pull_request.head.sha }}
+         ref: ${{ github.head_ref }}
      - name: reviewdog fixer
        uses: reviewdog/action-misspell@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          locale: "US"
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/create-pull-request@v2.4.4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos
          branch-suffix: timestamp

As I mentioned previously, if you really want a solution to check/fix both local and fork PRs I suggest to use slash-command-dispatch.

@peter-evans
Copy link
Owner

@qdm12 Hope you managed to find a setup that works well for you. Closing this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants