[英]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.