Github workflow - Conditional builds on all pull requests

I want to run a workflow conditionally on all pull_requests and unconditionally on master. The following accomplishes that on pull_requests against master but how can this be made generic to be pull requests against any branch.
Skipping
branches: - master
under pull_requests didn’t do the trick.

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
    # Run death_etl tests iff there are changes to the yaml file or death_etl/connect_util dir or requirements dir
    paths:
      - 'foo/*'    
1 Like

Thank you for your feedback.
Could you please describe your problem in detail? Also do you have a public repo demonstrating this? We can take a look to see what happened.
By the way, as mentioned in the document: The workflow files must be present in that commit SHA or Git ref to be considered.

Hello,
Thanks for the response. Unfortunately the repo in question is private. But the workflow is roughly as follows

name: foo_tests

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
    # Run iff there are changes in `foo` dir
    paths:
      - 'foo/**'
      - '.github/workflows/foo.yaml'

jobs:
  tests:
.....

This works for all pull_requests against master, as expected. We would like to make it generic so that it works on all pull_requests against any branch.

Hi @maverickz

Do you mean the pull request event does not distinguish any branch? If so, you could remove the branch filter, such as:

name: foo_tests

on:
  push:
    branches:
      - master
  pull_request:
    # Run iff there are changes in `foo` dir
    paths:
      - 'foo/*'
      - '.github/workflows/foo.yaml' 

jobs:
  tests:
.....

Note. The workflow files must be present in source branch

By the way, we should know that the branch filter is only for the target branch, for example:

on:
  # Trigger the workflow on push or pull request,
  # *but only for the master branch*
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

I should have clarified that we have tried the above and it didn’t work(the workflow was triggered unconditionally regardless of the underlying changeset rather changes being confined to the files/dir in specified path and hence the dilemma.

Hi @maverickz

Did you mean that you modified files other than the path filter in your pull request, but workflows were still triggered? If so, we should know that every time we push a new commit to a opening PR, the Actions app will read all the modified files in the PR from the first to last. Once at least one modified file satisfies the path filter to trigger the workflow, the workflow will be triggered.
If I misunderstood you, please create a minimal public example repository or provide some screenshots that shows this issue.