Action to add a commit to a PR

Hi,

I’m currently trying to achieve the following:

A user creates a PR, that triggers my action. Within this action, changes are made using a custom script. So far so good, since it works as expected until this point.

Now, I want to create a commit and push it into this PR.

What I’ve found is this action: Create or Update Pull Request · Actions · GitHub Marketplace · GitHub

However, I’m either too stupid to use it right, or it doesn’t work as I’ve expected, because it creates a new PR instead of updating the original one.

Are there alternatives to this action, or is there maybe a way to achieve this without an external action?

Just tried to manually commit & push, but that fails:

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

I was able to make it work, using gh:

      - name: Checkout PR
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: gh pr checkout ${{ github.event.pull_request.number }}

      # other stuff

      - name: Push changes
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: git push

Maybe this helps someone.

2 Likes