If you work with GitHub Actions and have used actions to commit to a branch, you may have run into this little problem I ran into today: automatically generated commits and events triggered by a workflow, do not trigger any workflow.
In practice, that means that if you used a workflow to add a commit to your Pull Request, CI will not be triggered after that commit is pushed. All the events and CI that you would expect to see run on your Pull Request will not be triggered until your next push.
This is done on purpose by GitHub, as per the docs:
When you use the repository’s GITHUB_TOKEN
to perform tasks, events triggered by the GITHUB_TOKEN
, with the exception of workflow_dispatch
and repository_dispatch
, will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. For example, if a workflow run pushes code using the repository’s GITHUB_TOKEN
, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.
Automatic token authentication
A possible work-around in such cases is to use a personal access token instead of the default GITHUB_TOKEN
to trigger events that require a token.
In my situation, I am using actions/github-script
and its authenticated Octokit client. Specifically, I use createOrUpdateFileContents
to add a new file, commit it, and push it to the branch. actions/github-script
allows using the github-token
input to pass your own custom token, so I used that:
uses: actions/github-script@v7 with: github-token: ${{ secrets.API_TOKEN_GITHUB }} script: |
The generated commit now happens in my name, and CI events are triggered as expected by that commit.