Reputation: 31
I have created a workflow that automatically merges branch A into branch B when branch A is pushed and a workflow that runs when branch B is pushed. However, the workflow does not run when branch B is pushed. Is this a GitHub specification? If so, I would like to know if there is documentation or an issue that clearly states this.
name: CI
on:
push:
branches: [ "A" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Merge branch B
run: |
git fetch
git checkout B
git merge A
git push origin B
name: CI-2
on:
push:
branches: [ "B" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Test
run: echo Hello
Upvotes: 3
Views: 1116
Reputation: 23280
According to the official documentation (triggering a workflow from a workflow) , this issue occurs because:
When you use the repository's
GITHUB_TOKEN
to perform tasks, events triggered by theGITHUB_TOKEN
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'sGITHUB_TOKEN
, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.
To make it work:
If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of
GITHUB_TOKEN
to trigger events that require a token. You'll need to create a personal access token and store it as a secret. To minimize your GitHub Actions usage costs, ensure that you don't create recursive or unintended workflow runs. For more information about creating a personal access token, see "Creating a personal access token." For more information about storing a personal access token as a secret, see "Creating and storing encrypted secrets."
If you're not familiar with the GITHUB_TOKEN
concept and want to get more context about its usage, I suggest to check this section from the official documentation.
Upvotes: 8