[英]Trigger a github workflow before running another workflow on : release [created]
當我通過其 UI 在 Github 上創建新版本時,我想觸發 release.yml 工作流。
在 release.yml 工作流程中,我想首先運行 ci.yml 工作流程,並且只有當它通過時,go 才會提前並創建一個發布。 如果 ci.yml 工作流失敗,請同時刪除 Github UI 上新創建的版本。
我有 2 個 YAML 文件 ci.yml 和 release.yml
在我的 release.yml 文件中
on:
release:
types: [created]
jobs:
# I want to run the ci.yml workflow here and then run the jobs below if it passes.
# If the ci.yml workflow fails, revert back and remove the created release.
job1:
.........
job2:
.........
如果有更好的方法來實現這一點,請告訴我。
您可以使用帶條件的workflow_run事件。
例如,在release.yaml
中,您可以添加類似這樣的內容以僅在ci
工作流成功完成時運行步驟:
on:
workflow_run:
workflows: [ci]
types: [completed]
jobs:
on-success:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- run: echo 'This is where your release steps can continue'
on-failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo 'you can remove this or do something with it like sending an email about why you are not releasing'
幾乎沒有其他方法可以從另一個工作流觸發一個工作流。 有些在這里:
在您的情況下,如果您更喜歡使用Workflow Dispatch
,您可以簡單地調用release
工作流程作為ci
工作流程的最后一步,這將滿足您僅在 ci 成功時運行release
工作流程的需求。
如果您更喜歡Repository Dispatch
,您可以在ci
工作流程的最后一步分派事件。 在這種方法中,您可以將額外的輸入傳遞給release
工作流程,以便您可以在release
工作流程中獲得額外的靈活性。
還有許多其他方法可以觸發工作流,這些都在此處詳細記錄。 您可以考慮的幾種方法是:在ci
工作流程中創建標簽,然后在release
工作流程中使用該事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.