GitHub Action on Pull Request only for certain branches

I’m using Actions to set up Heroku+Vercel review apps for pull requests. I also use Git Flow, so release candidates and hot fixes are made as pull requests and get deployed to staging. I don’t want my actions related to review apps to run for RCs and hot fixes. I’ve added a couple rules to the workflow YAML configs:

name: Set up review app

on:
  pull_request:
    types: [opened, reopened]
    branches-ignore:
      - 'rc/**'
      - 'hotfix/**'

It does not seem that the branches-ignore key is recognized. I’ve also tried branches: with negated patterns, ex:

branches:
  - '**'
  - '!rc/**'

The docs that refer to the branches and branches-ignore keys always seem to mention them in the context of the push event. Is there any way to get this functionality for pull_request events besides adding a step in the action that checks the branch patterns? That would be confusing as the action would still show up on an RC’s pull request. That would only be acceptable if there was some way to indicate that the action was skipped.

The branch filter for pull_request events works based on the name of the target (“base”) branch, not the branch holding the changes you want to merge in. So those filters you’ve tried will skip the workflow if the PR is trying to merge into an RC or hotfix branch. See documentation on on.<push|pull_request>.<branches|tags>:

For a pull_request event, only branches and tags on the base are evaluated.

1 Like