Skip to content

Latest commit

 

History

History
457 lines (365 loc) · 25.4 KB

prerelease.md

File metadata and controls

457 lines (365 loc) · 25.4 KB

Pre-releases: iterating an unreleased version against downstream consumers

Testing an unreleased change against a real downstream project used to require cutting a real release on npm / PyPI / NuGet / Maven Central. All four registries are immutable: the version number is spent the moment it ships, latest moves, and every consumer on a caret range can pick it up. That is an expensive way to answer "does this change work in a real app?" — and it is the reason 0.21.2 had to be cut within an hour of 0.21.1.

This page describes the alternative. Publish a pre-release to a separate registry, consume it from a downstream project, iterate, and switch that project back to public releases with a verified one-command revert.

Registry one Gitea instance serving npm, PyPI, NuGet, Maven and Cargo — the address is configuration (MO_REGISTRY_BASE), never a committed default; see §7
Reads anonymous — a consumer needs the URL and the owner, no account and no token
Writes token only, in gitignored local config, never in a committed file
Publisher bun run prerelease:publish (scripts/prerelease.mjs)
Consumer tools/prerelease/prerelease-link.sh link / unlink
Guard (consumer) tools/prerelease/detect-prerelease-pins.sh
Guard (this repo) scripts/check-no-prerelease-versions.sh

1. The version scheme

One canonical internal string, normalized per ecosystem in exactly one place (const V in scripts/prerelease.mjs):

canonical npm PyPI NuGet Maven
form <base>-rc.<N> 0.24.0-rc.3 0.24.0rc3 0.24.0-rc.3 7.24.0-rc.3
why SemVer2 verbatim PEP 440 canonical form SemVer2 verbatim same minor.patch, major is the npm major plus 7 (1.1.0-rc.2 is 8.1.0-rc.2)

<base> is the in-development version: the lowest CHANGELOG.md ## [x.y.z] section that is not released yet — the repository's own declaration of what is being worked on. "Released" is read from where a release leaves its mark, public npm's latest for the CLI and the v<x.y.z> tags, never from package.json: release preparation bumps package.json first, and reading it as released numbered every candidate cut during release prep one minor too high (1.2.0-rc.3 while 1.1.0 was the work in hand). The base falls back to the next minor only when every section is released; --base overrides, but never to skip an unpublished section (the run refuses), and the run prints which source it used. Deriving it as minor+1 unconditionally was wrong on every PATCH line — 0.23.3 after 0.23.2 is an ordinary outcome, and the tool would say 0.24.0 while the changelog said 0.23.3, so every invocation needed --base to be talked out of it. One forgotten flag burns a version number permanently.

<N> is a monotonic iteration counter, derived from what the registry already holds across all five ecosystems so that --only npm today and --only csharp tomorrow cannot collide.

Why a counter and not a commit sha. npm strips SemVer build metadata: 0.24.0-rc.1+aaa and 0.24.0-rc.1+bbb compare equal, so the second publish is refused as a duplicate. The sha still travels where it is useful — the C# packages carry it in AssemblyInformationalVersion via Source Link — but it cannot be the thing that makes two iterations distinct.

Why not one mutable -dev version. Deleting and re-pushing the same version is possible, and it silently serves the consumer stale bytes: with a lockfile and a warm client cache, npm install resolves the old tarball with no error and no warning. An immutable per-iteration version makes "did my fix actually reach the consumer?" answerable by reading a version number.

-rc.N sorts correctly everywhere, including numerically in Maven (rc.2 before rc.10), and it sorts below the eventual release. Neither ^0.23.2 nor ^0.24.0 matches 0.24.0-rc.1, so a pre-release can never be picked up by an existing range.

A burned version number can never come back

npm versions are permanent in a stronger sense than "you should not republish": once anything depends on a version, npm unpublish is refused (E405), and deprecating it does not free the number. @metaobjectsdev/metadata@0.24.0-rc.1 is burned exactly that way — published to public npm by accident while this design was being validated, and now unremovable. Nothing else in the lockstep set carries it, which is what makes it dangerous: a lockstep RC at 0.24.0-rc.1 would publish thirteen packages successfully and then fail irreversibly on the fourteenth.

Two places now handle that instead of discovering it late:

  • bun run prerelease:publish picks its iteration number by skipping every number already taken on the pre-release registry or on public npm, for any package in the set. With 0.24.0-rc.1 burned and rc.1–rc.3 used privately, it selects rc.4. An explicit --iter that lands on a burned number still works — the pre-release registry is a separate namespace — but warns that the number can never be promoted.
  • bun run release checks the target version against every package in the lockstep set before it publishes anything. It previously checked only @metaobjectsdev/cli, which would not have seen this at all.

Do not use -next.N. Maven treats next as an unknown qualifier, which ranks above the plain release: 7.24.0-next.3 sorts newer than 7.24.0.


2. Publishing

One-time, on the publishing machine:

cp tools/prerelease/registry.env.example tools/prerelease/registry.env
# fill in MO_REGISTRY_OWNER and MO_REGISTRY_TOKEN — the file is gitignored

Then:

bun run prerelease:publish                      # next iteration, npm + Maven (the default scope)
bun run prerelease:publish --only python,csharp # pick ports
bun run prerelease:publish --only all           # all five (npm, python, csharp, java, rust)
bun run prerelease:publish --iter 7             # pin the iteration number
bun run prerelease:publish --base 0.25.0        # target a different in-development version
bun run prerelease:publish --dry-run            # build + normalize + gate, publish nothing

Version declarations are edited in place and always restored on exit; the script refuses to start if any of them is already dirty.

The publish-target gate

The registry is a public HTTPS endpoint. "It is only bound to loopback" is not the safety model and never was the durable one. These are:

  1. The target must equal the configured registry (or be loopback) — an equality test, not a hostname pattern.
  2. An independent deny-list of the public registries (registry.npmjs.org, pypi.org, api.nuget.org, central.sonatype.com, …). Two checks that fail differently beat one check trusted twice.
  3. For npm, bun publish --dry-run is parsed and its reported registry compared to the expected one. This is not paranoia: bun ignores npm_config_userconfig, and during this design's validation it silently fell back to the user-level ~/.npmrc and published a pre-release to the public registry. bun is not taken at its word anywhere here.
  4. HOME is redirected to a scratch directory holding only the pre-release .npmrc, so a fall-back has no credential to publish with even if it happens.
  5. Maven deploys with an explicit -DaltDeploymentRepository and never -Prelease — this repo declares distributionManagement only inside the release profile, so a bare mvn deploy has no target at all. Its local repository is a scratch directory, so a pre-release never lands in the ~/.m2 that ordinary builds resolve from.

2a. Staged candidates

A release that arrives as a series of candidates (1.3.0-rc.1, -rc.2, …), each run against the adopter estates before the next is cut, uses this tool and not bun run release. release.mjs always publishes to public npm latest, commits the version and dates the CHANGELOG; the private-registry path does none of that, and it does not run the maintenance-branch check that gates the final cut (docs/RELEASING.md, Step 0).

A full candidate, every registry:

bun run prerelease:candidate          # = bun run prerelease:publish --only all

The default scope is npm and Maven only, so a Python, C# or Rust estate gets nothing from a bare prerelease:publish. Use the full command for any candidate an estate in those ports will run; name a narrower --only only for a fix you are iterating on one port.

The log. Every run that starts a publish appends one row to tools/prerelease/candidates.md: the candidate, the full HEAD it was built from (shortened to 12 characters, +dirty when tracked files outside the version declarations were modified), the UTC date, and the ecosystems published. A run that stops partway still writes its row: a registry whose publish began but did not finish reads <ecosystem> (cut short), because its candidate number is taken there, and a registry the run was asked for but never reached reads stopped before <ecosystem>. A dry run writes no row. It names ecosystems, never the registry host. The script writes the row after it has restored the version files, so the row is the only change the run leaves; commit it, so the repository records what each candidate was built from. Build a candidate from a commit that is already pushed: a sha nobody can fetch is not a record.

The upgrade list is checked first. Before it edits or publishes anything, the run checks, for each port it publishes, that every public name removed since the last release is named in the CHANGELOG upgrade list (scripts/check-export-surface.mjs; how it matches names is in scripts/export-surface/README.md). A name the list does not give stops the run. The C# and Java checks build those ports first.

The notes travel with the candidate. An adopter tests a candidate against its upgrade list, so each candidate carries the CHANGELOG it was built with: every section above the last release's own heading, then a link to the full history at that release's tag. Every npm package has it as CHANGELOG.md (node_modules/@metaobjectsdev/cli/CHANGELOG.md); every NuGet package has it at the package root, with release notes that point there; the PyPI sdist has it at its root and the wheel installs it as metaobjects/CHANGELOG.md; every Maven jar has it as META-INF/CHANGELOG.md; and every Cargo crate has it beside its Cargo.toml. The copy exists only while the candidate is built and is removed when the run ends. Never read the notes from a checkout of main or from the last release: rc.4's packages carried none, and one estate filed items as undocumented against a stale copy.

Estate runs. What an estate does with a candidate is tools/prerelease/estate-run.md, with tools/prerelease/estate-run.sh for the mechanical part.

Rust

The four crates (metaobjects, metaobjects-render, metaobjects-codegen, metaobjects-cli) publish to the registry's Cargo index with the other ports: --only rust (or its alias --only cargo) alone, and --only all as part of a full candidate, after the other ecosystems. They publish in the order scripts/release.mjs uses for crates.io (each crate after the ones it depends on), at the candidate's SemVer form, 1.3.0-rc.N. The run edits the manifests for the publish and restores them on exit: it adds registry = "mo-prerelease" to each sibling-crate dependency, so a published crate's siblings resolve from the private registry and never from crates.io or git. The publish names the registry explicitly, the crates.io token variable is removed from cargo's environment, and a dry run of the whole workspace must report the private index before anything is uploaded. Before any ecosystem publishes, the run also refuses a candidate number the registry already holds for any crate.

Add the registry to the consumer's .cargo/config.toml (reads are anonymous; <registry-base> and <owner> are the same values registry.env carries):

[registries.mo-prerelease]
index = "sparse+<registry-base>/api/packages/<owner>/cargo/"
[dependencies]
metaobjects = { version = "=1.3.0-rc.6", registry = "mo-prerelease" }
cargo install metaobjects-cli --version 1.3.0-rc.6 --registry mo-prerelease

A crate's other dependencies still come from crates.io; only the metaobjects* crates come from the private registry. Cargo resolves a candidate only for an exact requirement such as =1.3.0-rc.6.

Fallback: pin the commit. A candidate published before the crates joined it (1.3.0-rc.5 and earlier) has no crates on the registry, and the commit its row in the log names still works:

[dependencies]
metaobjects = { git = "https://github.com/metaobjectsdev/metaobjects", rev = "<commit from candidates.md>" }
cargo install --git https://github.com/metaobjectsdev/metaobjects --rev <commit> metaobjects-cli

Cargo finds each crate by name inside the repository, so the same rev serves metaobjects, metaobjects-codegen and metaobjects-cli. Use the full 40-character sha for rev (the log shortens it; git rev-parse <short> expands it in a clone). cargo meta --version prints only the crate version, so read the commit back from Cargo.lock's source line (it ends in #<sha>), the way the other ports read their resolved versions.


3. Consuming — one command in each direction

# from the consumer project root
tools/prerelease/prerelease-link.sh link --version 0.24.0-rc.3
tools/prerelease/prerelease-link.sh check
tools/prerelease/prerelease-link.sh unlink --to 0.23.2

link detects which ecosystems the project uses, at any depth, and configures only those: every independent Maven build (a pom.xml with none above it; modules inherit) and every Python project (pyproject.toml) gets its own block, so a repository with one project per port under ports/ needs one link, and every pom.xml is repinned, modules included. The .NET local tool manifest (.config/dotnet-tools.json) is repinned with the packages, so dotnet meta moves to the candidate too. Configuration is scoped to the vendor namespaces (@metaobjectsdev/*, metaobjects, MetaObjects*, com.metaobjects). Everything else keeps resolving from the public registry — verified: zod and pyyaml still come from npmjs.org and pypi.org while the vendor packages come from the pre-release registry.

link does not configure Cargo: a Rust consumer adds the registry by hand, as §2a Rust shows.

Everything it writes is delimited by managed markers, so unlink removes exactly what link added:

ecosystem what link writes mechanism
npm .npmrc scope line @metaobjectsdev:registry=…
Python pyproject.toml block [[tool.uv.index]] explicit = true + [tool.uv.sources] — real per-package index pinning
NuGet NuGet.config a second source plus packageSourceMapping limiting it to MetaObjects*
Maven pom.xml <repositories> plus .mvn/settings.xml when the registry is plain http (see below)

Files that are not normally tracked (.npmrc, NuGet.config, .mvn/*) are also added to the project's .git/info/exclude, which is local and not committed — in a linked git worktree this is the shared exclude file in the clone's common dir (git has no per-worktree exclude), so the paths link adds there live inside their own managed block too: unlink removes exactly that block, never a line a user added to the file by hand, and a repeated link does not duplicate it. An entry that another worktree of the same clone, or another project linked in the same worktree, still needs stays until that one is unlinked too. A clone linked by an earlier version of the script holds those entries as bare lines outside any block, which unlink cannot tell from a line a user added. link and unlink name such lines and print the one command that removes them, and leave them in place; link does not add a second copy inside the block while one is there. Run that command once no worktree of the clone is linked, after taking out of it any line you added yourself. Files that are tracked by definition (pyproject.toml, pom.xml) get a loud warning instead — there is no way to make an edit to a tracked file uncommittable, which is precisely why the detector in §5 exists.

After link:

npm     rm -f package-lock.json && npm install
python  uv lock && uv sync
nuget   dotnet restore --force-evaluate --no-cache
maven   mvn -U compile

NuGet's two flags are both required. NuGet caches the service index, so a plain dotnet restore — and even --force-evaluate on its own — will happily keep resolving the previous iteration of a floating version.

Maven blocks plain-http repositories since 3.8.1, via a built-in maven-default-http-blocker mirror, and the error names the blocker rather than the cause. Against an http:// registry link writes .mvn/settings.xml + .mvn/maven.config using -gs, which merges with your own ~/.m2/settings.xml rather than replacing it. unlink deletes both — leaving them behind would keep a security default suspended for that project forever. The project registry is HTTPS, so this path does not trigger for it.

Outside collaborators

Reads are anonymous, so someone outside the project needs no account and no token. Give them the two scripts (or a checkout of this repo) and one variable:

MO_REGISTRY_OWNER=<owner> tools/prerelease/prerelease-link.sh link --version 0.24.0-rc.3
npm install

and to get back off it:

tools/prerelease/prerelease-link.sh unlink        # --to defaults to the pins link found; with no record, the npm `latest`
npm install

They need to be told MO_REGISTRY_BASE and MO_REGISTRY_OWNER — neither is defaulted (§7) — and no token, because reads are anonymous. unlink needs nothing at all.


4. Why the config is per-project and never machine-global

A user-level ~/.npmrc, ~/.m2/settings.xml, ~/.config/NuGet/NuGet.Config or ~/.pypirc would be less typing. It is the wrong answer, for three reasons:

  1. It is invisible to the detector. The detector reads the project. A machine-wide redirect leaves nothing in the repository to find, so "is this branch safe to merge?" stops being answerable by any check — which is the exact failure this design exists to make impossible.
  2. It switches every project at once. You cannot then have one consumer on a pre-release and the rest on public releases, which is usually the comparison you want.
  3. A silent fall-back to user-level config is how a pre-release reached a public registry during this design's own validation. A tool ignored the config it was handed, found the user-level file instead, and published for real. Machine-global config is not a convenience here; it is the loaded gun.

5. The guards, and why they are load-bearing

The registry is a public HTTPS endpoint reachable from anywhere. There is no network boundary doing safety work: these checks are the containment, not a second opinion on top of it. Treat a failure as a build break.

In a consumer: tools/prerelease/detect-prerelease-pins.sh

link installs it into the consumer at tools/prerelease/detect-prerelease-pins.sh. A copy the consumer already tracks at that path is left as it is, so unlink has nothing of it to revert. Commit it and run it in CI (and from a pre-commit hook). It flags:

  1. the pre-release registry's host — read from MO_REGISTRY_BASE, never a committed default (§7), since this file ships into adopter repositories. Unset, this one check announces that it did not run rather than passing in silence, because a guard that is quiet when it skips cannot be told apart from a guard that looked and found nothing. link passes the address through, so the linked consumer gets it; the other five checks are host-independent and always run — check 3 in particular catches a pre-release pin no matter where it came from;
  2. any private-network or loopback host declared as a package source (someone else's self-hosted instance). "Declared as a package source" is load-bearing and was once merely "appears in a manifest": an Android module's buildConfigField("SERVER_URL", "http://10.0.0.5:8000") is where the built app looks for its own backend and says nothing about where Gradle resolves dependencies, yet it failed the gate with no way for that project ever to pass — and a permanent false positive is how the true positive this exists to catch gets waved through. Files that are package-resolution config end to end (.npmrc, lockfiles, pip.conf, NuGet.config, settings.xml, requirements*.txt…) are still scanned whole; files that carry both kinds of content are scanned only inside the region that declares a source — a Gradle repositories { } / pluginManagement { } block, a pom's <repositories>/<pluginRepositories>/<distributionManagement>, a package.json dependency block or registry key, a [[tool.uv.index]]/[[tool.poetry.source]] section, a *.csproj <RestoreSources>, or a gradle.properties key naming a repo. This is the same principle the file list already applies between files, carried one level down into the files where both kinds live together;
  3. a vendor dependency pinned to a pre-release version, in any of the four spellings — the only signal that survives pip freeze, which records no index provenance at all. In manifests the name and the version share a line, so the match is namespace-anchored exactly; in lockfiles they sit on different lines, so there — and only there — a proximity window is used instead. Keeping the window out of manifests is deliberate: it would flag a third-party rc/beta that merely happens to sit near a vendor entry;
  4. an npm dependency declared as a bare dist-tag, which floats;
  5. a Maven pom pinning a pre-release in a <dependency> or <properties> block — the project's own 1.0.0-SNAPSHOT version is normal and is deliberately not flagged;
  6. a pre-release generatedBy in .metaobjects/.agent-context.json. meta init stamps the running CLI's version there, so agent context refreshed with a release candidate says so in a committed file. Refresh it with the release CLI (meta init --refresh-docs --docs-only) and commit the result. meta init also warns when it writes one.

It scans dependency declarations only (manifests and lockfiles), plus that one agent-context file. A source file that binds a test server to 127.0.0.1, or a design doc quoting an old -SNAPSHOT, is not a dependency on anything, and a check that cries wolf is a check people learn to ignore.

In this repo: scripts/check-no-prerelease-versions.sh

Runs in the gates lane of scripts/ci-local.sh and from .githooks/pre-commit whenever a version-bearing file is staged. A committed pre-release version is not cosmetic: scripts/release.mjs derives the whole lockstep set from the CLI's current version, so a stray -rc.N in one package.json would silently drop that package from the next real release.

What is deliberately NOT in CI

There is no pre-release publish workflow in GitHub Actions, and there should not be one. Publishing needs the write token, and a hosted job holding a token whose only purpose is to push unreleased artifacts is a standing risk with no matching benefit — the loop it serves is a developer iterating against a project on their own machine. Pre-release publishing stays local; the guards are what belong in CI.


6. Relationship to a real release

bun run release (scripts/release.mjs) is unchanged and still publishes to the public registries. docs/RELEASING.md keeps its public-npm RC path for the one case a private registry cannot cover: a release where dependencies or package layout changed, where the thing being tested is a real external install from the real registry.

Everything else — "does this change work in a downstream app?" — belongs here.


7. Pointing the tooling at a registry

There is no default. MO_REGISTRY_BASE, MO_REGISTRY_OWNER and MO_REGISTRY_TOKEN all come from the environment or from tools/prerelease/registry.env (gitignored; copy registry.env.example), and the tooling refuses rather than guessing. The token is a credential and the owner is an account name, which is the obvious reason for two of them — the address is in the same set because it is infrastructure belonging to whoever runs the registry, and this repository is public: a committed hostname propagates one operator's infrastructure to every reader, every fork, and — via tools/prerelease/detect-prerelease-pins.sh, which installs into consumer repos — every adopter. Without it, that guard's registry-address check announces that it did not run rather than passing silently.

Any Gitea instance works. To stand one up (a fork, another team, an offline machine):

docker compose -f tools/prerelease/docker-compose.yml up -d
tools/prerelease/bootstrap.sh          # creates the owner + token, writes registry.env

The publisher and the link helper are registry-agnostic; nothing else changes.

A CDN in front of the registry may cap request bodies (100 MB on Cloudflare's free plan), in which case a very large artifact fails at the edge rather than at Gitea. Every artifact this repo publishes is far below that.