Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a GitHub Action step to run only on branches with a particular name prefix?

I am writing a GitHub Action. I want some of my steps to run only on certain branches.

The whole action is set to run only on master and on branches beginning with features/lr.

on:
  push:
    branches: 
      - master
      - features/lr*

I have a "deploy" step that I want to run on master and on branches beginning with features/lrd. (So for example if my branch is named features/lr-foo, then the deployment step should be skipped.)

I know I can do if conditionals like this:

- name: Deploy application
  if: github.ref == 'refs/heads/master'

Can I also check whether github.ref matches a certain prefix or pattern? What is the syntax for that?

Something like this pseudocode:

- name: Deploy application
  if: github.ref == 'refs/heads/master' || github.ref.matches('refs/heads/lrd*')

Thanks in advance!

like image 715
Claus Appel Avatar asked Dec 05 '25 16:12

Claus Appel


1 Answers

The branches, branches-ignore, tags, and tags-ignore keywords accept glob patterns. You can check details in docs - filter pattern.

As for using expressions, docs don't mention matches function, but maybe you could use something like contains, startsWith or endsWith. See here for details.

like image 167
frennky Avatar answered Dec 10 '25 11:12

frennky