moon run (or moon r) command will run one or many task targets and all of their dependencies in topological order. Each run will incrementally cache each task, improving speed and development times over time.
moon run is to “fail fast”, meaning that any failed task will immediately abort execution of the entire action graph. Use --on-failure continue for alternative behavior.
:::
How it works
Themoon run command is built on top of moon exec and provides a user-friendly interface for running tasks. It automatically:
- Resolves targets - Expands target locators (like
:testor#tag:build) into concrete project:task pairs - Builds dependency graph - Creates an action graph with all task dependencies in topological order
- Checks cache - Determines which tasks can be skipped based on cached results
- Executes pipeline - Runs tasks in parallel when possible, respecting dependencies
- Handles failures - Stops execution immediately on any task failure (bail mode)
Arguments
...<target>- Task targets or project relative tasks to run. See target syntax for details.[-- <args>]- Additional arguments to pass through to the underlying command.
Target syntax examples
| Syntax | Description |
|---|---|
app:lint | Run lint task in app project |
:test | Run test task in all projects |
~:build | Run build in closest project |
#frontend:lint | Run lint in all projects with frontend tag |
format | Run format task in default project |
Options
Inherits all options frommoon exec and pre-fills with: --on-failure=bail, --upstream=deep.
Common options
-f,--force- Force run and bypass cache, ignore changed files, and skip affected checks.-i,--interactive- Run the pipeline and tasks interactively.-s,--summary [LEVEL]- Print a summary of all actions that were ran in the pipeline.
Workflow options
--query <QUERY>- Filter tasks based on the result of a query expression.
Affected options
--affected [BY]- Only run tasks if affected by changed files. Optionally accepts “local” or “remote”.--base <BASE>- Base branch, commit, or revision to compare against.--head <HEAD>- Current branch, commit, or revision to compare with.-g,--include-relations- Include graph relations for affected checks.--status <STATUS>- Filter changed files based on a changed status.--stdin- Accept changed files from stdin for affected checks.
Graph options
--downstream <DEPTH>- Control the depth of downstream dependents. Supportsnone(default),direct,deep.--upstream <DEPTH>- Control the depth of upstream dependencies. Supportsnone,direct,deep(default).
Parallelism options
--job <INDEX>- Index of the current job (0 based) for splitting work across multiple CI jobs.--job-total <TOTAL>- Total amount of jobs to run.
Examples
Run a single task
Run multiple tasks
Run task in all projects
Run with passthrough arguments
Pass arguments directly to the underlying command:Run only affected tasks
Run tasks only for projects affected by changed files:Run with custom base/head revisions
Run with query filter
Filter tasks based on project metadata:Force run without cache
Bypass cache and run all tasks fresh:Run interactively
Run tasks with interactive input/output:Show execution summary
Environment variables
The following environment variables can be used as alternatives to command line options:MOON_FORCE- Same as--forceMOON_AFFECTED- Same as--affectedMOON_BASE- Same as--baseMOON_HEAD- Same as--headMOON_INCLUDE_RELATIONS- Same as--include-relationsMOON_JOB- Same as--jobMOON_JOB_TOTAL- Same as--job-totalMOON_NO_ACTIONS- Same as--no-actionsMOON_SUMMARY- Same as--summary
Configuration
Themoon run command is configured through:
Comparison with moon exec
moon run is a simplified, user-friendly wrapper around moon exec with these defaults:
--on-failure=bail- Stops immediately on any failure--upstream=deep- Includes all upstream dependencies
moon exec directly.