I am using GitHub Actions to run certain tasks on the PR branches like version bumping for the application. As part of this, I wanted to trigger the actions to run on all open PRs when a commit is made to the base branch, say main. The config I have in my workflow is
on:
push:
branches: ['main']
pull_request:
branches: ['main']
types: [opened, reopened, synchronize]
This triggers when there is a push event on the main branch but the action runs on the main branch itself. I don't want to bump my versions directly on the main branch. The version bump must be done in the PR before it is merged to the main branch. The reason behind this is my CI/CD pipeline listens to the main branch for changes. If I do a version bump after my PR merge, it will trigger twice.
I had to used if: "(github.event_name == 'pull_request')" on my job to skip the action on the main branch.
Question: How do I trigger the GitHub Actions on all open PRs when there is a change pushed to the base branch?