如何在 GitHub Actions 中统一处理 push: 和 pull_request: 的 paths:?

7
我希望对这些共同路径进行因式分解:
on:
  push:
    # Run only on changes on these files
    paths:
      - 'lib/**.nim'
      - 'doc/**.rst'
      - 'doc/nimdoc.css'
      - '.github/workflows/ci_docs.yml'

  pull_request:
    # Run only on changes on these files
    paths:
      - 'lib/**.nim'
      - 'doc/**.rst'
      - '.github/workflows/ci_docs.yml'

在Github上的文档提到了[push, pull_request],但如果有节点路径,则该指令无法正常工作。如何避免代码重复?对于在https://github.community/t/how-to-factor-paths-in-common-for-push-and-pull-request/115967中发表的跨贴致歉。(如果我得到任何答案,我将在另一端更新)
2个回答

1
如果我理解您的问题正确,您正在询问如何列出多个事件的常见路径,例如在pushpull_request上运行文件路径lib/**.nim'、'doc/**.rst'、'.github/workflows/ci_docs.yml',目前还不可能实现。
尊重地说,在两个位置都有列表并不是很重复,并且这样做很可能是GitHub方面的某些实现细节原因。
如果您想要更多阅读材料,请参阅官方文档: https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpaths

0

这里有一个你可能想尝试的例子。@xandermonkey 也在链接的文档中概述了类似的方法。

on:
  push:
  pull_request:
    # Run only on changes on these files
    paths:
      - 'lib/**.nim'
      - 'doc/**.rst'
      - '.github/workflows/ci_docs.yml'

2
你确定这个有效吗?我很确定在我发布这个之前已经尝试过了,但是没有成功。 - timotheecour

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接