英文:
GitHub Actions workflow path filter not working
问题
我正在测试一些GitHub Actions功能,用于运行仅在名为file-name.md
的文件没有更改时才针对main
分支运行的工作流。然而,尽管该文件发生了变化,但工作流仍然被触发。我该如何确保在提到的文件发生更改时不会触发此工作流?
这是我的工作流外观:
name: 'Try path filter'
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '**'
- '!**/file-name.md'
英文:
I'm testing some GitHub Actions functionality for a workflow that I want to run for the main
branch only when there is NO change in a file named file-name.md
. However, the workflow keeps getting triggered even though there is a change in that file. How can I make sure that this workflow won't get triggered when there is a change in the mentioned file?
Here is how my workflow looks:
name: 'Try path filter'
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '**'
- '!**/file-name.md'
Note: One thing I realized is that GitHub actions consider branches
and tags
filter combinations separately (OR fashion) rather than together (AND) fashion. The documentation states that you want to use both branches
and paths
filters when you want to only run the workflow when both filters are satisfied.
答案1
得分: 1
There is also a paths-ignore
subtype that allows to achieve the same result:
on:
push:
paths-ignore:
- 'file-name.md'
Is the same thing as:
on:
push:
paths:
- '**'
- '!file-name.md'
Note that if other files are updated together with this one, the workflow will be triggered.
> When all the path names match patterns in paths-ignore, the workflow will not run. If any path names do not match patterns in paths-ignore, even if some path names match the patterns, the workflow will run.
If you want to avoid this behavior, you would need to use a custom solution, for example by using a paths filter action. Here are some other threads about this alternative: thread 1, thread 2.
英文:
There is also a paths-ignore
subtype that allows to achieve the same result:
on:
push:
paths-ignore:
- 'file-name.md'
Is the same thing as:
on:
push:
paths:
- '**'
- '!file-name.md'
Note that if other files are updated together with this one, the workflow will be triggered.
> When all the path names match patterns in paths-ignore, the workflow will not run. If any path names do not match patterns in paths-ignore, even if some path names match the patterns, the workflow will run.
If you want to avoid this behavior, you would need to use a custom solution, for example by using a paths filter action. Here are some other threads about this alternative: thread 1, thread 2.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论