Sub topic 2
Jobs run in parallel by default
This chapter assumes you can read basic YAML, have a workflow file in .github/workflows, and know the on, jobs, runs-on, and steps keys. It covers what happens when you define several jobs and say nothing about their order.
The default: everything starts at once
A workflow is a set of jobs. Each job is a list of steps that runs on its own runner, which is a fresh virtual machine provisioned for that job. Unless you add dependencies, GitHub Actions schedules every job as soon as a runner is available. The order in which you list jobs in the YAML does not matter.
Here is a workflow with two jobs and no dependencies between them:
name: CI
on: [push]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm testWhen you push, lint and test both start at about the same time. The workflow takes roughly as long as the slower of the two, not the sum of both.
Why each job is isolated
Each job gets its own runner, so jobs do not share state. This has three consequences:
- Files created in one job do not exist in another. Even if both jobs run
npm ci, each installs its own copy. - Each job must check out the code itself with
actions/checkout. Checking it out inlintdoes nothing fortest. - Environment variables set in one job are not visible in another.
This isolation is what makes parallel execution safe. Jobs cannot interfere with each other, because they do not touch the same machine.
When parallel is the wrong default
Parallel jobs are a good fit for independent work such as linting, unit tests, and documentation checks. They are a poor fit when one job needs the result of another. Consider this workflow:
name: Broken pipeline
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run build
deploy:
runs-on: ubuntu-latest
steps:
- run: echo "Deploying"deploy does not wait for build. Both start immediately, so deploy can finish, or deploy broken code, while build is still running or has already failed. Nothing in the file says that deploy depends on build, so the scheduler does not infer it.
Common errors
- Assuming top-to-bottom order. A
deployjob listed last still starts first if a runner is free. - Expecting shared files. A job that reads
dist/produced by another job fails with "No such file or directory" unless you pass the files as artifacts. - Forgetting checkout. Running
npm ciin a job withoutactions/checkoutfails because the repository is not on the runner. - Assuming unlimited parallelism. Runners are limited by your plan's concurrency quota. Extra jobs wait in a queued state until a runner frees up, and they still start in no guaranteed order.
Reading parallelism in the UI
Open the run in the Actions tab. The workflow graph shows jobs without dependencies as separate boxes in the same column, with no arrows between them. Each box has its own status and logs. If you see an unconnected box that you expected to run later, a needs entry is missing.
Exercise
A workflow defines the jobs deploy, build, and test in that order, with no needs keys. In what order do they run, and why might deploy finish before build?
Show answer
They have no guaranteed order. All three are scheduled in parallel as soon as runners are available, regardless of their position in the file. deploy can finish first because nothing makes it wait for build, so it may run against code that has not been built or has failed to build.
Exercise
Two parallel jobs each run npm ci. Does the second job reuse the first job's node_modules? Explain.
Show answer
No. Each job runs on its own fresh runner, so node_modules is installed separately in each job. Sharing files between jobs requires artifacts, which a later chapter covers.