Rob
Rob

Reputation: 1183

GitHub action branch creation for code review pull request

I'm trying to create a GitHub workflow that will run ONLY when a new branch is created with a pattern. The purpose of this is to create a Code Review Pull Request when a new branch is pushed to origin, but only on the first time the branch is created, so using a push event will not work and why I'm looking at create.

All of these combinations fail where any new branch created will run, instead of those just matching the pattern

name: "Create Code Review PR"

on: 
  create:
    branches: ['feature/**']      

or

name: "Create Code Reivew PR"

on:
  create:
    branches:
      - 'feature/**'
      - 'support/**'
      - 'hotfix/**'

In both of these scenarios, if push a new branch called no-code-review, the above workflow will still run, but my expected behavior is that it wont run, but it should when a new branch such as these: feature/new-branch, support/new-support-branch or hotfix/fix-this ONLY.

Upvotes: 1

Views: 2072

Answers (1)

soltex
soltex

Reputation: 3551

The create event does not support a branch filter.

The alternative would be using an if condition on your step or job:

if: ${{ contains(github.ref, 'refs/heads/releases/') }}

Here's more information: https://github.community/t/trigger-job-on-branch-created/16878/5

Upvotes: 3

Related Questions