Github Actions pull_request when base branch has name "something/*", not target branch

Viewed 347

Trying to get a GitHub action to trigger when the name of the branch that the PR comes from has a specific pattern.

Normally you can do this;

name: My action name
on:
  pull_request:
    branches:
      - 'something/**'

# ... the rest of the action

This will make the action trigger when a pull request tries to merge into a branch named something/any-string-here, however, I want the reverse. I want this action to run when the base branch has this name, regardless of what the target branch is.

Can this be done? Or do I have to add if-statements to all the steps checking the branch name?

1 Answers

The / is a special character when used on paths or branches trigger fields.

In that case, similarly with what can be done in regex, you need to escape it with a \.

Therefore, to achieve what you want, you would need to use:

name: My action name
on:
  pull_request:
    branches:
      - 'something\/**'

# ... the rest of the action

Note: It's similar to this other StackOverflow question


I tested it with this PR which triggered this workflow.

Related