moon exec (or moon x, or moonx) command is a low-level command for executing tasks in the action pipeline. It provides fine-grained control over how tasks are selected and executed through command line options, making it ideal for custom workflows and advanced use cases.
The moon check, moon ci, and moon run commands are all built on top of moon exec, so be sure to check those out for more user-friendly abstractions!
Usage
How it works
When you executemoon exec, it performs the following steps:
- Load changed files - Determines which files have changed based on VCS (git) information. This supports both local development and CI environments, with automatic detection of base and head revisions in CI.
- Build action graph - Constructs an action graph that includes all tasks and their dependencies. The graph can be filtered using queries and affected checks.
-
Track affected tasks - When
--affectedis enabled, identifies which tasks are impacted by the changed files. - Execute action pipeline - Runs all actions in the graph in topological order, respecting dependencies and running tasks in parallel where possible.
Arguments
Task targets or project relative tasks to run. Supports multiple targets.
Additional arguments to pass through to the underlying command. Use
-- to separate from exec options.Options
Core options
Force enable CI mode. When enabled, moon will:
- Automatically sync the workspace
- Use CI-specific VCS revision detection
- Apply stricter task validation
Force run and bypass cache, ignore changed files, and skip affected checks. Useful for ensuring a clean run.
Run the pipeline and tasks interactively. This enables stdin for tasks that require user input.
Print a summary of all actions that were run in the pipeline. Accepts a log level (e.g.,
info, debug).Workflow options
Ignore “run in CI” task checks. By default, tasks configured with
runInCI will only run in CI environments.When a task fails, either bail the pipeline, or continue executing.Options:
bail- Stop execution immediately (default)continue- Continue running other tasks
Run the pipeline without sync and setup related actions. Skips workspace sync, toolchain setup, and dependency installation.
Affected options
These options control which tasks run based on changed files:Only run tasks if affected by changed files. Optionally accepts:
local- Compare against local changesremote- Compare against remote branch
Base branch, commit, or revision to compare against. Used to determine changed files.
Current branch, commit, or revision to compare with. Defaults to
HEAD.Include graph relations for affected checks, instead of just changed files. This will mark tasks as affected if their dependencies or dependents are affected.
Filter changed files based on a changed status (e.g.,
added, modified, deleted).Accept changed files from stdin for affected checks. Useful for piping file lists.
Graph options
These options control how task dependencies are resolved:Control the depth of downstream dependents to include.Options:
none- Don’t include dependents (default)direct- Include direct dependents onlydeep- Include all dependents recursively
--dependentsControl the depth of upstream dependencies to include.Options:
none- Don’t include dependenciesdirect- Include direct dependencies onlydeep- Include all dependencies recursively (default)
--dependenciesParallelism options
These options enable job partitioning for CI environments:Index of the current job (0-based). Used for splitting tasks across multiple CI jobs.
Total amount of jobs to run. Must be used with
--job.Examples
Run affected tests only
Run tests only for projects affected by changes since the main branch:Continue on failure
Run all tests even if some fail:Query-based execution
Run builds only for TypeScript libraries:Job partitioning for CI
Split test execution across 4 CI jobs:Interactive mode
Run a task that requires user input:Related commands
moon run- High-level command for running tasksmoon ci- Run tasks in CI modemoon check- Check tasks without running them
Related concepts
- Action graph - Understanding the execution pipeline
- Query language - Filtering tasks with MQL
- Targets - Task target syntax
- Affected - How affected detection works