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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification about "working with any ref" changes #351

Closed
prince-chrismc opened this issue Jan 21, 2022 · 8 comments
Closed

Clarification about "working with any ref" changes #351

prince-chrismc opened this issue Jan 21, 2022 · 8 comments
Assignees
Labels
good first issue Good for newcomers type: docs Documentation changes

Comments

@prince-chrismc
Copy link

馃憢 First off, thank you for this action (it's a huge help)

I was updating my repo to the latest version v8 because I wanted to take advantage of

now work with whatever ref has been checked out, without pulling or switching branches by default.

In my workflow on a pull_request event I simply use the default option with actions/checkout@v2 here

However this fails https://github.com/prince-chrismc/label-merge-conflicts-action/runs/4892752781?check_suite_focus=true#step:8:79 with fatal: You are not currently on a branch.

My use case is very similar to the example https://github.com/EndBug/add-and-commit#automated-linting just a different event 馃

Do you have any suggestion or ideas to help me debug this issue?

Thanks in advance 鉂わ笍

@EndBug
Copy link
Owner

EndBug commented Jan 21, 2022

Hi, thanks for using the action!

By default actions/checkout creates a detached head state when the run is triggered by a pull_request event. If you want to commit to the head branch you would need to checkout the branch the PR is coming from in the head repo.

I would set it up like this:

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

You can find the full docs for payloads of pull_request events here.

If you're planning on running this only on "internal" PRs then you could omit the repository input. If you're planning to use this with PRs coming from other forks, please keep in mind that you might not have write access to that repo. You can try setting up the repo with your PAT, but honestly, I've never tried.

PS: I see that your workflow runs on both pull_request events and other ones: since this "custom checkout" is meant only for PRs, you could try having it run only for pull_request events, while other ones will trigger the usual checkout. If you wish to do so, you can use the step.if property, here's the docs.

Anyway, I think this is something worthy of putting in the FAQ section of the README, since other people might want to use the action in this scenario.

I hope this solves your issue!

@EndBug EndBug added type: docs Documentation changes and removed type: question Further information is requested labels Jan 21, 2022
@EndBug EndBug self-assigned this Jan 21, 2022
@EndBug EndBug added the good first issue Good for newcomers label Jan 21, 2022
@fasanosalvatore
Copy link

I have the same problem, the action fails (https://github.com/fasanosalvatore/FitDiary/runs/4908561536?check_suite_focus=true) on pull_request event even if I set the ref parameter as indicated.

@EndBug
Copy link
Owner

EndBug commented Jan 22, 2022

@fasanosalvatore ref is an input of actions/checkout, not of my action, you have to add it to the first step of your workflow.

@prince-chrismc
Copy link
Author

prince-chrismc commented Jan 23, 2022

By default actions/checkout creates a detached head state when the run is triggered by a pull_request event.

that was what I was missing, Thanks for the pointer.

I already handled forks and dependabot by checking the permissions since that covers my use case better 馃槃

Just adding ref input to actions/checkout failed to push, doing some digging it seems the default token does not have workflow permission so I needed to use a PAT.

My PR is passing now. 馃帀

鈩癸笍 I actually still have part of my CI running v7 with ref and token for actions/checkout and it fails so thanks for this improvement!

@EndBug
Copy link
Owner

EndBug commented Jan 23, 2022

Happy to hear that!
I'll close this issue as soon as I add the FAQ section to the README, let's keep this open in the meanwhile

@EndBug EndBug closed this as completed in 3d8fcf9 Jan 23, 2022
@EndBug
Copy link
Owner

EndBug commented Jan 23, 2022

@all-contributors please add @prince-chrismc for their docs contribution

@allcontributors
Copy link
Contributor

@EndBug

I've put up a pull request to add @prince-chrismc! 馃帀

@EndBug
Copy link
Owner

EndBug commented Jan 23, 2022

This fix has been published in v8.0.1 (also v8 and latest). Thanks again for your contribution 鉂わ笍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type: docs Documentation changes
Projects
None yet
Development

No branches or pull requests

3 participants