GitHub Actions workflow path filter not working.

huangapple go评论54阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月7日 11:29:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定