Dependencies Between Workflows on Github Actions
Now it's possible to have dependencies between workflows on Github Actions using workflow_run.
Using this config, the Release
workflow will work when the Run Tests
workflow is completed.
name: Release
on:
workflow_run:
workflows: ["Run Tests"]
branches: [main]
types:
- completed
You can (also) do it by combining workflow_run and if.
Using the below config, the deploy
workflow will start only when all of these conditions are true:
- after the
test
workflow is completed, - if the
test
workflow was successful, Tere was a tag pushed to the default branch,
Assuming that the default branch is main
:
name: deploy
on:
# the 1st condition
workflow_run:
workflows: ["tests"]
branches: [main]
types:
- completed
jobs:
deploy-packages:
# the 2nd condition
if: ${{ github.event.workflow_run.conclusion == 'success' }}
(...)
....BUT unfortunately the 3rd condition cannot be checked this way as the deploy
workflow is triggered in a context of the HEAD of the default branch, without the knowledge about the tag that may be pointing there.
So doing something like:
if: ${{ github.event.workflow_run.conclusion == 'success' }} && startsWith(github.ref, 'refs/tags/') }}
...will NOT work.
I will update this answer when I find out the workaround for this issue.
It seems that the Wait n Check action is currently the optimal workaround for this missing feature, as it declares in its README:
🎉 It allows to work around a GitHub Actions limitation of non-interdependent workflows (we can only depend on jobs inside a single workflow).
UPDATE: see also my other answer for a partial solution using workflow_run
.