# Releasing ferrovue The runtime's crates on crates.io and the compiler (`ferrovue` on npm) are released together and always share one version. The crates are `ferrovue-core` (escaping, numbers and URIs), `ferrovue-router`, `ferrovue-i18n` and `ferrovue`, which depends on the other three at exactly its own version and holds each as a module (`ferrovue::core`, `ferrovue::router`, `ferrovue::i18n`); `node scripts/release.ts crates` lists them in the order they are published. A release is one pull request and one tag. CI checks everything and stages every package; nothing becomes public until a maintainer approves it, once on each registry. ## Cutting a release 1. Reread `CHANGELOG.md`'s `[Unreleased]` section as a whole against the pull requests merged since the last release (`git log --merges ..main`): fold the entries about one change into one that describes it as it ships, and check each path, code and version an entry names against the code. Each entry is a change a user of the crates or the npm package can notice, in at most two lines ending with a link to the guide page that holds its detail. A release ships such a change, so `release.ts bump` refuses an empty section. The section opens with a line saying whether the release changes the HTML pages render, `Rendered output: unchanged.` or `Rendered output: changes for …` naming each construct, checked against the conformance fixtures recorded in the cycle (`git log ..main -- '*.html'`); `release.ts bump` refuses a section without it, and the GitHub release's notes carry it. Its subsections are those of [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), each at most once and in this order: `### Added`, `### Changed`, `### Deprecated`, `### Removed`, `### Fixed`, `### Security`. `release.ts bump` and `release.ts check` refuse any other heading or order. 2. Choose the version. While the crates are at 0.x, a release that breaks a public API bumps the minor version (0.1.3 to 0.2.0) and one that does not bumps the patch (0.2.0 to 0.2.1), as Cargo reads versions. `cargo semver-checks -p ` (`cargo install cargo-semver-checks --locked`) compares a crate with its last version on crates.io and says which the changes need; the release workflow runs the same check on every crate crates.io already has, and stops a release whose version is too small. It does not follow a module that is another crate: `ferrovue::router::Router` is checked as `ferrovue_router::Router`, and `crates/ferrovue/tests/paths.rs` holds each path `ferrovue` reaches through `core`, `router` and `i18n` in place. A `#[doc(hidden)]` item is outside the API it compares, and hiding one it compared before counts as breaking; CONTRIBUTING.md's "The crates' contract" says which items are hidden, `#[non_exhaustive]` and `#[must_use]`. 3. Check the version of generated code. Every generated `mod.rs` opens with `ferrovue::__compat!(N)`, where `N` is `GENERATED_VERSION` in `packages/ferrovue/src/rust.ts`, and the `ferrovue` crate accepts the versions the arms of `__compat!` in `crates/ferrovue/src/compat.rs` list. Compare the generated code and the crate with the last release's: - if generated code now calls something in the crates that the last release lacks, or calls it differently, add the next number as an arm, set `GENERATED_VERSION` to it and say "supports versions M to N" in the macro's message, so that the last release's crate refuses the new code and the new crate still takes the old; - if the crates dropped or changed something the last release's generated code calls, remove the arms that code's versions had, so that the new crate refuses it with a message in place of type errors. This is a breaking change to the generated-code contract (`crates/ferrovue/docs/guide/generated_code.md`). `generator.test.ts` checks that `GENERATED_VERSION` is the newest version the crate accepts and the message names the range, and `crates/ferrovue-contract/tests/compat.rs` checks the message a version the crate does not accept stops the build with (`TRYBUILD=overwrite cargo test -p ferrovue-contract --test compat` records it again). 4. Bump the version and open the release pull request: ```sh node scripts/release.ts bump X.Y.Z --pr ``` This sets the version in `Cargo.toml` (the workspace's version, which every crate takes, and the `=X.Y.Z` the crates require one another at) and `packages/ferrovue/package.json`, updates `Cargo.lock` and `fuzz/Cargo.lock`, sets the release the files in `VERSIONED_DOCS` name (the schema URL, the `ferrovue` dependency and the bug report's placeholder), moves the changelog notes under `## [X.Y.Z] - `, points the changelog's `[Unreleased]` link at `vX.Y.Z...HEAD` and adds a `[X.Y.Z]` link comparing with the tag before it, and opens a `release/vX.Y.Z` pull request. Without `--pr` it only edits the files. `release.ts check` refuses a tag those files do not name. Only the upgrade pages, the error codes' retirements and the changelog name earlier releases. 5. When CI is green, merge it, then tag the merge commit and push the tag: ```sh git switch main && git pull git tag -a vX.Y.Z -m "ferrovue X.Y.Z" git push origin vX.Y.Z ``` 6. The **Release** workflow then: - checks the tag against every manifest and the changelog (`node scripts/release.ts check vX.Y.Z`); - checks each crate's public API against its newest version on crates.io not newer than the tag (`cargo-semver-checks`, the kind of release read from the two versions): breaking changes need a new minor version before 1.0, a new major version after. A crate crates.io does not have yet is skipped; - runs the full CI on the tag; - **packs** every package once, in a job with no publishing rights: the crates (`cargo package`) and the npm tarball (`pnpm pack`, which builds `dist` and writes concrete versions in place of `workspace:` and `catalog:`), uploaded as the run's `packages` artifact with their SHA-256 in the job's summary; - **stages** that npm tarball, which is not public yet. The staging job checks out nothing and installs nothing but a pinned npm: it is the job that holds the OIDC token npm trusts; - **waits** for approval of the `release` environment before publishing the crates, each after the crates it depends on; - attests the build provenance of the packed files (`actions/attest-build-provenance`), and creates the GitHub release with the changelog notes and those same files attached. 7. **Approve both:** - **npm:** `npm stage approve `, which asks for your 2FA. The run prints the command, with the id when npm reports one, as a notice at the top of its page and in the npm and GitHub release jobs' summaries; otherwise `npm stage list ferrovue` shows the id. - **crates.io:** open the workflow run on GitHub and approve the waiting `release` deployment. A tag with a pre-release suffix (`vX.Y.Z-rc.1`) stages to npm under the `next` tag, and the GitHub release is marked as a pre-release. Every publishing step skips a version its registry already has, crate by crate, so a run that failed halfway can simply be re-run. The `.tgz` on the GitHub release is byte for byte the one npm staged. Anyone can check a downloaded file against the attestation: ```sh gh attestation verify ferrovue-X.Y.Z.tgz --repo Kinsmir/ferrovue ``` `cargo publish` packs the crates again in the job that publishes them, so the `.crate` files on the release are the same sources, not necessarily the same bytes as crates.io's; `cargo package --list` or unpacking both shows the files agree. ## Deprecations A release removes only what an earlier minor release deprecated, and only in a major release (after 1.0; before it, a minor one). Before 1.0 and after it, a deprecation lasts at least one minor release: - a crate item carries `#[deprecated]` in at least one minor release before the major that removes it, and `cargo-semver-checks` reports the removal as breaking; - a configuration key or command-line option warns (`FV1117`, `FV1118`) for at least one minor release before it is removed, and its removal is listed under `### Removed`; - the npm package's exports change only with `packages/ferrovue/api` (`pnpm api:report`), so a removed export shows in the release's diff. Before a major release, search for `#[deprecated`, `deprecated:` in `packages/ferrovue/src/schema.ts` and `packages/ferrovue/src/args.ts`, and remove what has been deprecated for at least one minor release. ## Release dry run The **Release dry run** workflow does what a release does short of publishing, for a throwaway pre-release of the current version (`0.6.0-dryrun.`): it checks the manifests and the changelog as the release's first job does, renders the notes, packs every package through the same `pack.yml` the release calls (after `release.ts set-version`), and has the release's npm stage the tarball with `--dry-run`. It runs on pull requests that change the release's workflows, actions or script, weekly, and by hand from the Actions tab, so a broken step shows up before a tag does. It cannot cover the signed-tag check, `cargo-semver-checks` against the next version, crates.io's publish, the provenance attestation or creating the GitHub release: those need a tag, an OIDC token or write access. The crates are published without their test data: each crate's `exclude` in its `Cargo.toml` leaves out the conformance suite, the recorded vectors and the benchmark's expected HTML, so the tests and benchmarks run from the repository only. `cargo package -p --list` shows what a crate ships, and CI's "Examples and package" job builds each crate from its tarball. ## Signed tags Only a signed, annotated tag starts a release: the workflow's first job asks GitHub whether the tag is annotated and its signature verified, and stops before anything is staged or published if not. Sign tags with a key that is on your GitHub account as a **signing key** (SSH or GPG), and make signing the default so a plain `git tag -a` signs too: ```sh git config --global tag.gpgSign true git tag -s vX.Y.Z -m "ferrovue X.Y.Z" # -s is then implied, but harmless git tag -v vX.Y.Z # check before pushing ``` ## One-time setup Neither registry holds a token for this repository: each trusts the workflow through GitHub's short-lived OIDC token. ### crates.io Each crate needs a **trusted publisher** of its own: on `https://crates.io/crates//settings`, for each of `ferrovue-core`, `ferrovue-router`, `ferrovue-i18n` and `ferrovue`, add: | Field | Value | |---|---| | Repository owner | `Kinsmir` | | Repository name | `ferrovue` | | Workflow filename | `release.yml` | | Environment | `release` | A trusted publisher is added to a crate that exists, so a new crate's first version is published by hand, with an API token from https://crates.io/settings/tokens (scope `publish-new`, expiring soon). For the first release with `ferrovue-core`, `ferrovue-router` and `ferrovue-i18n`, once the release pull request is merged and before the tag is pushed, from `main`: ```sh cargo publish -p ferrovue-core -p ferrovue-router -p ferrovue-i18n # with CARGO_REGISTRY_TOKEN set ``` Then add the trusted publisher to each of the three, and revoke the token. The workflow skips the three versions crates.io then has, and publishes `ferrovue` itself. A crate added later is published by hand the same way the first time, and goes into `CRATES` in `scripts/release.ts`, after the crates it depends on. ### npm ```sh npm trust github ferrovue --repo Kinsmir/ferrovue --file release.yml --allow-stage-publish ``` Grant only `--allow-stage-publish`, never `--allow-publish`: the workflow can then stage a version but never make it public without your 2FA. Then, on the package's **Access** settings page, choose "Require two-factor authentication and disallow tokens". ### GitHub - **Settings → Environments → New environment** `release`: - required reviewer: you; - deployment branches and tags: tags matching `v*`. - **Settings → Rules → New tag ruleset** for `v*`: restrict creation to maintainers, so only a maintainer can start a release. ## Releasing by hand If the workflow is unavailable: ```sh cargo publish -p ferrovue-core -p ferrovue-router -p ferrovue-i18n -p ferrovue cd packages/ferrovue && pnpm publish --access public # asks for your npm 2FA ``` Then create the GitHub release from the tag, with `node scripts/release.ts notes X.Y.Z` as the notes.