Open source usage
Although moon was designed for large monorepos, it can also be used for open source projects, especially when coupled with our built-in continuous integration support.
However, a pain point with moon is that it only supports a single Node.js version within its
toolchain, but open source projects typically need to run checks against
multiple Node.js versions! To mitigate this problem, we built the
moonrepo/tool-version-action
GitHub Action,
which will override the Node.js version configured in the workspace.
This action works best when paired with a matrix, as demonstrated below!
name: 'Pipeline'
on:
push:
branches:
- 'master'
pull_request:
jobs:
ci:
name: 'CI'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest']
node-version: [14, 16, 18]
steps:
# Checkout repository
- uses: 'actions/checkout@v3'
with:
fetch-depth: 0
# Install Node.js so we can install dependencies
- uses: 'actions/setup-node@v3'
with:
cache: 'yarn'
# Set Node.js version to use in moon
- uses: 'moonrepo/tool-version-action@v1'
with:
node: ${{ matrix.node-version }}
# Install dependencies
- run: 'yarn install --immutable'
# Run moon and affected tasks
- run: 'yarn moon ci'
Currently, we only have a solution for GitHub actions, but the same mechanism can be applied to
other CI environments by setting the MOON_NODE_VERSION
environment variable.
Reporting run results
We also suggest using our
moonrepo/run-report-action
GitHub
action. This action will report the results of a moon ci
run to a pull request
as a comment and workflow summary.
# ...
jobs:
ci:
name: 'CI'
runs-on: 'ubuntu-latest'
steps:
# ...
- run: 'yarn moon ci'
- uses: 'moonrepo/run-report-action@v1'
if: success() || failure()
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
The report looks something like the following:
