moon ci command.
How it works
Theci command does all the heavy lifting necessary for effectively running jobs. It achieves this by automatically running the following steps:
- Determines changed files by comparing the current HEAD against a base.
- Determines all targets that need to run based on changed files.
- Additionally runs affected targets dependencies and dependents.
- Generates an action and dependency graph.
- Installs the toolchain and applicable dependencies.
- Runs all actions within the graph using a thread pool.
- Displays stats about all passing, failed, and invalid actions.
Prerequisites
Before setting up moon in CI, ensure you have:- A moon workspace configured in your repository
- Tasks configured with the
runInCIoption (enabled by default) - Your VCS provider configured in
.moon/workspace.yml
Configuring tasks
By default, all tasks run in CI, as you should always be building, linting, typechecking, testing, so on and so forth. However, this isn’t always true, so this can be disabled on a per-task basis through therunInCI option.
moon.yml
Integrating with CI providers
Choose your CI provider
The following examples can be referenced for setting up moon and its CI workflow in popular providers. For GitHub, we’re using our
setup-toolchain action to install moon. For other providers, we assume moon is an npm dependency and must be installed with Node.js.Choosing targets
By defaultmoon ci will run all tasks from all projects that are affected by changed files and have the runInCI task option enabled. This is a great catch-all solution, but may not vibe with your workflow or requirements.
If you’d prefer more control, you can pass a list of targets to moon ci, instead of moon attempting to detect them. When providing targets, moon ci will still only run them if affected by changed files, but will still filter with the runInCI option.
Comparing revisions
By default the command will attempt to detect the base and head revisions automatically based on the current CI provider. If nothing was detected, this will fallback to the configuredvcs.defaultBranch for the base revision, and HEAD for the head revision.
These values can be customized with the --base and --head command line options, or the MOON_BASE and MOON_HEAD environment variables, which takes highest precedence.
Parallelizing tasks
If your CI environment supports sharding across multiple jobs, then you can utilize moon’s built in parallelism by passing--job-total and --job options. The --job-total option is an integer of the total number of jobs available, and --job is the current index (0 based) amongst the total.
When these options are passed, moon will only run affected targets based on the current job slice.
Caching artifacts
When a CI pipeline reaches a certain scale, its run times increase, tasks are unnecessarily ran, and build artifacts are not shared. To combat this, we support remote caching, a mechanism where we store build artifacts in the cloud, and sync these artifacts to machines on demand.Manual persistence
If you’d prefer to not use remote caching at this time, you can cache artifacts yourself, by persisting the.moon/cache/{hashes,outputs} directories. All other files and folders in .moon/cache should not be persisted, as they are not safe/portable across machines.
However, because tasks can generate a different hash each run, you’ll need to manually invalidate your cache. Blindly storing the hashes and outputs directories without a mechanism to invalidate will simply not work, as the contents will drastically change between CI runs. This is the primary reason why the remote caching service exists.
Reporting run results
If you’re using GitHub Actions as your CI provider, we suggest using ourmoonrepo/run-report-action. This action will report the results of a moon ci run to a pull request as a comment and workflow summary.
.github/workflows/ci.yml
Community offerings
The following GitHub actions are provided by the community:appthrust/moon-ci-retrospect- Displays the results of amoon cirun in a more readable fashion.kymckay/moon-ci-booster- Displays failingmoon citasks as comments with error logs directly on your pull request.