【问题标题】:Pull requests trigger push workflow拉取请求触发推送工作流
【发布时间】:2020-05-19 13:30:26
【问题描述】:

在 GitHub 存储库中,我有两个独立的 GitHub Actions 工作流程:

github/workflows/pr.yml 只是构建和测试

name: Pull request workflow

on: pull_request

github/workflows/push.yml 构建、测试和部署

name: Push workflow

on: push

创建拉取请求会触发这两个工作流。

无法将这些分开还是我在这里遗漏了什么?

【问题讨论】:

  • 您的拉取请求是来自 fork 还是来自您自己的存储库?您只希望 Pull request workflow 触发 PR 而不是 Push workflow?
  • @riQQ 我正在使用来自同一个 repo(只是一个单独的分支)的 PR 进行测试,是的
  • 我的回答能解决你的问题吗?

标签: github-actions


【解决方案1】:

如果你只部署某​​些分支,请通过以下方式限制Push workflow

name: Push workflow
on:
  push:
    branches:
    - master

另一种选择是排除分支

on:
  push:
    # Sequence of patterns matched against refs/heads
    branches-ignore:
      # Push events to branches matching refs/heads/mona/octocat
      - 'mona/octocat'
      # Push events to branches matching refs/heads/releases/beta/3-alpha
      - 'releases/**-alpha'

更多示例请参见https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestbranchestags

【讨论】:

  • branches ignore patch-** 或类似的东西可能会更好......
  • 取决于 imo 的分支模型,但在某些情况下可能会更好
【解决方案2】:

您可以在工作中使用这些行来避免内部拉取请求(也触发推送)触发您的工作流程,同时允许外部拉取请求触发您的工作流程。

    # a push event from the origin repo, or a PR from external repo
    if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'your/full_repo_name' }}

但请注意,由于安全设计原因,外部拉取请求只会触发在上游存储库的默认分支中定义的工作流。

参考:

【讨论】:

    【解决方案3】:

    为此,您可能还需要在 PR 中定义触发器的类型。

    示例代码:

    on:
      pull_request:
        types:
          - closed
        branches:
          - master
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 2021-08-25
      • 2016-08-19
      • 2011-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多