GitHub Actions trigger another workflow


Problem

Do you need a workflow to trigger another GitHub Actions workflow?

This may be necessary if there’s an action that creates a pull request (PR) but the branch is protected by a required status check:

# .github/workflows/create-pr.yml
name: Create PR
on:
  push:
    branches:
      - develop
jobs:
  create-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Create PR
        run: gh pr create --base master --fill
        continue-on-error: true
        env:
          GITHUB_TOKEN: ${{ github.token }}

Solution

If you want an action to trigger another action, then you must use a Personal Access Token (PAT) instead of the default secrets.GITHUB_TOKEN or github.token:

 # .github/workflows/create-pr.yml
 name: Create PR
 on:
   push:
     branches:
       - develop
 jobs:
   create-pr:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout
         uses: actions/checkout@v3
         with:
           fetch-depth: 0
       - name: Create PR
         run: gh pr create --base master --fill
         continue-on-error: true
         env:
-          GITHUB_TOKEN: ${{ github.token }}
+          GITHUB_TOKEN: ${{ secrets.PAT }}

Now the PR will be opened by a user rather than a bot.

See this discussion for more information.



Please support this site and join our Discord!