A workflow in a GitHub Actions can be optimized by splitting it into several jobs, which run in parallel by default.
Parallel jobs is a great way to improve build times and provide a faster feedback to your development & QA teams.
This note shows how to run jobs in parallel in the Github Actions.
Parallel Jobs in GitHub Actions
This is an example of a common sequential workflow:
name: Sequential App Build Workflow on: [push] jobs: sequential-build: runs-on: self-hosted steps: - run: | echo "Build Application" # [...] - run: | echo "Integration Testing" # [...] - run: | echo "Functional Testing" # [...] - run: | echo "Deploy Application" # [...]
In the GitHub Actions it will be visualized as follows:
To optimize and speed up this workflow we can splitting it into several jobs, for example:
name: Parallel App Build Workflow on: [push] jobs: build: runs-on: self-hosted steps: - run: | echo "Build Application" # [...] integration-testing: needs: build runs-on: self-hosted steps: - run: | echo "Integration Testing" # [...] functional-testing: needs: build runs-on: self-hosted steps: - run: | echo "Functional Testing" # [...] deploy: needs: [integration-testing, functional-testing] runs-on: self-hosted steps: - run: | echo "Deploy Application" # [...]
ℹ Dependent Jobs: Use the needs
keyword to define dependencies and control which jobs to run sequentially and which in parallel.
In the GitHub Actions the workflow above with the parallel jobs will be visualized as follows:
Parallel jobs execution in the GitHub Actions helps to run your jobs independently that saves a lot of time and increases productivity.