Github操作:如果在特定文件夹中发生更改,则在工作流中运行步骤/作业



我们有什么方法可以根据特定文件夹中的更改来控制在工作流中运行哪些作业/步骤吗

例如:

我已经说过,在我的git repo中有以下文件夹:a,b,c每次PR合并到我的分支机构时,我都会触发一个工作流。工作流将执行作业,例如,A->B->C.只有当文件夹"a/**""b/**"等出现更改时,我才想运行作业A。

因此,如果PR中的更改仅发生在"a/**""b/**"中,则工作流将跳过C的作业执行,使工作流运行为A->B

您可以在作业或步骤级别使用具有if条件的路径筛选自定义操作,使用setup作业作为初步作业来检查您的特定路径是否已更新,并将结果保存为输出。

下面是一个例子

name: Paths Filter Example
on: [push, workflow_dispatch]
jobs:
paths-filter:
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.filter.outputs.workflows }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
workflows:
- '.github/workflows/**'
# run only if 'workflows' files were changed
- name: workflow tests
if: steps.filter.outputs.workflows == 'true'
run: echo "Workflow file"
# run only if not 'workflows' files were changed
- name: not workflow tests
if: steps.filter.outputs.workflows != 'true'
run: echo "NOT workflow file"
next-job:
runs-on: ubuntu-latest
# Wait from the paths-filter to be completed before starting next-job
needs: paths-filter
if: needs.paths-filter.outputs.output1 == 'true'
steps:
...

这样,你的工作中就可以有这样的东西:A->CCD_ 11或CCD_;CCD_ 13,具体取决于已更新的路径。

是:https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#registry_package

这是语法:

on:
push:
paths:
- 'a/**'
- 'b/**'

最新更新