[英]In GitHub Actions, how can I trigger on push but only if a PR is active?
Say I have 2 branches, a feature branch and a develop branch.假设我有 2 个分支,一个功能分支和一个开发分支。
There's no SLA on feature branch normally, meaning I can push broken code up to it all day long and no CI build should be triggered.通常功能分支上没有 SLA,这意味着我可以整天将损坏的代码推送到它,并且不应触发 CI 构建。
Then I open a PR into develop.然后我打开一个 PR 到 develop。 I trigger a CI build action on pull_request: created.
我在 pull_request: created 上触发了 CI 构建操作。 Let's say this build fails.
假设此构建失败。 By default I can't merge the PR, which is correct.
默认情况下我不能合并 PR,这是正确的。
Now I want to push edits to feature branch to update the PR.现在我想将编辑推送到功能分支以更新 PR。 I want these pushes to trigger a CI build (because we're now working inside an open PR).
我希望这些推送能够触发 CI 构建(因为我们现在在一个开放的 PR 中工作)。 I don't want to allow the PR to proceed/be merged until these push-CIs pass.
在这些推送 CI 通过之前,我不想让 PR 继续/合并。
How can I do that in GitHub Actions?我如何在 GitHub 操作中做到这一点? I tried
on pull_request: edited
but that didn't work for me.我试过
on pull_request: edited
但这对我不起作用。
I'm looking for the functional equivalent of:我正在寻找功能等价物:
on:
push:
if: inside_open_pr
Use the event pull_request
and don't specify activities or specify the activity synchronize
:使用事件
pull_request
并且不指定活动或指定活动synchronize
:
on:
pull_request:
Note: By default, a workflow only runs when a
pull_request
's activity type isopened
,synchronize
, orreopened
.注意:默认情况下,工作流仅在
pull_request
的活动类型为opened
、synchronize
或reopened
时运行。 To trigger workflows for more activity types, use the types keyword.要触发更多活动类型的工作流,请使用 types 关键字。
if you push a new commit to the HEAD ref of a pull request then this “synchronize” event will be triggered.
如果您将新提交推送到拉取请求的 HEAD 引用,则将触发此“同步”事件。 This is because the system is syncing the pull requests with the latest changes.
这是因为系统正在将拉取请求与最新更改同步。 This will NOT trigger if the base ref is updated.
如果基础 ref 更新,这将不会触发。
If you also need to react to a change of the base branch, then you have to add the activity edited
.如果您还需要对基础分支的更改做出反应,那么您必须添加活动已
edited
。
If pull_request
is not an option, you can try usinghttps://github.com/marketplace/actions/get-current-pull-request如果
pull_request
不是一个选项,您可以尝试使用https://github.com/marketplace/actions/get-current-pull-request
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.