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 ifciworkflow 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 thereleaseworkflow as last step ofciworkflow which will satisfy your needs of runningreleaseworkflow only when ci is successful.If you prefer
Repository Dispatch, you can dispatch the event at the last step ofciworkflow. In this approach you can pass additional inputs toreleaseworkflow so that you can have additional flexibility inreleaseworkflow.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
ciworkflow and then use that event inreleaseworkflow.