Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Actions auto-approve not working on pull request created by GitHub Actions bot

I am using two workflows inside my GitHub repository.

The first workflow gets triggered by every push on dev and bumps up the version inside a new branch bump-version and create a new pull request to dev.


name: bump-version
on: 
  push:
    branches:
      - 'dev'

jobs:
  bumpVersionNumber:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v1
        with:
          node-version: 10
      - run: npm ci

      - name: Bump Version
        run: |
          git config --local user.email "[email protected]"
          git config --local user.name "GitHub Action"
          npm run release

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4
        with:
          commit-message: bump version
          title: Bump version
          body: Bump version to reflect release changes
          branch: bump-version
          base: dev

The second workflow should get triggered by every push and pull request to the newly created branch bump-version:

name: auto-approve
on: 
  push:
  pull_request:
    branches:
      - 'bump-version'

jobs:
  autoApprove:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v1
        with:
          node-version: 10
      - run: npm ci
         
      - name: Pull request number
        run: |
          echo "Pull Request Number - ${{ github.event.pull_request.number }}"

      - name: Approve pull Request
        if: ${{ github.event.pull_request.number }}
        uses: hmarr/auto-approve-action@v2
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          pull-request-number: ${{ github.event.pull_request.number }}

The problem is that the second workflow auto-approve does not get triggered, when the new pull request is created or there is a push on the branch by the first workflow bump-version.

I would like to know why the second workflow auto-approve gets triggered by push on any branch but not the bump-version branch and why it's not getting triggered when a new pull request is being created from the branch bump-version to dev?

Does it has to do something with the fact that the pull request is being created by GitHub Actions bot?

like image 559
Animesh Sharma Avatar asked Jun 20 '26 15:06

Animesh Sharma


1 Answers

By default, when you use the repository's GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.

If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of the GITHUB_TOKEN to trigger events that require a token.

Here, you would have to use this PAT when calling the peter-evans/create-pull-request action:

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4
        with:
          commit-message: bump version
          title: Bump version
          body: Bump version to reflect release changes
          branch: bump-version
          base: dev
          token: ${{ secrets.PAT }}
like image 123
GuiFalourd Avatar answered Jun 23 '26 19:06

GuiFalourd