Is there a way to combine push criteria in GitHub actions using the logical AND?

Viewed 1203

In the GitHub actions 'Events that trigger workflows' documentation there are multiple ways listed, like on specific branches and specific path changes. Is there a way to combine those two using an AND?

As far as I understand the following syntax would trigger the run if the push is either to the master branch OR to the specific path. Is it possible to say that both criteria must be fulfilled to trigger the action?

on:
  push:
    branches:
    - master
    paths:
    - 'app/*'

Note: I am not looking for a hacky solution like letting it trigger on the path and then checking in the step if the branch is the master branch. I know that this is possible, but you would need to do it for each step and it isn't elegant at all.

2 Answers

Your specific request does not appear to be supported by the syntax.

I read through the workflow syntax for GitHub Actions documentation and the two trigger configurations appear unrelated.

Closest workaround I've found is something like this

name: only on master but when the POM changes

on:
  push:
    paths:
      - 'pom.xml'

jobs:
  build_pom:
    if: ${{ github.ref == 'refs/heads/master' }}
    runs-on: ubuntu-latest
    steps:
    [...]
Related