Skip to main content

moon v1.24 - Task mutexes, auto-detect revisions, project dependents, and more!

· 3 min read
Miles Johnson
Founder, developer

This is a light release that focused solely on requests and improvements from the community.

Exclusive resources with task mutexes

Some tasks may require exclusive access to a resource, like a database, file, or network connection, but other parallel running tasks may also require access to the same resource. When both of these tasks run, they may conflict with each other, causing one or both to fail. This wasn't an easy problem to solve in moon, until now!

Thanks to Andrés Correa Casablanca for the idea and implementation, tasks now support a new option called mutex. This option allows you to specify a unique name (across the entire workspace) for the mutex, which will be used to lock the task from running if another task with the same mutex name is already running.

Take the following for example:

# server/moon.yml
tasks:
build:
command: 'build-server'
options:
mutex: 'app'

# client/moon.yml
tasks:
build:
command: 'build-client'
options:
mutex: 'app'

When moon run :build or moon ci is ran, both tasks will be parallelized within our pipeline, but only one of them will run at a time. If the server task is running, the client task will wait until the server task is complete. This ensures that both tasks don't conflict with each other.

This could technically be solved through task deps, but with a mutex, it allows you to decouple project and task dependencies, and instead focus on a virtual resource that is being locked.

Auto-detect base/head for moon ci

We've updated moon ci to try and detect the base and head revisions automatically when running in a popular CI provider, like GitLab and Jenkins. For the base revision, we'll use the base/target commit SHA or target branch, while the head revision will use the source commit SHA or HEAD. This is great for pull requests and forks!

With that said, these values can be overwritten with environment variables, or command line arguments. Below is the order of precedence:

  • MOON_BASE / MOON_HEAD environment variables
  • --base / --head command line arguments
  • base_revision / head_revision via CI provider
  • vcs.defaultBranch setting / HEAD literal value

This functionality is provided by the ci_env Rust crate. Please refer to that crate for supported providers, and which of them support revision detection (primarily the base_revision and head_revision fields).

Include dependents for focused project graph

When running moon project-graph <id>, we visualize a graph of the focused project and all of its dependencies (other projects it depends on). However, if you wanted to also visualize dependents (other projects that depend on the focused project), this was currently not possible.

We felt this information could be useful, so we've added a --dependents flattenDiagnosticMessageText, which will include direct dependents in the graph.

$ moon project-graph server --dependents

We also felt dependent information can be useful when querying projects, so have also added support for the --dependents flag to the moon query projects command.

$ moon query projects --affected --dependents

Other changes

View the official release for a full list of changes.

  • Added an experimental moon templates command, that lists all available codegen templates.
  • Added a runner.autoCleanCache setting to .moon/workspace.yml, allowing the post-run clean mechanism to be controlled.
  • Updated moon generate with better argument to variable handling.
  • Updated action graph and project graph visualization to be more readable.
  • Updated root-level tasks to have no inputs by default, instead of **/*.