question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checking out a merge commit in `pull_request_target` workflows

See original GitHub issue

I am coming from https://github.com/dependabot/dependabot-core/issues/3253, where there is a lot of confusion of how to safely run actions with secrets when untrusted code from external PRs comes into play.

The bottom line is that there may be situations where you – after you understood the risks – might want to use the pull_request_target event because it has access to secrets; but combine that with a checkout of the PR.

One suggested way of doing this is with

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

which will check out the PR head commit.

This is, however, not 100% what you’d get for a simple uses: actions/checkout@v2 on a pull_request event, because that would check out a merge commit.

I wonder whether it would be possible for this action here to also support checking out such a merge commit on pull_request_target events?

I don’t know if creating such a merge commit involves advanced Git trickery to get-it-right™️ , so I thought this was the best place to ask.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:7

github_iconTop GitHub Comments

7reactions
trim21commented, Jul 31, 2021
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: "refs/pull/${{ github.event.number }}/merge"

this should work as you expected I think.

1reaction
geekflyercommented, Jun 8, 2022

Yes, but github.event.pull_request.head.sha is not what we want in this situation. We want to know that the repo will look like after the pr is merged.

yeah, I mean there is probably other ways to achieve the merge and test against the merged state. But using refs/pull/${{ github.event.number }}/merge" alone is not exactly the safest way since it references a ref that can be updated by the outside contributor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: On the pull request diff, "merged" commits are dis...
In order to see the changes to the target branch reflected in the diff, you can sync the target branch to your source...
Read more >
GitHub pull request showing commits that are already in target ...
Solution 2: Create a new pull request. Suppose that you want to merge intro master from feature-01 : git checkout feature-01 git checkout...
Read more >
Merge request pipelines - GitLab Docs
Create a new merge request from a source branch with one or more commits. Push a new commit to the source branch for...
Read more >
Pull Requests with GitKraken Client
A pull request (sometimes called merge requests), is a review request. You are asking someone to check the changes on a branch before...
Read more >
Effective pull requests and other good practices for teams ...
Alternatively, you can force a merge commit to keep track of which commits came from the feature branch. (feature/masquerading) $ git checkout ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found