CI / Speed and debugging
Skip jobs that nothing changed for
Your pull request has a slow test job, and a docs fix runs it again for ten minutes, although no file that it tests changed. Tell the forge which files the job reads: when they did not change since a run where the job passed, the job takes that result and starts no container.
5 min read
The forge also compares your workflow files and the job itself. The job gets the result of that run, with its outputs and its summary.
1. Add inputs to the job
Give the job inputs: the path patterns of every file that can change its result. The patterns are the patterns of pullRequest({ paths }), and a ! pattern removes files:
import { defineWorkflow, pullRequest, setup } from '@tanstack-source/ci'
export default defineWorkflow('pr', { on: [pullRequest({ branches: ['main'] })] })
.job('test', {
inputs: ['packages/**', '!packages/*/README.md', 'package.json', 'pnpm-lock.yaml', 'tsconfig.json'],
steps: [
setup.node(),
setup.pnpm(),
{ name: 'Install dependencies', run: 'pnpm install --frozen-lockfile' },
{ name: 'Test', run: 'pnpm test' },
],
})
A job without inputs is reused too, but only when no file of the commit changed: for example after a rebase that changed nothing, or an empty commit.
2. Open a pull request, and let the job pass once
The first run of the pull request has no result to reuse. The test job runs, as before. When it passes, the forge keeps its result for the next runs.
3. Push a change outside the inputs
Push a change to docs/ only. In the new run:
- The
testjob passes at once. On the pull request, its check says Passed, unchanged since run with a link to the run where it passed. - The job page says that the job did not run, and links to that run.
- The jobs that need
testget the outputs of the job that passed.
Done
A docs fix no longer waits for the tests. Push a change to a file of packages/, and the job runs again.
What makes the job run again
The forge computes a key for each job, from:
- The git ids of the files that match
inputs, in the commit that the job checks out (the head of the pull request). Withoutinputs, the id of the whole tree of that commit. The forge reads the ids from the git trees, and never the files. - The
.sourcefolder of that commit: your workflow files, and the files that they import from it. - The job itself: its steps,
env, image, size, timeout, checkout, cache settings, matrix cell, secret and variable names, permissions and egress, and theenvof the workflow. - The results and the outputs of the jobs that it needs.
- The pull request and its head branch, and the commits of the extra checkouts of a virtual monorepo.
A difference in any of these gives another key, and the job runs. The values of secrets and variables are not in the key.
When a job always runs
- In a push,
schedule(),manual()orafter()run. These runs can deploy or publish, so their jobs always run, and they give no result to reuse. - In a run of a hidden workflow, and in a run of a private pull request.
- When a person runs the run or the job again, or selects "Run checks" on the pull request. These runs never reuse a result.
- When the job did not pass in the earlier run. A job that failed, was cancelled or was skipped gives no result to reuse.
- When the earlier run had a lower trust level. A run reuses only a result of a run at its own trust level or a higher one. So a run of a pull request from a fork never gives a result to a trusted run.
The forge also does not walk a tree of more than 50,000 files and folders for inputs, so the job runs in such a commit.
What can go wrong
- A wrong
inputslist gives a wrong pass. When the job reads a file that is not ininputs, a change to that file does not run the job. List every file that the job reads, its configuration files and the lockfile. When you are not sure, leaveinputsout: then the job runs for any change. - The base branch is not in the key. The job checks out the head of the pull request. When the job compares the head with the base branch, like
nx affected, a new commit on the base branch alone does not run it again. - A reused job does nothing else. It has the outputs and the summary of the job that passed, and no log, findings or artifacts of its own. Open the run that it came from to read them.
Read it in REST, MCP and src
Each job of a run has reusedFrom: { run, job, jobId } of the job whose result it took, or null for a job that ran.
GET /api/v1/repos/<owner>/<repo>/ci/runs/<run>and the MCP toolget_ci_rungive it for each job.GET /ci/runs/<run>/timingandget_ci_run_timinggive it too, and no timed parts for that job.src run viewprints✓ test (unchanged since run <run>), and--json jobsgivesreusedFrom.src ci viewputsUnchanged since run <run>: it did not run.in the note of the job.