Github Actions Creating Pull Requests
So I’ve been publishing a few of my little tools via Homebrew and I saw an example of someone automating this process to check these tool repos daily for any released updates which is a great little automation.
Problem was, it kept giving me access errors. It unhelpfully told me I didn’t have permission to create PRs in this repository with an error like:
GitHub Actions is not permitted to create or approve
pull requests. -
https://docs.github.com/rest/pulls/pulls#create-a-pull-request
Which has a fair bit of useful information related to the REST API, but doesn’t exactly address the problem.
Googling around I realized I also needed to have a permissions stanza in the Github Action YAML itself, so I added that:
permissions:
contents: write
pull-requests: write Which I was just sure was going to solve it for me… but of course not. On a lark I decided to see if there was any Settings
in the repo related to this and there are! If you navigate to:
Settings -> Github Actions -> General
you’ll see the following:
You need to enable Read and write permissions AND check the ‘Allow Github Actions to create and approve pull requests’ to
*ACTUALLY give it permissions.
I understand the security reasoning here, I just wish they had a better error message that would have led me here during the first half dozen attempts to do this!