'How to run GitHub Actions workflow only if the pushed files are in a specific folder
I have a folder structure that looks something like this.
- folder1
- file1
- *other files*
- folder2
- file1
- *other files*
- .gitignore
- package.json
- *other files*
I want to run my GitHub Actions workflow on push, only if any of the changed/pushed files are located in the folder1
directory/folder.
Solution 1:[1]
The normal syntax involves a path filter
on:
push:
paths:
- folder1/**
If that is not enough, you also have the GitHub Action Path Filter.
Solution 2:[2]
Path filters only work at workflow level.
on:
push:
paths:
- 'sub-project/**'
If you want to apply this at job level, look for changed-files
Solution 3:[3]
You will need this if also wanting to filter pull request runs
on:
push:
paths:
- 'folder1/**'
pull_request:
paths:
- 'folder1/**'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Flimtix |
Solution 2 | DᴀʀᴛʜVᴀᴅᴇʀ |
Solution 3 |