Jobs and Matrices
Parallelize without losing control of execution time or your bill.
A test suite that takes twelve minutes in a single job often takes four across three parallel jobs. The gain is real, but it comes at the price of added complexity, and above all an unpleasant discovery: what one job produced doesn't exist for the others. The most common mistake in a multi-job workflow is to build in one job, then try to use the result in another one — which runs on an entirely different machine with an empty filesystem.
The second pitfall involves matrices. Testing three language versions on three operating systems seems reasonable until you do the math: nine full runs of the suite for every commit. If each one takes five minutes, a single commit costs forty-five runner minutes, and Windows minutes are billed at twice the rate of Linux minutes, macOS at ten times. A matrix is a multiplier; writing one is easy, deciding on its size is the real work.
Parallelism by Default
Two jobs declared in the same workflow start simultaneously, on two separate runners.
name: Verifications
on:
pull_request:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm run lint
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm test
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion