CI / Rules
Require all jobs with one check
Your workflow has many jobs, like lint and tests in 4 shards, and you want one required check that passes when all of them pass. .requireAll() adds that job: it runs no steps, needs no container, and the forge decides it as soon as the jobs that it needs end.
2 min read
A last job that checks the others needs a container of its own. It waits for a slot before it can pass, and your deploy waits with it. A .requireAll() job passes only when every job that it needs passed, with every matrix cell, and it never waits for a slot.
1. Add the job
Add it after the jobs that it needs:
import { defineWorkflow, pullRequest, push, setup } from '@tanstack-source/ci'
const install = { name: 'Install', run: 'pnpm install --frozen-lockfile' }
export default defineWorkflow('ci', { on: [pullRequest({ branches: ['main'] }), push({ branches: ['main'] })] })
.job('lint', {
egress: ['registry.npmjs.org'],
steps: [setup.pnpm(), install, { name: 'Lint', run: 'pnpm lint' }],
})
.job('test', {
matrix: { shard: [1, 2, 3, 4] },
egress: ['registry.npmjs.org'],
steps: [setup.pnpm(), install, { name: 'Test', do: (ctx) => ctx.sh`pnpm vitest run --shard=${ctx.matrix.shard}/4` }],
})
.requireAll('checks', { needs: ['lint', 'test'] })
needsnames at least one job declared before it.- The job passes when every cell of each job that it needs passed. A cell that failed, was skipped or was cancelled makes it fail.
- It takes no option other than
needs. It has no steps, no matrix, no secrets and no outputs.
Run src ci plan to see it:
ci (.source/workflows/ci.ts)
on: pull request (branches: main), push (branches: main)
jobs:
lint
test: 4 matrix cells (shard: 1, 2, 3, 4)
checks: requires all of lint, test
1 workflow, 3 jobs.
2. Make it the required check
A required check is <workflow>/<job>. Require ci/checks on main:
src ci rule set main --require-pull --check ci/checks
When you add a job to the workflow later, add it to needs. The branch rule stays the same.
3. Start the deploy after it
A later job can need it, like any job:
.requireAll('checks', { needs: ['lint', 'test'] })
.job('deploy', {
needs: ['checks'],
if: (ctx) => ctx.event === 'push',
steps: [{ name: 'Deploy', run: './deploy.sh' }],
})
checks passes as soon as the last job that it needs passes, and the deploy starts right after it. No container starts for checks between them.
Done
One check now stands for the whole workflow, and it costs no container time.
- The checks of the pull request list
ci/checkswith its summary. The summary isEvery job it needs passed., or names the jobs that did not pass, likeThese jobs it needs did not pass: test. - The check has no Details link, because no job ran.
- The run page shows
checkswith the same summary, and no log. - On your machine,
src ci run ci checks --with-needsrunslintandtestfirst. Then it printsJob checks passed: every job it needs passed.