When I create a new release on Github via its UI, I want to trigger the release.yml workflow.
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. If the ci.yml worflow fails, remove the newly created release on the Github UI as well.
I have 2 YAML files ci.yml and release.yml
In my release.yml file
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.
For example, in
release.yaml
, you can add something like this to run a step only ifci
workflow has successfully completed:There are few other ways to trigger a workflow from another workflow. Some are here:
Using Workflow Dispatch
Repository Dispatch
In your case, if you prefer to use
Workflow Dispatch
, you can simply invoke therelease
workflow as last step ofci
workflow which will satisfy your needs of runningrelease
workflow only when ci is successful.If you prefer
Repository Dispatch
, you can dispatch the event at the last step ofci
workflow. In this approach you can pass additional inputs torelease
workflow so that you can have additional flexibility inrelease
workflow.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 inrelease
workflow.