GitHub Actions "paths" is too wide

Hey there.

I’m trying to make PR auto approve basing on following logic:
   - modified files are in “dir1”: PR auto approve is triggered

   - modified files are in “dir1” and “dir2”: PR auto approve is not triggered

Officially:

… you can configure a workflow to run when … at least one modified file matches the configured “paths” …

So each of following code examples auto-approves PR even if modified files are not only in “dir1”, but in “dir2” as well.

on:
  pull_request:
    paths:
      - 'dir1/**'

on:
  pull_request:
    paths:
      - 'dir1/**'
      - '!dir2/**'

on:
  pull_request:
    paths:
      - '!dir2/**'

How can I restrict “paths” search pattern to trigger PR approving only if “dir1” is the only place with modified files?

5 Likes

Eventually got the list of the changed files in the PR as follwing:

curl --request GET \
          --url https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/files \
          --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'

Then restricted paths trigger by working only with those PRs, which list above consist only of necessary dirs.