简体   繁体   English

在运行另一个工作流之前触发 github 工作流:发布 [已创建]

[英]Trigger a github workflow before running another workflow on : release [created]

When I create a new release on Github via its UI, I want to trigger the release.yml workflow.当我通过其 UI 在 Github 上创建新版本时,我想触发 release.yml 工作流。

Within the release.yml workflow, I'd like to first run the ci.yml workflow and only if it passes, go ahead and create a release.在 release.yml 工作流程中,我想首先运行 ci.yml 工作流程,并且只有当它通过时,go 才会提前并创建一个发布。 If the ci.yml worflow fails, remove the newly created release on the Github UI as well.如果 ci.yml 工作流失败,请同时删除 Github UI 上新创建的版本。

I have 2 YAML files ci.yml and release.yml我有 2 个 YAML 文件 ci.yml 和 release.yml

In my release.yml file在我的 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:
    .........

If there is a better way to do achieve this, please let me know.如果有更好的方法来实现这一点,请告诉我。

You can make use of workflow_run event with a condition.您可以使用带条件的workflow_run事件。

For example, in release.yaml , you can add something like this to run a step only if ci workflow has successfully completed:例如,在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'

There are few other ways to trigger a workflow from another workflow.几乎没有其他方法可以从另一个工作流触发一个工作流。 Some are here:有些在这里:

  1. Using Workflow Dispatch使用工作流调度

  2. Repository Dispatch 存储库调度

In your case, if you prefer to use Workflow Dispatch , you can simply invoke the release workflow as last step of ci workflow which will satisfy your needs of running release workflow only when ci is successful.在您的情况下,如果您更喜欢使用Workflow Dispatch ,您可以简单地调用release工作流程作为ci工作流程的最后一步,这将满足您仅在 ci 成功时运行release工作流程的需求。

If you prefer Repository Dispatch , you can dispatch the event at the last step of ci workflow.如果您更喜欢Repository Dispatch ,您可以在ci工作流程的最后一步分派事件。 In this approach you can pass additional inputs to release workflow so that you can have additional flexibility in release workflow.在这种方法中,您可以将额外的输入传递给release工作流程,以便您可以在release工作流程中获得额外的灵活性。

There are many other way to trigger a workflow which are well documented here .还有许多其他方法可以触发工作流,这些都在此处详细记录。 Few of the ways you can consider are: creating a tag in your ci workflow and then use that event in release workflow.您可以考虑的几种方法是:在ci工作流程中创建标签,然后在release工作流程中使用该事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM