Push to protected branch from GitHub actions
Last updated
Last updated
It turns out that you really can't just git push
from your GitHub actions or required checks before merging. Sorta makes sense, but still a PITA.
The solution that worked for me was to . Since the awesome GitHub CLI named GH_TOKEN
(since depending on the command you use, you might need a different one than GITHUB_TOKEN
), I decided to (ab)use the same:
An that uses this to generate a full changelog and push it to main on releases looks like this:
Important parts:
I default the GH_TOKEN
envvar to a same-name secret, if present
If it's not present, I default it to GITHUB_TOKEN
Checkout always uses GH_TOKEN
, which now may be a higher-permissions PAT than the default
I do the defaulting since the push will succeed if the repository doesn't use branch protection for main
and in that case I don't want to always force the presence of a GH_TOKEN
secret.