Search code examples
githubgithub-actionslerna

how to define workflow to run based on two push rules


Is there a way to define 2 push rules in same workflow file or work around ?

How to combine and write below rules into single workflow file :

  1. Run when any file is pushed on non master branch
On:
  push:
     branches-ignore:
     - 'master'
     paths:
     - 'path-to-package/**'

  1. Run Only when particular(package.json) file pushed in master branch
On:
  push:
     branches:
     - 'master'
     paths:
     - 'path-to-package/package.json'
       

Solution

  • Your specific request doesn't appear to be supported by the syntax.

    According to the workflow syntax for GitHub Actions documentation, two trigger configurations appear unrelated.

    GitHub allows free users to open support requests. You could always make a feature request at support.github.com/contact

    The closest workaround I know at the moment would be something like the workflow below, using a conditional inside your jobs.

    on:
      push:
        paths:
          - 'path-to-package/package.json'
    
    jobs:
      build_pom:
        runs-on: ubuntu-latest
        steps:
          - run: echo 'this is master'
            if: github.ref == 'refs/heads/master'