Github actions 'pull_request_review' on a specific target branch

Viewed 1119

We are trying to setup a github action which only triggers on pull_request_review for pull requests targeted to a specific base branch pattern release/*

This is so we have a GH action be able to check if the review is from a specific release gatekeeper group.

Doing something like so, does not seem to work only for PR's targeted to release/* branches. It seems to trigger on PR reviews target to all base branches

on:
  pull_request_review:
    branches:
      - release/*

Seems to us that we cannot chain the base branch like so

2 Answers

You can perform filtering at job level.

Example:

name: Filtering PR Reviews

on:
  pull_request_review:
    branches:
      - 'releases/**'

jobs:
  Releases:
    name: Releases
    runs-on: ubuntu-latest
    if: ${{ startsWith( github.event.pull_request.base.ref, 'releases/' )}}
    steps:
      - name: trigger
        run: echo "we are in releases/**"
    
  ReleasesNext:
    name: ReleasesNext
    runs-on: ubuntu-latest
    if: ${{ startsWith( github.event.pull_request.base.ref, 'releases/next' )}}
    steps:
      - name: trigger
        run: echo "we are in releases/next"    

You can make it work by setting condition as in:

on:
pull_request_review:
    branches:
        - release/**

jobs:
  release-job:
    if: startsWith(github.event.pull_request.base.ref, 'release/')

This basically checks base reference for text (not case sensitive).

If the condition is false the wf will be still displayed among other ones, but will be shown as skipped (0s execution time).

Note that you would need to set this if condition for every job in a workflow.

I don't think you need branch filter anymore.

Related