Skip to content

Release a Monorepo

llms.txt lists every page for an agent
Optional: hand this page to your coding agentThe steps work by hand too.
Show the whole prompt
Read https://intentius.io/chant/guide/release-a-monorepo/.
Set up one release member per publishable package of this repository's workspaces, add release.train and release.workflow to the workspace root's chant.config.ts, and render the workflow with chant release workflow, in a pull request.
Run `npx chant workspace train cut <env>` without `--yes` and show me what it prints; do not run it with `--yes`, push a tag, or run `chant workspace train publish` yourself.
Never deploy to a real cloud account or shared environment (with `chant run`, `chant components` or a platform's own CLI), approve (a pull request review, `chant approve` or `chant run approve`), override a policy denial (`chant approve policy-override`), or merge; never cut or publish a release (`chant release cut --yes`, `chant workspace train cut --yes`, `chant release publish` or `chant workspace train publish`), push or delete a `ci/*` tag (`chant ci tick` pushes them), or change the value of an existing flag; never touch `.chant/allowed_signers` or `chant/lifecycle`.

A monorepo whose packages ship at their own versions releases each package separately and publishes the ones that changed together. In chant each package is a release member with its own ledger, labels and tags, and one run cuts every member that changed and records them as a release train. The train is what publishes: each package goes out in dependency order, and each range on a sibling names the version the train gives that sibling.

In an npm, pnpm or yarn workspace, chant release init writes everything this page describes: chant.workspace.json with a member per publishable package, each package’s chant.config.ts, the root’s release.train, and the workflow. It is a dry run until --yes, and it replaces no release block without --force:

Terminal window
chant release init # prints the files and why
chant release init --yes # writes them, and renders the workflow

The sections below show what it writes, for setting it up by hand or changing it later.

Give every publishable package a chant.config.ts of its own and declare each package directory as a chant member of the workspace:

chant.workspace.json
{
"name": "acme",
"schema": 1,
"members": [
{ "name": "core", "dir": "packages/core", "kind": "chant" },
{ "name": "web", "dir": "packages/web", "kind": "chant" }
]
}
packages/web/chant.config.ts
export default {
release: {
version: { packages: ["."], ranges: "train" },
publish: [{ type: "npm", packages: ["."] }],
},
};

release.version stamps the release’s label into the package’s package.json when it is built, so the committed version never moves (see The label as the package version). ranges: "train" sets each workspace dependency’s range to ^ and the label the train gives that dependency. A package with no environments is cut as an artifact release, gated on its forge checks unless the workspace declares green commits.

The packages can also stay where they are, with the release members in a nested workspace of their own (release/<member>, each naming ../../packages/<name>). A release member then takes the name of the outer member that owns the package’s directory, so chant release changed maps a change to the package to it.

Declare the train in the workspace root’s chant.config.ts, with the workflow that runs it:

// chant.config.ts at the workspace root
export default {
release: {
train: { env: "npm" },
workflow: { trigger: "dispatch" },
},
};

Then render the workflow:

Terminal window
chant release workflow

The file it writes starts by hand with the input levels. The default, auto, lets each package’s conventional commits and intent files decide its level; minor gives every package one, and web=major names one. The run picks the newest green commit, and chant workspace train cut takes it from there:

  • chant release changed lists the packages that changed since their last release, and the packages they need that changed too, in publish order.
  • Each package’s label is past every version it already has: its ledger, its tags, its package.json, and what npm already holds. A label is never one the registry has.
  • Each package is cut at that commit, the train is recorded, and the package tags and release-train/npm/<id> go out in one push.

The publish job then stamps every package the train cut (chant workspace train prepare), builds the workspace packages they build against once, and runs chant workspace train publish, which publishes the packages in dependency layers, waiting for each layer to resolve on npm before the next. A package the train pins at an earlier release must already be on npm. Each package’s release.verify commands run after every package has staged and before any reveals, and stage: true keeps every package under next until the whole train has staged.

A train that was cut and did not publish, because a publish job stopped part way or never ran, is finished from the same workflow: dispatch it with the input train set to the train’s id, which chant workspace train list npm prints. That run skips the gate and the cut, checks out the train’s commit, and publishes that train, resuming from what the earlier run staged or revealed. Nothing is cut again and no tag is pushed:

Terminal window
gh workflow run publish.yml -f train=<id>

A member can build more than an npm package at its cut: container images (release.images) or files such as binaries and archives (release.artifacts, goreleaser included). Declare them in that member’s chant.config.ts, beside its targets:

packages/cli/chant.config.ts
export default {
release: {
version: { packages: ["."], ranges: "train" },
artifacts: [{ name: "cli", goreleaser: {} }],
publish: [
{ type: "npm", packages: ["."] },
{ type: "forge", forge: "github", repo: "acme/mono", assets: ["artifact:cli"] },
],
},
};

The cut job builds them once, in that member’s cut, and hands them to the publish job, which checks every file against the digests the release recorded before anything publishes. A publish with no cut job before it (a train tag pushed from a workstation, or a dispatched train) builds them again from the train’s commit and publishes only when they come out the same. See A release train for what the jobs run.

An image or chart built from files outside every package, such as the repository root’s Dockerfile, can have a member of its own, such as release/web-image, whose entry names them with .. (dockerfile: "../../Dockerfile", context: "../..") and whose release.sources: ["../.."] makes release changed release it when they change. release init sets this up.

Files that need another runner, such as a macOS or Windows binary, come from the member’s own release.workflow.builds, with a release.artifacts entry whose builtBy names the jobs. The workflow’s gate plans the train first, so each build job runs with the label its member is about to be cut at, and the cut refuses a train whose labels changed since. Such a train publishes in the run that cut it. A member’s builds on other runners shows the config.

chant release workflow renders the train for GitLab as jobs of .gitlab/chant-release.yml, which .gitlab-ci.yml includes. Store a project access token with write_repository as the masked CI/CD variable CHANT_RELEASE_TOKEN, since a job token cannot push the train’s tags. Start a train by running a pipeline with CHANT_RELEASE_LEVELS=auto, and finish one that did not publish with CHANT_RELEASE_TRAIN=<id>. A release train on GitLab has the details.

Plan the train from your machine; nothing is cut, recorded or pushed without --yes:

Terminal window
$ chant workspace train cut npm
Release train for npm from 9deea68907d3:
core 0.1.1 needed-by web; patch from default; floor 0.1.0
web 0.1.1 paths-changed; patch from default; floor 0.1.0
Dry run: nothing was cut, recorded, tagged or pushed. Run again with --yes to cut the train.

chant workspace train cut npm --yes from a workstation cuts and pushes the same train, and the workflow’s publish job runs on its release-train/npm/* tag.

A monorepo that released every package at one version until now has each package’s history at that version. first: "together" cuts the first train at one label for every member, one past the highest version any package has, so the packages start from the same place; every later train labels each one on its own. release.legacyTags names the old tags (v, release/), so release changed reads the last shared release as each member’s last release.

release: {
train: { env: "npm", first: "together" },
legacyTags: ["v"],
},

release.train.check runs commands once the labels are known and before anything is cut, with the plan in CHANT_TRAIN_PLAN, such as a check that a constant in the source names the version being released.

chant