Reputation: 994
I cannot get the Github workflow feature to exclude paths to work properly and could not find a similar problem on stack overflow. The most similar case is Github workflow does not trigger on push for path based filtering but it has not helped me.
I have the workflow for PRs below:
name: Build For PRs
on:
pull_request:
types: [opened, synchronize, ready_for_review]
paths:
- 'src/**'
- '!src/abc/**'
- '!src/def/**'
- '!src/ghi/**'
- '!src/docker-compose*.yml'
- '!**.md'
I want it to run on PR's when any file under "src" changes, except when one of the negative filters is a match.
Even changing a .md file triggers this WF. How can I achieve the logic above?
Upvotes: 9
Views: 14698
Reputation: 19852
The problem is that excluding paths doesn't work as you want by design.
When all the path names match patterns in paths-ignore, the workflow will not run, but if you have at least one file that doesn't fall under negations - workflow will still run.
So there is no way to stop workflow by this feature the way you want to do - to stop workflow when at least 1 file belong to excluded list.
I would recommend filtering changed files and then stopping workflow if you find any files matching your criteria and use https://github.com/tj-actions/changed-files/ instead. With that action you will be able to check if any files are fitting your criteria and then you just stop the workflow. Unfortunately it will start full workflow, create a runner and execute workflow itself.
Upvotes: 8