CI / Start
Run CI jobs on your machine
A CI job failed on the forge, and each try of a fix costs a push and a wait for a container. Run the same job on your machine, fix it there, and push once.
5 min read
src ci run runs the job as the forge does: the same workflow file, steps, matrix cell and needs.
You need:
- The
srcCLI. It is in the npm package@tanstack-source/cli, which has thesrcbinary.src ci planandsrc ci runwork without the forge.
1. Plan the workflows
src ci plan
The command shows each workflow and its jobs, or the errors with the file to fix.
2. Give the job its secrets
If the job declares secrets, it gets each one from your environment, then from .env in the root of the checkout. For example, a publish job of a release workflow that needs NPM_TOKEN:
echo 'NPM_TOKEN=<your own token>' >> .env
src ci run release publish
On your machine the job gets the value itself, because no proxy sits between the job and the network.
The run reads from
.envonly the secrets that the jobs declare.If a required secret has no value, the command stops before any job runs:
src ci run: Job publish needs the secret NPM_TOKEN. Set it in the environment or in .env.
Warning
Keep .env out of git. By default, the forge refuses a push that adds a .env file.
3. Run the job
src ci run ci test
The command exits with 0 when the job passed, and with 1 when it failed. To run one matrix cell, or the jobs that it needs first, add a flag.
The end of the output shows the failed test, with its file and line:
--- Test
FAIL src/sum.test.ts > sum > adds two numbers
error src/sum.test.ts:5:22 sum > adds two numbers: expected 3 to be 4 // Object.is equality
Error: vitest exited with code 1
...
--- Test: failed (9.9 s): vitest exited with code 1
--- Save cache pnpm-3b1f2a9c8d7e6f50: skipped
Job test failed: Step "Test" failed: vitest exited with code 1
4. Fix it, and run it again
Fix src/sum.ts, then run the job again:
--- Test
✓ src/sum.test.ts (2 tests) 3ms
No findings
--- Test: passed (6.0 s)
--- Save cache pnpm-3b1f2a9c8d7e6f50
Saved the cache pnpm-3b1f2a9c8d7e6f50 in /home/you/.cache/tanstack-source/ci
--- Save cache pnpm-3b1f2a9c8d7e6f50: passed (2.2 s)
Job test passed.
Tip
If the job passes on your machine and fails on the forge, the tools can be different. Run a job in its CI image with --docker.
5. Push once
Commit the fix and push it. Then list the runs of your pull request:
src ci runs --pr 12
ID STATUS WORKFLOW EVENT REF COMMIT
d4e5f6a7-8b9c-4d0e-9f1a-2b3c4d5e6f70 success ci pull_request fix-sum 5d6e7f8
b51f0e2a-6c7d-4e8f-9a1b-2c3d4e5f6a7b failure ci pull_request fix-sum 1a2b3c4
Done
The run of your fix is green, after one push.
To run a job of a forge run again with its exact matrix cell, inputs and needs, see Run a forge job again on your machine.
Flags of src ci run
| Flag | What it does |
|---|---|
--matrix <key>=<value> | Runs only the matrix cells with this value. Repeat it for more keys. Without it, every cell runs, one after the other. |
--with-needs | Runs the jobs that the job needs first, and gives it their results and outputs. |
--input <name>=<value> | Gives a value to an input of manual(). Repeat it for more inputs. The run then has the event manual. |
--live | Sends the writes of forge() to the forge. See Send real writes to the forge. |
--docker | Runs the job in its CI image. See Run a job in its CI image. |
src ci run e2e test --matrix shard=2
src ci run ci gate --with-needs
src ci run release publish --input channel=next
If a job has needs and you leave out --with-needs, the job gets no results or outputs of them. The command then warns you:
Job gate needs test, and this run gives it no results or outputs of them. Add --with-needs to run them first.
How a local run differs
- The trust level is
local. - The event is the type of the first trigger of the workflow. With
--input, the event ismanual. ctx.headis the commit that you checked out,ctx.baseis its parent, andctx.refis your branch.- The steps run in Bash, in the root of your checkout, with your environment.
- Your machine has its own tools. To use the tools of the forge, run the job in its CI image.
Windows local runs need native Bash, such as the Bash in Git for Windows. The runner checks the step's PATH and PATHEXT, including step overrides. It resolves relative PATH entries from the step's working directory. It checks for Bash beside each Git executable and continues when an installation has no Bash. Git's usr/bin/bash.exe keeps the requested PATH, unlike its bin/bash.exe wrapper. The runner resolves Bash for each script, so changed environments and removed files take effect. WSL launchers and WindowsApps aliases are not supported. A missing native Bash produces an error before the script starts.
An embedded Git installation can use a separate native Bash on PATH. Bash does not add missing Git programs. Jobs that use Git HTTP or newer merge commands still need a Git installation that supplies them.
Where the cache, artifacts and fixups go
A local run keeps them in a folder of your machine: $XDG_CACHE_HOME/tanstack-source/, or ~/.cache/tanstack-source/ when XDG_CACHE_HOME is not set.
| Folder | What it holds |
|---|---|
ci/ | The entries of cache() and of the step cache. Delete this folder to start with an empty cache. |
artifacts/ | The archives of artifact(). The step prints the path of each one. |
fixups/ | The patches of fixup(). The step prints the git apply command for each one. |
tools/ | The Node, bun and pnpm that the setup steps download. |
report() prints its findings in the log of the step.
Send real writes to the forge: --live
Without --live, each forge() write is a dry run. The step prints the write and sends nothing:
[dry run] POST /repos/acme/app/issues/7/comments {"body":"Released"}
With --live, the job also gets TSS_FORGE_URL and TSS_TOKEN, and forge() sends each write. --live needs TSS_FORGE_URL, TSS_TOKEN and TSS_REPO.
export TSS_FORGE_URL=https://forge.example/api/v1
export TSS_TOKEN=<your personal access token>
export TSS_REPO=acme/app
src ci run release publish --live
Caution
Use --live only when you want the writes on the forge. The writes use your own token, so the permissions of the job do not limit them.
Measure startup on Source
A local run cannot measure the start of a VM or the queue of the account. To measure them on Source, see Measure how fast CI jobs start.