Max*_*Max 5 git yaml github github-actions
当我将提交推送到 PR 时,我的测试会为此提交触发。之后,如果我向这个 PR 推送额外的提交,Github Actions 中的测试会在两个提交上运行。
我需要取消之前的运行并仅在最近的推送提交上运行它们。
如何配置我的 yaml 文件来实现这一目标?
Dav*_*uel 146
要在触发新工作流程时从同一 PR、分支或标签取消当前正在运行的工作流程,您可以使用:
name: Workflow X
on: # ...
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs: # ...
Run Code Online (Sandbox Code Playgroud)
解释:
${{ github.workflow }}:工作流名称用于生成并发组(例如Workflow 1)。这允许您在同一事件(例如 PR)上触发多个不同的工作流程(例如workflow1.yaml和)。workflow2.yaml否则,workflow1.yaml将取消workflow2.yaml,反之亦然。${{ github.event.pull_request.number:当触发事件为PR时,会使用PR号生成并发组(例如workflow1-33)。|| github.ref }}:当触发器不是 PR 而是推送时,会使用分支或标签名来生成并发组(例如workflow1-branch1)。cancel-in-progress: true:如果cancel-in-progress被省略或设置为false,当触发新的工作流程时,当前正在运行的工作流程不会被取消,并且新的工作流程将排队等待,直到前一个工作流程完成。参考: https: //docs.github.com/en/actions/using-jobs/using-concurrency
Emm*_*ess 11
您可以使用并发:
并发确保一次只运行一个使用相同并发组的作业或工作流。
concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true
Run Code Online (Sandbox Code Playgroud)
Phi*_*lip 10
您还需要确保在同一存储库中拥有多个工作流程,以便仅取消同一工作流程的正在进行的运行。
使用并发GitHub 文档的片段:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Run Code Online (Sandbox Code Playgroud)
完整的工作示例(来源):
name: CI with in-progress cancellations
on:
pull_request:
branches: [ main ]
workflow_dispatch:
# This is what will cancel the workflow
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Print concurrency group
run: echo '${{ github.workflow }}-${{ github.ref }}'
- name: Sleep 15s
run: sleep 15s
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
315 次 |
| 最近记录: |