Search code examples
continuous-integrationglobgithub-actions

GitHub Actions run on push to all branches


It's easy to run a GitHub Action on any push or pull request:

# Triggers the workflow on push or pull request events
on: [push, pull_request]

But what if I want to restrict runs to pull requests opened against specific base refs, while allowing runs on all branches?

I thought about this:

on:
  push:
    branches:
      - "*"
  pull_request:
    branches:
      - "develop"
      - "staging"

But it didn't work. I added this Action to a feature branch and GitHub didn't pick it up.

Is there anything wrong with my glob? Why doesn't '*' work?


Solution

  • I found the Filter pattern cheat sheet after posting the question:

    '*': Matches all branch and tag names that don't contain a slash (/). The * character is a special character in YAML. When you start a pattern > with *, you must use quotes.

    '**': Matches all branch and tag names. This is the default behavior when you don't use a branches or tags filter.

    It happened that the branch I was testing contained a slash (/), so one asterisk (*) wasn't enough. I switched to two asterisks (**) and it works now.