Search code examples
githubgithub-actions

Only trigger workflow if it is coming from a specific branch


Given the following branches:

  • main
  • feature_1
  • feature_important_1
  • feature_2
  • feature_3
  • feature_important_2
  • feature_4

To trigger pipelines from any branch to branches named *_important_*, we can use:

name: "some_name"
on:
  pull_request:
    branches: 
      - '*_important_*'

But what I want to do is only trigger on branches named *important* that go to main, how can I filter on the branch "source" name on pull request? e.g.

name: "some_name"
on:
  pull_request:
    branches: 
      - 'main'
    source_branches: # THIS PART  IS MADE UP
      - '*_important_*'

Solution

  • This controls whether the workflow starts, but currently only the base branch can be excluded from the PR, and branch to the main cannot.

    This means that based on your limitations, it will start, perhaps it's the pollution you mentioned.

    Of course, it can be skipped through if and context. And please note that it can only be skipped.

    jobs:
      specific-branch:
        if: github.head_ref == 'test'