拉取请求触发推送工作流程

时间:2020-05-19 13:30:26

标签: github-actions

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

github/workflows/pr.yml仅用于构建和测试

name: Pull request workflow

on: pull_request

github/workflows/push.yml进行构建,测试和部署

name: Push workflow

on: push

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

是否无法分开这些?或者我在这里想念什么?

3 个答案:

答案 0 :(得分:3)

如果仅部署某些分支,请按照以下方式限制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

答案 1 :(得分:0)

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

示例代码:

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

我希望这会有所帮助。

答案 2 :(得分:0)

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

    # 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' }}

参考: