chant release init
Sets up chant release in a project that has never used chant. It reads the project, writes a release block into chant.config.ts, writes the release workflow with release workflow, and lists what has to be set up by hand on the registries. An npm, pnpm or yarn workspace with more than one publishable package or VS Code extension gets a release train instead: each package released at its own version.
chant release init # a dry run: prints the block and whychant release init --yes # writes it| Flag | Description |
|---|---|
--yes | Write the config, the workflow and the goreleaser change. Without it nothing is written |
--dry-run | Write nothing, as without --yes. With --yes too, nothing is written. |
--force | Replace an existing release block, a release workflow file chant did not write, and a chant.workspace.json member in the way of a train’s |
--one-release | Release every package of a workspace together, at one label under one tag, rather than as a train |
--forge <forge> | The forge the workflow is written for. Default: the repository’s workflow directory (.github/workflows, .forgejo/workflows, .gitlab-ci.yml), else the forge origin names, else github |
--json | Print the plan as JSON: layout (train or one-release), release, reasons, notes, registry, workflow, goreleaser and next; a train adds workspace and members |
What it reads, from the directory it runs in, and what each sets:
| Found | Sets |
|---|---|
| The repository’s tags | release.tag: the prefix most version tags share, such as v{version} for v1.2.0 or cli-v{version} for cli-v0.4.1; v{version} when no tag names a version, or {path}/v{version} for a Go module in a subdirectory. A release of more than one package keeps v{version} unless its tags are v<version> already. release.legacyTags lists the prefixes the existing tags use, so release next and release changed read them as earlier releases |
ci.green in chant.workspace.json, or ci/green/ tags | release.green: "chant"; otherwise "forge-checks". A repository with no CI workflow is told that a cut refuses a commit with no checks |
package.json, with npm workspaces (a list or { packages }) or pnpm-workspace.yaml | With more than one package to publish, a release train. With one, or with --one-release: an npm target for every package not marked private, in dependency order, with access: "public" when a scoped package has no publishConfig.access. release.version stamps the same packages, with ranges: "exact" when one depends on another |
engines.vscode in a package.json | marketplace targets for the VS Code Marketplace and Open VSX (trusted publishing) from dist/<name>.vsix, and VSCE_PAT from the repository’s secrets in release.workflow.env |
Dockerfile or Containerfile, at the root or up to two directories down | A release.images entry each, and an oci target on the registry of the forge origin names: ghcr.io/<owner>/<repo>, registry.gitlab.com/<path>, or the Forgejo host |
.goreleaser.yaml (or .yml, or without the dot) | A release.artifacts entry { name: "goreleaser", goreleaser: {} }, so the cut runs goreleaser release --snapshot once and records the files it writes, and a forge release of the origin repository with generated notes that uploads them (assets: ["artifact:goreleaser"]). The notes are the forge’s own, or, when the config’s changelog.filters.exclude names commit types (^docs:, ^chore(\(.*\))?:), notes from commits with those types in exclude; a filter that names no commit type is reported, and the notes stay the forge’s own. The release workflow installs the goreleaser version chant pins. With --yes, a config with no snapshot section gets snapshot.version_template: "{{ .Env.CHANT_RELEASE_LABEL }}", so its snapshot build carries the release’s label; a config with its own snapshot section is told to set it. A goreleaser config whose dockers (with docker_manifests) or dockers_v2 build an image becomes a Dockerfile entry in release.images, with its platforms, its build arguments and labels ({{ .Version }} as {version}) and the archive build/images/<name>.tar, and an oci target with its repository, its manifest tags and its per-platform tags as platformTags. The plan says to remove those keys from the goreleaser config, names anything it could not carry (another template, a second repository, a one-stage Dockerfile that copies goreleaser’s binary), and other Dockerfiles stay out of release.images. A config that builds images with kos alone gets no image, and the plan says the release will not publish one |
Chart.yaml, at the root or up to three directories down, not inside another chart | A release.artifacts helm entry per chart (chart, or chart-<name> with more than one), so the cut packs each with the release’s version, and a helm target that pushes them to <registry>/charts/<name> on the registry of the forge origin names |
nfpm.yaml (or .yml, or with a leading dot) | A release.artifacts entry { name: "packages", nfpm: {} }, so the cut builds a deb and an rpm once, and artifact:packages among the assets of the forge release of the origin repository. A config whose version does not name ${CHANT_RELEASE_VERSION} is told to; the files it packs need a build entry before it, which the output says |
pyproject.toml with a [project] (or [tool.poetry]) name | A release.artifacts entry { name: "python", build: "python -m pip install build && python -m build", outputs: ["dist/*"] }, so the cut builds the sdist and wheel once and records them, and a pypi target for artifact:python with auth: "trusted-publishing" ("token" on Forgejo, with PYPI_TOKEN from the repository’s secrets in release.workflow.env). A pyproject.toml whose version is static is added to release.version.files; one whose version is dynamic is left to the build, which the output says |
Cargo.toml with a [package] name or a [workspace] | A cargo target, which publishes each crate that allows crates.io in dependency order. A Cargo.toml with a version in [package] or [workspace.package] is added to release.version.files; a workspace root without one is told to name its member crates. A crate with publish = false gets no target |
pom.xml | A release.artifacts entry maven whose build runs mvn -B -ntp deploy -DaltDeploymentRepository=local::file:./target/staging-deploy and zips the result to target/central-bundle.zip, and a maven target for artifact:maven. MAVEN_CENTRAL_USERNAME and MAVEN_CENTRAL_PASSWORD come from the repository’s secrets in release.workflow.env. The output says that the build must sign the files and set the version |
*.csproj files that pack | A release.artifacts entry nuget that runs dotnet pack <project> -c Release -o dist/nuget -p:Version="$CHANT_RELEASE_LABEL" for each, and a nuget target for artifact:nuget with auth: "trusted-publishing" and NUGET_USER from the repository’s secrets ("token" on Forgejo, with NUGET_API_KEY). A project with <IsPackable>false</IsPackable> is left out |
A *.gemspec | A release.artifacts entry gem that runs gem build into dist/gem/, and a rubygems target for artifact:gem with auth: "trusted-publishing" on GitHub ("token" elsewhere, with GEM_HOST_API_KEY). The output says that the gemspec’s version is published as it sets it |
go.mod | Nothing to publish: the release’s tag is what the Go module proxy reads |
A workflow under .github/workflows that runs npm publish (or pnpm publish, yarn publish, yarn npm publish) and that chant did not write | release.workflow.file set to it, when the release publishes to npm and it is the only one. An npm trusted publisher names the workflow file a package publishes from, so the release workflow replaces that file and the trusted publisher keeps working; nothing else is left that publishes. A project below the repository root adopts only a workflow that names its directory. With several such workflows, init writes chant-release.yml and says to set release.workflow.file to the one the trusted publisher names |
release.workflow is trigger: "dispatch", so a release is one run started by hand with its label. With pnpm or yarn it installs with corepack enable and the lockfile’s tool, and builds with that tool when the root package.json has a build script; with npm and no package-lock.json it installs with npm install. A package.json that does not depend on @intentius/chant runs chant in the jobs as npx --yes @intentius/chant@<version>, the version that wrote the config.
A project with no chant.config.ts gets one holding the block alone. Reading a TypeScript config needs tsx, an optional dependency of chant: when it is not installed, a project with no config gets a chant.config.json holding the block instead, which init, the release workflow’s jobs and every other command read without it, and a project whose chant.config.ts is already there is refused with release-init-tsx-missing before anything is written, with the install command (npm i -D tsx). The same holds for each member config of a train. One that has a config gets the block added to the object its default export names: export default { ... }, export default defineConfig({ ... }), or export default config with const config = { ... }. A chant.config.json is rewritten with the block added. A config that already has a release block is refused with release-init-release-exists unless --force, and one whose default export is not an object literal with release-init-config-unreadable; both print the block to add by hand. A release workflow file that chant did not generate is refused with release-init-workflow-exists unless --force, except an npm publish workflow that init adopts as release.workflow.file: --yes replaces that one, and the dry run says it will.
The output ends with the steps to take by hand, such as an npm trusted publisher that names the workflow file (chant-release.yml, or the adopted file, whose existing trusted publisher stays) with npm dist-tag allowed, a PyPI trusted publisher that names the same file (on GitLab, the top-level pipeline file .gitlab-ci.yml), crates.io trusted publishing or a CARGO_REGISTRY_TOKEN (a crate’s first version needs the token), the Maven Central namespace and user token, a nuget.org trusted publishing policy, a RubyGems.org trusted publisher, the Open VSX trusted publisher, VSCE_PAT, a GHCR package’s visibility, and on GitLab the include and CHANT_RELEASE_TOKEN. Then it prints the commands to commit and push, to run release doctor once those steps are done, and to start the first release. When the repository has version tags that release.tag or release.legacyTags matches, that is the label auto (gh workflow run chant-release.yml -f label=auto), which takes the label from the commits since the newest of those tags with release next. Otherwise it is a label: a patch after the newest version tag, or 0.1.0. Each later release can be started with auto, which then reads the previous release from chant’s ledger. The dispatched workflow runs release doctor in its cut job too, before the cut.
Init turns on no security group. A train’s new chant.workspace.json has no security key, and an existing one is left as it is. When the workspace does not opt into supply-chain, the plan’s notes say what adding it would do: scan every image and SBOM before anything is pushed, sign with Sigstore, and require OIDC provenance and an SBOM on every target, so each npm package must then carry one. See Require SBOMs and provenance.
A workspace of several packages
Section titled “A workspace of several packages”When the workspaces hold more than one package not marked private (npm packages and VS Code extensions), init sets up a release train: each package is a release member with its own labels and tags, and one run releases every package that changed.
$ chant release initDry run: a release train of 2 packages, each released at its own versionIt writes:
| File | Holds |
|---|---|
chant.workspace.json | A chant member per package, named after the package without its scope (@acme/core is core), and one per directory that holds what no package’s directory does (see Images, charts, Python and Rust). An existing file keeps what it has and gets the members added; an entry with the same name or directory that is not that member is refused with release-init-member-exists unless --force |
<package>/chant.config.ts | The member’s release: version: { packages: ["."] }, with ranges: "train" when it depends on another package of the train, an npm target for the package (access: "public" for a scoped package with no publishConfig.access), or for a VS Code extension the two marketplace targets from dist/<name>.vsix, the gate, and tag: "{member}/v{version}". A package whose own tags are already in the repository, such as web-v0.3.0, keeps that prefix, and one whose prefix no template can hold (@acme/core@1.2.0) has it in legacyTags |
release/<name>/chant.config.ts | A member of its own for a directory no package holds, such as the repository root (see below) |
chant.config.ts at the root | release.train: { env: "npm" }, the gate, and release.workflow: { trigger: "dispatch" }, with VSCE_PAT from the repository’s secrets in its env when a member is a VS Code extension. Tags that name releases of every package together (v1.4.0) go in release.legacyTags, with first: "together", so the first train starts every package one past the highest version any has |
| The release workflow | The train workflow release workflow renders: started by hand with levels, it runs workspace train cut and publishes the train |
Each config is refused with release-init-release-exists when it already has a release block, unless --force. The registry steps name a trusted publisher on npmjs.com for each package, all naming the same workflow file, and a package that is not on npm yet needs its first version published by hand from its directory before it has settings; the train labels its next version past that one. The output also says when a package has neither files in its package.json nor an .npmignore, since npm then packs the member’s chant.config.ts with it. The steps that follow:
git add chant.workspace.json chant.config.ts packages/core/chant.config.ts packages/web/chant.config.ts .github/workflows/chant-release.yml && git commit -m "ci: release with chant" && git pushchant workspace train cut npm # the first train's plan; nothing is cut without --yesgh workflow run chant-release.yml -f levels=autolevels=auto takes each package’s level from its commits and intent files since its last release; minor gives every package one, and web=major names one.
A workspace gets one release under one label instead, with a note saying why, when a train from init would leave part of it out: the root package.json is published too, or the project has a goreleaser config, an nfpm config, a pom.xml, a .csproj or a .gemspec at its root. goreleaser and nfpm read their paths from the directory they run in, and a train member runs them in its own; such a train can be set up by hand with the config in the member’s directory (see Releasing a monorepo). --one-release asks for the one release on any workspace. On GitLab the train is written to .gitlab/chant-release.yml, the trusted publishers name .gitlab-ci.yml, and the first train starts from a pipeline run with CHANT_RELEASE_LEVELS=auto.
Images, charts, Python and Rust
Section titled “Images, charts, Python and Rust”A Dockerfile, a Helm chart, a Python package or a Rust crate belongs to the member whose directory holds its file. What no member’s directory holds, such as the root’s Dockerfile, pyproject.toml or Cargo.toml, a chart under charts/, or a Dockerfile in a private package, gets a member of its own at release/<name>, one per directory. That member’s entries name the files with ../.., and its release.sources names the directory, so release changed releases it when those files change. The plan prints this rule among its reasons.
| Found | The member gets |
|---|---|
| A Dockerfile | A release.images entry and an oci target on the forge’s registry, as for one release. In a package npm publishes, the archive is build/images/<name>.tar, outside the dist npm packs. At the root: { name, dockerfile: "../../Dockerfile", context: "../.." } in release/<name>, named after the repository |
A Chart.yaml | A helm entry in release.artifacts (chart, or chart-<name> for a member with several) and a helm target that pushes to <registry>/charts. In a package npm publishes, the archive goes to build/. Under charts/api: chart: "../../charts/api" in release/api |
pyproject.toml with a name | In release/<name>, named after the Python package: a python entry whose build is python -m pip install build && python -m build --outdir dist ../.., a pypi target for it, and version.files: ["../../pyproject.toml"] when its version is static |
Cargo.toml with a [package] name or a [workspace] | In release/<name>, named after the crate: a cargo target with manifest: "../../Cargo.toml", and version.files: ["../../Cargo.toml"] when it has a version |
A root Dockerfile beside a root pyproject.toml goes to the Python package’s member, since both come from the root. release.sources: ["../.."] counts every path in the repository, so such a member is in every train with a change; narrow it to the directories it is built from. The registry steps are the ones a single release prints for the same targets: the PyPI trusted publisher, crates.io trusted publishing or CARGO_REGISTRY_TOKEN, the GHCR package’s visibility, VSCE_PAT and the Open VSX trusted publisher.