Github Action Workflow Dependency
▌Introduction
The jobs in a GitHub
Actions: workflow by default run in parallel at the same time.
To run a job only
when another job has completed, we can use needs keyword as
following,
(The sample
manifest comes from GitHub
Docs: Creating dependent jobs)
However, it needs
some tricks on workflows dependencies, let us see the following example.
▌Implement
▋ Scenario
I am going to create 2 workflows:
1. Publish Docker Image
2. Run Docker Container (to execute some commands)
The second workflow
depends on the result of the first one.
We will run the
container after the Docker image publish successfully. In other words, if publishing
fails, we won’t run the container.
▋
Constraints
1. Currently (2021-11) GitHub Actions only supports putting the
second workflow (that will be triggered by first one) on the “default branch”.
2. To get the previous workflow’s state, use the value of github.event.workflow_run.conclusion.
▋ Workflow: Publish Docker
Image
This is the
first workflow and it is not what we will focus in the article, see [GitHub]
Github Actions - Publish Docker images for more details.
▋publish_docker_image.yml
▋ Workflow: Run Docker Container
The second
workflow will need to watch the if the dependent workflow has been closed by
▋run_docker_constainer.yml
Like we
mentioned in Constraints, we have to enable the workflow (put the manifest
file) in the default branch, e.q. master or main.
Notice that the
above manifest used addnab/docker-run-action
as the “Docker Run Action” Or we can use the default Action like this,
▌Reference
▋Using
Docker Containers In Jobs - GitHub Actions
▋Workflow_run
not working as expected
▋How to use the GitHub
Actions `workflow_run` event?
▋actions/runner:
Secrets cannot be used to condition job runs #520
▋Pass Github secrets to a
docker github action
▋Workflow_run
completed event triggered by failed workflow
Great breakdown of GitHub Actions and workflow dependencies! This will definitely streamline CI/CD processes. Check out Better Joy for more insights on automation!
回覆刪除