axle run
axle run <task>... [options] [-- <arguments>]Runs each task, a script in package.json or a command in axle.toml, in every package that has it. A package waits for the same script in the packages it depends on, unless dependsOn in axle.toml says otherwise, and as many tasks run at once as the machine has CPU cores.
Running build in 3 packages with pnpm, up to 16 tasks at once.
@acme/core#build built@acme/ui#build built@acme/web#build built
3 tasks passed in 4.2s| Task | Runs |
|---|---|
build |
build in every package that has it |
build test |
both; they wait for each other only where dependsOn says so |
web#build |
build in web, and what it depends on |
//#lint |
lint from the root package.json |
Scripts named dev, start, serve, preview or watch, and tasks with persistent = true, run until stopped: they wait for nothing unless dependsOn says so, all start at once and don’t count towards --concurrency. A task can wait for one once it has a ready check.
Options
Section titled “Options”| Option | What it does |
|---|---|
--filter <selector> |
runs only in some packages; can be repeated |
--affected |
runs only the tasks a change affects |
--base <ref>, --head <ref> |
what --affected compares; see axle affected |
--only |
runs the named tasks without their dependencies |
--variant <name> |
runs the variant with this name of each task that has one |
--shard <index>/<count> |
runs only this CI job’s share of the tasks, such as 2/4; see splitting a run across CI jobs |
--concurrency <count> |
how many tasks run at once: a number, or a share of the CPU cores such as 50% |
--continue, --continue=always |
runs everything even after a failure |
--continue=never |
stops at the first failure, the default |
--continue=dependencies-successful |
after a failure, runs only tasks whose dependencies passed |
--log-order stream |
prints lines as they come, the default with labelled lines |
--log-order grouped |
prints each task’s output together, the default in CI |
--output-logs full |
prints all output, the default |
--output-logs new-only |
prints the output of tasks that ran, and one line for each cached one |
--output-logs hash-only |
prints one line with each task’s hash, and no output |
--output-logs errors-only |
prints only the output of tasks that fail |
--output-logs none |
prints no output |
--ui tui |
shows every task in an interactive view, the default; see terminal UI |
--ui stream |
shows each line labelled with its task |
--dry, --dry=json |
shows what would run, each task’s hash and whether it would come from the cache |
--json |
prints one JSON event per line; with --dry, the same as --dry=json |
--profile <file> |
writes a timeline to open in your browser’s performance tools |
--summarize |
writes a JSON report of the run and a page that shows it to .axle/runs/ |
--log-file <file> |
also writes every task’s output and the summary to a file, without colours; see log file |
--force |
runs every task, ignoring the cache, and stores the new results |
--cache <mode> |
what the local and remote caches may do, such as local:rw,remote:r; see caching |
--env-mode <mode> |
which environment variables tasks see: strict (the default) or loose |
--check-inputs, --check-inputs=error |
reports tasks that use files that aren’t among their inputs, or fails those tasks; see checking inputs |
--check-inputs-with <way> |
checks inputs by tracing the files tasks read, on Linux, or in a sandbox |
-- <arguments> |
passes arguments to the named tasks |
The options a repository would want to fix, such as --concurrency, can also be set under [run] in axle.toml and in an AXLE_* variable such as AXLE_CONCURRENCY. A flag wins over a variable, and a variable over the file. [hooks] in axle.toml runs commands before and after every run.
Choosing packages
Section titled “Choosing packages”| Selector | Selects |
|---|---|
web, @acme/* |
packages by name |
./apps/* |
packages by folder |
web... |
web and everything it depends on |
...ui |
ui and everything that depends on it |
{./apps/*}... |
the same, for a folder |
!docs |
leaves packages out, whatever else selected them |
[main] |
packages changed since main |
[main...v2] |
packages changed between main and v2 |
...[main] |
those packages and everything that depends on them |
./apps/*[main] |
packages in apps that changed since main |
tag:backend |
packages and projects with this tag in axle.toml |
Several filters add up, and exclusions apply last. Dependencies of selected packages still run unless you pass --only.
A Git range in square brackets compares the point where the current branch left that branch, tag or commit with your working tree, or with the second one when it has two. Changes count the same way as for axle affected, except that [main] leaves out the packages that depend on the changed ones; add ... in front to include them.
Affected packages
Section titled “Affected packages”--affected runs tasks only in the packages a change affects: those whose files changed since the base branch, and every package that depends on them. axle affected lists them and explains how they are found.
Comparing with main: 3 files changed in 1 package, which 2 others depend on.Running test in 3 packages with pnpm, up to 16 tasks at once.A task with inputs is decided on its own, as tasks explains, and axle why affected web#build says why one task runs.
With --filter, --affected narrows the selected packages to the affected ones. Dependencies of the selected tasks still run, even in packages that aren’t affected, unless you pass --only. If nothing is affected, nothing runs and Axle exits with 0.
Affected test files
Section titled “Affected test files”A task whose arguments hold {testFiles} or {changedFiles} gets the files of the change as arguments with --affected, so it runs only the tests the change reaches, even in another package:
@acme/ui#test > vitest run src/button.test.ts@acme/web#test > vitest run src/button.test.tsx--dry shows what each such task gets on a Tests: line, such as 1 test file the change reaches, or why it runs every test instead, and --dry=json adds a selection object to the task, as axle affected --files --json prints it. The files are part of the task’s hash, so a run given some files is never restored from the cache for a run given others. Running only the tests a change reaches walks through it.
Splitting a run across CI jobs
Section titled “Splitting a run across CI jobs”A large run can be spread over several CI jobs that run at the same time, each given --shard with its number and how many jobs there are:
axle run test --affected --shard 2/4Each job runs its share of the tasks named on the command line, those --filter and --affected chose, together with the tasks they wait for. Every job works out the same shares from the same commit, so each task runs in exactly one job. A task that others wait for runs in each job that needs it, and with a remote cache the first job to finish it saves the others the work.
One large test suite would still be one task in one job. With split = true, a task whose arguments hold {testFiles} runs in every job instead, each with its share of the test files:
[tasks.test]arguments = ["{testFiles}"]split = trueThe files are the task’s test files, or with --affected the ones the change reaches, shared by size so each job gets about as much to run. A job with no files for the task leaves it out. --dry shows what a job would run, so you can check the shares before you rely on them.
In GitHub Actions, a matrix gives each job its number:
strategy: matrix: shard: [1, 2, 3, 4]steps: - run: pnpm axle run test --affected --shard ${{ matrix.shard }}/4AXLE_SHARD, such as 2/4, does the same when --shard isn’t given. axle generate ci --set jobs=4 writes a workflow that splits its run this way on GitHub Actions, GitLab CI or Bitbucket Pipelines.
Caching
Section titled “Caching”A task whose inputs haven’t changed since a run that passed comes from the cache: Axle puts back its files and prints its output again instead of running it, and the summary says how many tasks came from the cache. axle why miss <task> says why a task ran instead.
A mode gives the local cache and the remote cache one of rw, r, w or off, such as local:rw,remote:r. A part left out is rw, so local:r still writes to a configured remote cache; say local:r,remote:r to write to neither. none turns both off.
| Access | Reads the cache | Stores results |
|---|---|---|
rw |
yes | yes |
r |
yes | no |
w |
no | yes |
off |
no | no |
--cache also comes from AXLE_CACHE or mode under [cache] in axle.toml, and --env-mode from AXLE_ENV_MODE or envMode under [run]. --force stops this run reading the cache, but it still stores results unless the mode says not to. In strict mode, a task sees only the environment variables it needs to run and those listed in axle.toml; caching lists them.
--summarize writes .axle/runs/<time>.json once the run ends: a formatVersion of 1, the version of Axle, the title, such as axle run build, startedAt and finishedAt in milliseconds since 1970, and each task with its hash, status, time, startMs and endMs counted from the start of the run, savedMs, the time the cache saved when it came from there, and inputs, with the names of its environment variables but not their values, and the commands whose output it hashes. Axle puts a .gitignore in .axle/, so reports are never committed.
Beside it, .axle/runs/<time>.html shows the same run in your browser, with nothing to install and nothing sent anywhere: a timeline of when each task ran, what passed, failed or came from the cache, the time the cache saved, and, for each task you pick, its folder, hash, command, files, environment variable names and the tasks it waited for. Search and pick a status to narrow the list.
Log file
Section titled “Log file”--log-file <file> writes every task’s output, each line labelled with its task as --ui stream labels it, and then the summary, to a file, whichever view the terminal shows and whatever --output-logs leaves out of it. Colours and other terminal codes are left out, so the file reads well in an editor or a CI artifact:
@acme/core#build built@acme/web#build built
2 tasks passed in 4.2sLines go to the file as they come. In the terminal UI, each task’s output is written when the task ends, as the view showed it. The file is created afresh for every run; a relative path is relative to the folder you started Axle in. It also comes from AXLE_LOG_FILE, and from logFile under [run], where a relative path is relative to the repository’s root. If the file can’t be written, Axle stops with log-file-not-written.
Checking inputs
Section titled “Checking inputs”A task whose inputs leave out a file it uses can come from the cache after that file changed. --check-inputs looks for such tasks and warns about each; --check-inputs=error also fails them, so CI can keep inputs complete. Tasks that come from the cache don’t run, so they aren’t checked. It slows a run down, so it is off by default. It also comes from checkInputs under [run], "off", "warn" or "error", and from AXLE_CHECK_INPUTS.
It checks in one of two ways, which --check-inputs-with, checkInputsWith or AXLE_CHECK_INPUTS_WITH choose:
| Way | Where | How |
|---|---|---|
tracing |
Linux only, and the default there | follows every file each task opens while it runs |
sandbox |
every system, and the default on macOS and Windows | runs each task again in a copy of the repository holding only what it declares |
Tracing
Section titled “Tracing”On Linux, Axle follows each task’s processes through the system’s debugging interface and warns about each file one reads that isn’t among its inputs:
warning: @acme/web#build: read packages/web/.env, which isn't among its inputshint: Add it to the task's inputs in axle.toml, so that changing it runs the task again.It leaves out files in node_modules, .git and .axle, files outside the repository, files changed while the task ran, and files that the task or a task it waits for declares as inputs or outputs. Tasks run noticeably slower while traced. On macOS and Windows, which don’t let Axle trace without administrator rights, tracing is an error.
Sandbox
Section titled “Sandbox”After a task runs and passes, Axle runs it again in a new folder in the system’s temporary folder holding only:
- the task’s inputs, as Axle hashes them;
- the inputs and outputs of the tasks it waits for, as the run just left them, or every file in a folder whose task has no
outputs; - each
package.json, the lockfile and the package manager’s settings files, so the script can start; - the installed packages, linked from each
node_modulesrather than copied: with junctions on Windows, which need no administrator rights, and symbolic links elsewhere. Caches tools keep there, such asnode_modules/.cache, are left out.
The task gets the same environment as before. If it fails there, Axle shows its output from that run and warns; if it passes but writes outputs that differ from the first run’s, Axle names each one:
warning: @acme/web#build: failed when given only its inputshint: Its output from that run is above. Add the files it needs to the task's inputs in axle.toml.warning: @acme/web#build: wrote a different packages/web/dist/index.js when given only its inputshint: Add the files it's made from to the task's inputs in axle.toml, or make the task write the same file every time.The first run is the one you get: its output, its files and its result in the cache. The copy never touches the repository and is removed when the check ends, also when you stop the run with Ctrl+C. Persistent and interactive tasks, tasks with cache = false and tasks a plugin runs in a batch aren’t checked, since running them twice could do harm or wouldn’t end.
The sandbox costs a second run of every task, and it notices less than tracing:
- A task that reads an undeclared file but writes the same outputs without it, such as a linter, passes the check.
- A task whose outputs change from run to run, such as a build that writes the time, or a tool that writes where installed packages really are, such as a bundler’s source maps, is reported even when its inputs are complete. A path to the copy in an output is read as the repository’s, so a tool that writes absolute paths of the task’s own files is fine.
- A task that needs Git’s history fails in the copy, which has none.
On Linux, --check-inputs-with=sandbox checks this way too, which helps where tracing isn’t allowed, such as in some containers.
Terminal UI
Section titled “Terminal UI”In a terminal, axle run shows the run in an interactive view, as on the home page: the tasks down the left, and the output of the selected task beside it, with the task’s description after its name at the top. The tasks are grouped under Running, Failed, Done and Waiting, each with how many it holds, so what’s finished and what’s left are apart at a glance. A spinner marks a running task, with how long it has run or ready once its ready check passes; ✓ one that passed, with its time, or in blue with cached if it came from the cache; ✗ one that failed; ■ one that was stopped; ○ one skipped; and · one still waiting. ◆ marks a pinned task. Above them, a bar fills as tasks finish, beside how many are done, how many came from the cache, how many failed and how long the run has taken; it turns green when the run ends well and red once a task fails. Each task runs in its own pseudo-terminal, so tools print colours and progress bars as they would in your terminal.
| Key | What it does |
|---|---|
Up and Down, or k and j |
selects a task |
| Page Up and Page Down, mouse wheel | scrolls back through its output |
/ |
searches the selected task’s output; n and N move between matches, and Esc clears the search |
p |
pins the selected task, so its output stays in view beside the others; up to four |
r |
restarts the selected persistent task, but not the tasks that wait for it |
| Enter | types into the selected interactive task, until Ctrl+Z |
q, Ctrl+C |
stops the run |
--ui stream, ui = "stream" under [run] or AXLE_UI=stream turns it off. A restarted task’s earlier output stays in its history, above a -- restarted -- line. When the run ends, the view closes and Axle prints the output of each task that failed, then the summary. Where it can’t help, Axle prints labelled lines anyway: when the output isn’t a terminal, in CI, with --json, --dry or --output-logs none, and for a single task that isn’t persistent or interactive.
Axle counts a run as in CI when the CI environment variable is set, as CI services do, to anything but an empty value, 0 or false in any case. In CI it groups each task’s output by default and leaves out the terminal UI.
OpenTelemetry
Section titled “OpenTelemetry”With OTEL_EXPORTER_OTLP_ENDPOINT set, Axle sends a trace of each axle run and axle exec to that OpenTelemetry collector once the run ends, so CI runs show up in the same place as your other traces. It reads the standard variables and sends nothing when no endpoint is set:
| Variable | Meaning |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT |
the collector’s base address, such as http://localhost:4318; Axle sends to /v1/traces under it |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT |
the full address of the traces endpoint, used as it is and winning over the one above |
OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TRACES_HEADERS |
headers such as an API key, as name=value pairs separated by commas, with % escapes |
OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT |
how long to wait for the collector, in milliseconds; 10 seconds by default |
OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL |
http/json or http/protobuf; Axle sends JSON over HTTP either way, and refuses grpc |
OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES |
the service name, axle by default, and other resource attributes, such as deployment.environment=ci |
OTEL_SDK_DISABLED=true, OTEL_TRACES_EXPORTER=none |
send nothing, even with an endpoint set |
The trace has a span for the run, named after the command, such as axle run build, with axle.version and the number of tasks that passed, came from the cache and failed. Each task that ran or came from the cache is a span inside it, named after the task, from when it started to when it ended, with axle.task, axle.package, axle.script, axle.folder, axle.hash, axle.status, axle.cache.hit and, on a hit, axle.cache.saved_ms. A failed task and a failed run have an error status. Nothing about a task’s output, environment or files is sent.
A collector that can’t be reached is a warning; the run’s results and exit code don’t change.
Failures and stopping
Section titled “Failures and stopping”The first failure stops the run, and Axle exits with that script’s exit code. Ctrl+C, or q in the terminal UI, stops every task and what those tasks started, and Axle exits with 130. Axle passes the Ctrl+C on and waits for every task to finish shutting down, so a server can close its connections and a script can stop what it started; press Ctrl+C again to end them at once. When a task fails, the others get 5 seconds to stop before they are ended by force.
JSON events
Section titled “JSON events”{ "run": 1, "event": "run-started", "protocol": 1, "tasks": 1, "concurrency": 16 }{ "run": 1, "event": "task-started", "task": "web#build", "hash": "6c0d5e93…" }{ "run": 1, "event": "output", "task": "web#build", "stream": "stdout", "line": "built" }{ "run": 1, "event": "task-finished", "task": "web#build", "status": "passed", "exitCode": 0, "durationMs": 1180 }{ "run": 1, "event": "run-finished", "passed": 1, "cached": 0, "failed": 0, "skipped": 0, "durationMs": 1210 }run numbers the run each event belongs to. It’s always 1 for axle run; axle watch numbers each of its runs. protocol in run-started is the version of these events. It goes up only when a change would break a tool that reads them, such as an event or field taken away or a field that changes meaning; new events and fields can arrive without it, so a tool should skip what it doesn’t know. The npm package ships events.schema.json, a JSON Schema of every event.
status is passed, cached, failed or stopped; a stopped task’s exitCode is null. A persistent task whose ready check passes gets { "event": "task-ready", "task" }. hash is left out for a task that isn’t hashed. A task from the cache gets { "event": "cache-hit", "task", "hash", "savedMs", "source" } after task-started, then its stored output as output events; savedMs is how long the task took when it was stored, and source is local or remote. A passed task whose result is stored gets { "event": "cache-stored", "task", "hash", "remote" }, with remote true when it was also handed to the remote cache. A persistent task restarted from the terminal UI, or by axle watch, gets { "event": "task-restarted", "task" } and then task-started again. A warning during the run, such as a task that changed its own inputs, is { "event": "warning", "task", "code", "message", "hint" }; one from before the run, such as a filter that matches nothing, has no task and comes before run-started. code names the warning’s page under messages, such as task-changed-its-inputs. --check-inputs adds { "event": "input-warning", "task", "reason", "file" } for each problem it finds: reason is read for a file a traced task read that isn’t among its inputs, differs for an output that differed in the sandbox, both with the file, or failed, with no file, for a task that failed in the sandbox.
A task that never started gets { "event": "task-skipped", "task", "reason" } just before run-finished. reason is dependency-failed when --continue=dependencies-successful left it out after a task it waits for failed, and stopped when the run stopped first.
--dry=json prints one document that starts with "formatVersion": 1, then packageManager, concurrency and tasks. Each task has the fields of axle graph --format json, including its variant or null, its description or null, persistent and waitsFor, then the command it would run, its hash, and cache, which is hit, miss, off or after-dependencies. lastRun says when this checkout last ran the task or restored it from the cache, as { "at", "durationMs", "hash" }, with at in milliseconds since 1970 and durationMs how long the task took, or is null when it hasn’t. When its hash equals the task’s hash, nothing has changed since. A task with ^outputs in its inputs is only hashed once the tasks it waits for have finished, so --dry shows “after dependencies” for its hash and cache, and --dry=json gives null and after-dependencies.
An error from Axle itself prints { "run": 1, "event": "error", "code", "message", "hint" }, also with --dry=json, where code names its page under messages, such as unknown-task.