CI / Speed and debugging
Share steps across repositories
Ten repositories set up pnpm and install their dependencies with the same steps, each with its own copy, so a fix needs ten pull requests. Put the steps in a TypeScript module in one repository: each workflow imports it with a src: import, and .source/src.lock pins the exact commit that it runs.
4 min read
You need the src CLI (the npm package @tanstack-source/cli), logged in. src ci commands use your login. Without a login, set these forge variables:
export TSS_FORGE_URL=https://forge.example/api/v1
export TSS_TOKEN=<your personal access token>
1. Write the module
Create a repository for the shared steps, like acme/ci-steps. Add the file pnpm.ts:
import { setup, type Step } from '@tanstack-source/ci'
/** Sets up the pnpm that package.json names, then installs the dependencies. */
export function pnpmInstall(): Step[] {
return [setup.pnpm(), { name: 'Install', run: 'pnpm install --frozen-lockfile' }]
}
A module can import only these:
- Relative files of the same repository, at the same commit.
- Other
src:modules. @tanstack-source/ci. The runner gives its own copy.node:built-ins.
Push the module, then tag a version and push the tag:
git tag v1.0.0
git push origin v1.0.0
2. Import it in a workflow
In the repository acme/app, import the module in .source/workflows/ci.ts:
import { defineWorkflow, pullRequest } from '@tanstack-source/ci'
import { pnpmInstall } from 'src:acme/ci-steps@v1.0.0/pnpm.ts'
export default defineWorkflow('ci', { on: [pullRequest({ branches: ['main'] })] })
.job('test', {
egress: ['registry.npmjs.org'],
steps: [...pnpmInstall(), { name: 'Test', run: 'pnpm test' }],
})
A specifier is src:<owner>/<repo>@<ref>/<path>.ts. The ref is one tag, branch or commit name, with no / in it. Import a module only with a static import. The forge refuses import() of a src: module.
A repository created on or after 2026-11-26 requires commit pins: the ref must be a commit, not a tag or a branch. Write the tag as here, then run src ci update --pin in step 3, and it writes the commit for you. See Pin shared modules to commits.
3. Pin it with src ci update
Run src ci update in the root of acme/app:
src ci update
acme/ci-steps@v1.0.0: new pin at 3f2a1b9
added pnpm.ts: 6 lines
Wrote .source/src.lock.
Synced acme/ci-steps@v1.0.0 at 3f2a1b9: 1 file.
Added .source/.modules/ to .gitignore.
Wrote .source/tsconfig.json.
src.lockpins the commit of each<owner>/<repo>@<ref>, its tree, and a hash of the files that the workflows load.- The module files go to
.source/.modules/, and git ignores that folder. .source/tsconfig.jsonmapssrc:imports to those files, so your editor has types.- Your login, or
TSS_TOKEN, must be able to readacme/ci-steps.
4. Commit the lock file
Commit the workflow and the lock file, and push:
git add .source/workflows/ci.ts .source/src.lock .gitignore
git commit -m "ci: use the shared pnpm steps"
git push
After a new clone, run src ci sync. It downloads the pinned files, for your editor and for src ci plan and src ci run. It changes no pin. On the forge, each CI job gets the pinned files from the forge before its workflow loads, with the same checks as the plan. A job whose modules can't load fails with the reason.
Done
The test job runs the shared setup steps from commit 3f2a1b9. Do steps 2 to 4 in a second repository, like acme/web, and src ci update pins the same commit:
acme/ci-steps@v1.0.0: new pin at 3f2a1b9
added pnpm.ts: 6 lines
Both repositories run the same reviewed setup steps. A change to acme/ci-steps reaches a repository only when that repository runs src ci update. See Update a shared module.
Who can import a module
- Any repository can import a module of a public repository.
- A private repository can import a module of a private repository of the same owner, when an admin allows it.
- A public repository cannot import a module of a private repository.
To allow a private repository, an admin of the repository that imports adds it to the allowed workflow sources:
export TSS_REPO=acme/app
src ci source add acme/ci-steps
Workflows may import src: modules from acme/ci-steps.
In the browser, open Settings, then CI under Code (/@<owner>/<repo>/settings/ci). Under Allowed workflow sources, enter acme/ci-steps and click Allow.
If the forge cannot use the repository, the plan stops with this error. The words are the same for a repository that does not exist:
src:acme/ci-steps@v1.0.0/pnpm.ts: the repository acme/ci-steps was not found. A private repository works only when it has the same owner, and an admin of acme/app adds it to the allowed workflow sources.
Find errors before you push
A push or a pull request with a src: error records a failed run with no jobs. The run shows the error on the CI tab, on the run page, and in the checks of the pull request. To find errors before you push, run src ci plan on your machine. It shows the errors of your checkout, like a src: import with no entry in src.lock.
| The error says | Do this |
|---|---|
... has no entry in .source/src.lock | Run src ci update. |
The files imported from acme/ci-steps@v1.0.0 changed since .source/src.lock pinned them | A workflow imports another file of the module. Run src ci update. |
... is not in .source/.modules/ | This error is on your machine only. Run src ci sync. |
... this repository requires commit pins | Run src ci update --pin. See Pin shared modules to commits. |
... commit 3f2a1b9 is not on any branch or tag of acme/ci-steps | The commit is not one that acme/ci-steps published. Pin a commit of one of its tags or branches. |
Caps
For one plan, the forge reads all src: modules together, with these caps:
- At most 1 MiB of module files.
- At most 100 module files.
- Imports at most 8 deep. The
src:import of a workflow has depth 1, and a file that it imports has depth 2.