How to Reduce CI Cost by Consolidating Jobs
Each job provisions a fresh runner, checks out the repo, and restores caches, so ten one-minute jobs cost far more than one ten-minute job.
Where jobs do not need real parallelism or different runners, fold them into one job with sequential steps to pay the setup tax once.
Steps
- List jobs that each do a few seconds of work on the same runner.
- Merge lint, typecheck, and unit tests into one job when they share setup.
- Keep genuinely long or independent work as separate parallel jobs.
Workflow
.github/workflows/ci.yml
jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm testGotchas
- Merging serializes steps, so it trades a little wall-clock time for lower cost.
- Do not merge jobs that need different runner sizes or operating systems.
- Billing rounds each job up to the nearest minute, so many short jobs round up repeatedly.
Related guides
How to Skip Duplicate Runs With ConcurrencyCancel superseded GitHub Actions runs with a concurrency group and cancel-in-progress, so rapid pushes to a b…
How to Control Matrix Cost ExplosionKeep a GitHub Actions build matrix from multiplying your minutes bill by pruning combinations with exclude an…