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

Cannot use parent specifiers in the ref #61

Closed
mathstuf opened this issue Oct 29, 2019 · 17 comments · Fixed by #112
Closed

Cannot use parent specifiers in the ref #61

mathstuf opened this issue Oct 29, 2019 · 17 comments · Fixed by #112
Assignees
Labels
enhancement New feature or request

Comments

@mathstuf
Copy link

I'd like to run an action on a pull_request and check out the actual content of the PR, not a merge with master (because I want it to run even if there is a merge conflict among other reasons). Support for specifying this has been requested on the community forum.

I've tried the following:

with:
  ref: ${{ github.ref }}^2

Which causes a failure because it tries to do:

 git fetch --tags --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/pull/3/merge^2:refs/remotes/pull/3/merge^2

which is an invalid refspec.

Doing this seems to just get completely ignored:

with:
  ref: ${{ github.sha }}^2

I haven't found a way to use $GITHUB_SHA yet either (it seems to be used literally when in a with block).

@ericsciple
Copy link
Contributor

@mathstuf consider adding a run step after checkout, and git reset --hard HEAD^2

@mathstuf
Copy link
Author

But is that going to mean that GITHUB_SHA is wrong?

@ericsciple
Copy link
Contributor

Yes. GITHUB_SHA is not set by the checkout action. It is from the server event payload.

@mathstuf
Copy link
Author

And while that may be a workaround, not being able to specify a valid Git refname in such a way (and that gets silently ignored) seems like a bug in any case.

@mathstuf
Copy link
Author

Also of note is that manual checkout misses all of the submodule sync/update, depth options, etc. available through the action.

@ericsciple
Copy link
Contributor

from the pr event payload, i think ${{ github.event.after }} is the SHA you want

@peter-evans
Copy link
Contributor

peter-evans commented Nov 1, 2019

I think this will checkout the merging branch instead of the merge commit.

      - uses: actions/checkout@master
        with:
          ref: ${{ github.head_ref }}

Edit: I misunderstood. I think this only works for non-fork PRs.

@ericsciple
Copy link
Contributor

@peter-evans instead of refs/pull/merge/<number> iirc refs/pull/<number> contains the commit (for forks and non forks). i may be wrong?

@peter-evans
Copy link
Contributor

@ericsciple I tested the following but it didn't work and gave the error ##[error]fatal: couldn't find remote ref refs/pull/281

on: pull_request
jobs:
  pullRequest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
        with:
          ref: refs/pull/${{ github.event.number }}

What does seem to work for me is the following. But to make this work for forks as well you need to use a repo scoped PAT. Additionally, specifying the path is necessary to keep fork and non-fork checkouts at the same path for the rest of your workflow.

      - uses: actions/checkout@v1
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          ref: ${{ github.event.pull_request.head.ref }}
          path: ${{ github.event.repository.name }}

@ericsciple
Copy link
Contributor

i'll play with this a bit, i think there's a different way

@ericsciple ericsciple self-assigned this Nov 23, 2019
@ericsciple
Copy link
Contributor

ericsciple commented Dec 2, 2019

@peter-evans sorry its refs/remotes/pull/###/head or pull/###/head

i played around with this locally by fetching everything under pull:

git fetch origin '+refs/pull/*:refs/remotes/pull/*'
git branch --list --remote
git log refs/remotes/pull/70/head

@ericsciple
Copy link
Contributor

@mathstuf it sounds like the following solution will work:

on: pull_request
jobs:
  pullRequest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
        with:
          ref: refs/pull/${{ github.event.number }}/head

@mathstuf
Copy link
Author

mathstuf commented Dec 3, 2019

Thanks, I'll try that out when I get a chance. However, I feel like that shouldn't be necessary and that ^2 should still work (really, anything git rev-parse accepts that resolves to a commit).

@ericsciple
Copy link
Contributor

I'll update the README with the scenario: checkout the head commit of a PR, rather than the merge commit.

Leaving this issue open and i'll mark it as enhancement.

Also interested in other scenarios.

@mrrobot47
Copy link
Contributor

mrrobot47 commented Dec 10, 2019

@ericsciple first of all, thanks a lot for your replies on this thread. It helped me a lot to configure my action.

In the README update you have used github.event.after which works for PR synchronize but fails when PR is created and does a checkout of the merge commit.

To handle the checkout of head commit during PR creation as well as synchronize either:

  1. refs/pull/${{ github.event.number }}/head (as you rightly suggested in prev. comment)
    or
  2. github.event.pull_request.head.sha

can be used. I have created a PR with the second option to update the README as that felt better to read and explained exactly as the title read.

@ericsciple
Copy link
Contributor

@mrrobot47 thanks. also note, the first option is a race condition because the PR can be updated before the job starts (ref update)

@mathstuf
Copy link
Author

FWIW, the way GitLab-CI seems to get around that is that CI jobs pull a refs/pipelines/${{ pipeline_id }} ref instead.

thorn0 added a commit to fisker/prettier that referenced this issue Aug 27, 2020
thorn0 pushed a commit to prettier/prettier that referenced this issue Aug 27, 2020
Test

commit_message

with ref

Update code-style.yml

Experimenting

see actions/checkout#61 (comment)

Experimenting 2

Experimenting 3

Try `pull_request_target`

Fix code style

Revert "Fix code style"

This reverts commit 2ecc65b.

Remove other tasks
thorn0 pushed a commit to prettier/prettier that referenced this issue Aug 27, 2020
Test

commit_message

with ref

Update code-style.yml

Experimenting

see actions/checkout#61 (comment)

Experimenting 2

Experimenting 3

Try `pull_request_target`

Fix code style

Revert "Fix code style"

This reverts commit 2ecc65b.

Remove other tasks
borgmanJeremy pushed a commit to flameshot-org/flameshot that referenced this issue Oct 10, 2020
borgmanJeremy pushed a commit to flameshot-org/flameshot that referenced this issue Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants