8 ms·
One extremely painful "gotcha" we encountered was trying to push code to a protected branch from inside a workflow. With the default GITHUB_TOKEN, you can't pu
by m_a_g 5y ago
One extremely painful "gotcha" we encountered was trying to push code to a protected branch from inside a workflow.
With the default GITHUB_TOKEN, you can't push to protected branches. If you decide to use personal access tokens, you can push to protected branches, BUT that will trigger other workflows. That can cause an infinite loop of workflows.
We still couldn't figure out how to push code to a protected branch without triggering the same/other workflows.
- simonw 5y agoOne trick that might work is to include a token such as 'DO_NOT_TRIGGER_ACTIONS' in your automated commit message, then have your other action skip any commits that include that token using this in the workflow: if: "!contains(github.event.head_commit.message, 'DO_NOT_TRIGGER_ACTIONS')"
- m_a_g 5y agogood idea, thanks!
- chad_oliver 5y ago> We still couldn't figure out how to push code to a protected branch without triggering the same/other workflows. If you include `[skip ci]` anywhere in the commit message, that commit won't trigger any github actions. This is a built-in behavior; you don't have to manually check for that string in any downstream actions. I spent a long time trying to work around the same constraint before my colleague pointed out that `[skip ci]` was a thing.
- dcherman 5y agoYou can also use a deploy key. That's how I do it while avoiding adding a PAT to a shared repo