Jeremy Herve<p>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.</p><p>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.</p><p>This is done on purpose by GitHub, as per the docs:</p><blockquote><p>When you use the repository’s <code>GITHUB_TOKEN</code> to perform tasks, events triggered by the <code>GITHUB_TOKEN</code>, with the exception of <code>workflow_dispatch</code> and <code>repository_dispatch</code>, 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 <code>GITHUB_TOKEN</code>, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.</p><p><a href="https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication" rel="nofollow noopener noreferrer" target="_blank">Automatic token authentication</a></p></blockquote><p>A possible work-around in such cases is to use a personal access token instead of the default <code>GITHUB_TOKEN</code> to trigger events that require a token.</p><p>In my situation, I am using <code><a href="https://github.com/actions/github-script" rel="nofollow noopener noreferrer" target="_blank">actions/github-script</a></code> and its authenticated Octokit client. Specifically, I use <code>createOrUpdateFileContents</code> to add a new file, commit it, and push it to the branch. <code>actions/github-script</code> allows using the <code>github-token</code> input to pass your own custom token, so I used that:</p><pre><code>uses: actions/github-script@v7 with: github-token: ${{ secrets.API_TOKEN_GITHUB }} script: |</code></pre><p>The generated commit now happens in my name, and CI events are triggered as expected by that commit. </p><p><a rel="nofollow noopener noreferrer" class="hashtag u-tag u-category" href="https://herve.bzh/t/en/" target="_blank">#EN</a> <a rel="nofollow noopener noreferrer" class="hashtag u-tag u-category" href="https://herve.bzh/t/github/" target="_blank">#GitHub</a> <a rel="nofollow noopener noreferrer" class="hashtag u-tag u-category" href="https://herve.bzh/t/github-actions/" target="_blank">#GitHubActions</a></p>