'Github action rebase running twice

I want github action to rebase my branch onto main as soon as a PR is created or updated from feature branch onto main branch. But this rebase workflow ends up running twice. Following is the code:

name: Rebase on main branch

on:
  pull_request:
    branches: [ main ]

jobs:
  rebase:
    name: Rebase on main branch
    runs-on: ubuntu-latest
    steps:
      - name: git checkout
        uses: actions/checkout@v2
        with:
          token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          fetch-depth: 0

      - name: automatic rebase
        uses: cirrus-actions/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

I have another test workflow that runs on successful rebase. Since rebase runs twice, test also runs twice which is not the intended behavior.

  • How do I make rebase run only once?
  • Or is there some trigger that can tell me if PR(create or update) + rebase happened?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source