From b0e26b0bf41868d3186a10c3470081d0676b327c Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 15:58:40 +1100 Subject: [PATCH 01/16] ci(publish): a release publishes under rc and never moves latest A release-bump push now publishes prisma and @prisma/cli under the `rc` dist-tag, with its GitHub Release, git tag and checks as before. `latest` moves later, when a maintainer promotes the release, so the ORM, Composer and CLI releases can be checked together from npm first. A publish dispatch refuses `latest`. The version-follow script reads the products' `rc` tag first and falls back to `latest`, so a product release still reaches the CLI when it publishes, and the script does not move pins back to an older `latest` while a release waits to be promoted. The engine still publishes under `latest`: every package that uses it pins an exact version. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/publish.yml | 4 +-- .github/workflows/update-product-versions.yml | 2 +- README.md | 6 ++-- docs/oss/release-automation.md | 4 +-- docs/oss/versioning.md | 16 +++++---- docs/reference/glossary.md | 2 +- packages/cli/README.md | 2 +- packages/prisma/README.md | 2 +- scripts/determine-version-utils.test.ts | 35 ++++++++++++++----- scripts/determine-version-utils.ts | 31 ++++++++++------ scripts/determine-version.ts | 6 ++-- scripts/update-product-versions.mjs | 18 +++++----- skills-contrib/publish-npm-version/SKILL.md | 4 +-- 13 files changed, 83 insertions(+), 49 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c813f864f..0ced392a9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ on: workflow_dispatch: inputs: dist-tag: - description: "npm dist-tag. Empty = latest, the canonical tag for every release since the 2026-08-25 cutover. Pass another tag (e.g. beta) for a hand-cut preview." + description: "npm dist-tag. Empty = rc, the tag every release publishes under. latest is refused: the promote workflow moves it. Pass another tag (e.g. beta) for a hand-cut preview." required: false default: "" type: string @@ -38,7 +38,7 @@ jobs: # from any branch. if: ${{ github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dry-run == 'true') }} permissions: - contents: write # Required to create the GitHub Release + tag for latest publishes + contents: write # Required to create the GitHub Release + tag for releases id-token: write # Required for npm OIDC Trusted Publishing steps: diff --git a/.github/workflows/update-product-versions.yml b/.github/workflows/update-product-versions.yml index 2eebd09ec..b357844e9 100644 --- a/.github/workflows/update-product-versions.yml +++ b/.github/workflows/update-product-versions.yml @@ -117,7 +117,7 @@ jobs: git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "$BRANCH" PR_URL=$(gh pr create \ --title "$TITLE" \ - --body "Opened automatically by update-product-versions.yml, following the products' release dist-tags ($SUMMARY). Merging releases \`prisma@$VERSION\` under \`latest\`; the checks on this pull request are what stand between a product release and that CLI release." \ + --body "Opened automatically by update-product-versions.yml, following the products' release dist-tags ($SUMMARY). Merging publishes \`prisma@$VERSION\` under \`rc\`, and \`latest\` moves when a maintainer promotes it; the checks on this pull request are what stand between a product release and that CLI release." \ --base main --head "$BRANCH") gh pr merge --auto --squash "$PR_URL" echo "Opened $PR_URL with auto-merge armed." diff --git a/README.md b/README.md index e1b83d3d5..87c32b322 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ branches, services, service versions, environment variables, and the Prisma ORM schema and migration workflow. The 8.0.0 release candidates publish as `prisma` (binary `prisma`) and -`@prisma/cli` (binary `prisma-cli`) on the `latest` dist-tag. +`@prisma/cli` (binary `prisma-cli`) on the `rc` dist-tag, and move to `latest` +once checked. ## Install @@ -135,7 +136,8 @@ lockstep) is the release source of truth. The workflow publishes Release channels: -- `latest`: releases on the Prisma 8 RC line (`8.0.0-rc.N`). A merged PR that bumps the root version (via `pnpm bump-version`) publishes automatically: a maintainer's release PR, or the version-follow PR a product release opens; `workflow_dispatch` is the manual escape hatch and the dry-run path. +- `rc`: every release on the Prisma 8 RC line (`8.0.0-rc.N`), as soon as it publishes. A merged PR that bumps the root version (via `pnpm bump-version`) publishes automatically: a maintainer's release PR, or the version-follow PR a product release opens; `workflow_dispatch` is the manual escape hatch and the dry-run path. +- `latest`: the release a maintainer has checked and promoted. See [versioning](docs/oss/versioning.md). - `dev`: latest successful `main` build. Every push to `main` that does not change the root version publishes `-dev.N` under the `dev` dist-tag. Commit traceability comes from npm provenance and the GitHub Actions run. diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 4c86fe276..0af4e1d80 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -17,9 +17,9 @@ A **release** of the CLI depends only on **released** versions of the products. ## What happens when a product publishes 1. The product repository's publish workflow finishes and sends a `repository_dispatch` event of type `product-published` to `prisma/prisma-cli`. -2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. Every watched package publishes its releases under `latest`, pre-release versions included: they are all new packages with no pre-8 audience to protect. The bare `prisma` name, which this repository publishes, was the one exception: its `latest` served Prisma 7 until the 2026-08-25 cutover, and since then every release of it publishes under `latest` too (see [versioning.md](versioning.md)). `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each other package carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". +2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. The ORM and Composer publish each release under `rc` and move `latest` later, once the releases are checked together, as this repository does (see [versioning.md](versioning.md)). So the script reads `rc` first and falls back to `latest` for a product that does not publish `rc`. Reading `rc` lets a product release reach the CLI as soon as it publishes, and keeps the script from moving pins back to an older `latest` while a release waits to be promoted. `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each other package carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". 3. If any pin changed, or `main` holds pins the last release (its `v` tag) did not ship, the workflow bumps the CLI to its next version with `pnpm bump-version` (which also refreshes `pnpm-lock.yaml`), opens a pull request titled `Release : follow the products' released versions: ...`, and arms auto-merge. Every earlier open pull request from this workflow, and every open `Bump to version` release pull request, is closed first: each bumps the same version, so only one can merge. -4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `latest` with the committed product versions, plus the usual `dev` build. +4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `rc` with the committed product versions, plus the usual `dev` build. `latest` moves when a maintainer promotes the release. A product release reaches a released CLI with no person in the loop, as long as CodeRabbit gives the approval the ruleset requires (see the troubleshooting table when it does not), because a CLI left on an older product version breaks every project on the newer one: `prisma@8.0.0-rc.29` pinned `@prisma/orm-toolchain` 8.0.0-rc.21 for four days after the ORM's rc.22 shipped, while its release pull request waited for a review. A release for a change in this repository alone is still cut by a maintainer (see [versioning.md](versioning.md)). Everything on `main` ships with either kind of release, so `main` must always be releasable. Any commit that changes a product pin on `main`, by hand or not, is released by the next run. diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 017667029..b02c3e6e4 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -8,7 +8,7 @@ Prisma 8 ships as a release-candidate line ahead of `8.0.0` final: releases are RC respins may include breaking changes until `8.0.0` final ships. There are no patch releases on the RC line — a fix ships as the next `rc.N`. -For the packages this repository's publish workflow ships (`prisma`, `@prisma/cli`, `@prisma/cli-engine`), **every release publishes under `latest`, RC-line versions included** (operator cutover ruling 2026-08-25, executing rollout-plan step 5; supersedes the 2026-08-12 "RC under `next`" ruling). A dist-tag moves only through a deliberately merged version-bump PR (or a manual `workflow_dispatch`); creating and merging the bump PR is the operator's explicit act. Existing installs are unaffected — lockfiles pin resolved versions. +For `prisma` and `@prisma/cli`, **every release publishes under `rc`, and `latest` moves later**, when a maintainer promotes the version. The ORM and Composer do the same. A CLI release usually ships beside ORM and Composer releases, and the reason for the split is to check those releases together, installed from npm by exact version, before `npm install prisma` gives them to users (December 2026; from the 2026-08-25 cutover until then, every release went straight to `latest`, and before that the RC line lived on `next`). Merging a version-bump PR publishes under `rc`; promoting moves `latest`; both are a maintainer's deliberate act. `@prisma/cli-engine` is the exception: nothing installs it by tag, because every package that uses it pins an exact version, so it still publishes under `latest` at its own version bump. Existing installs are unaffected — lockfiles pin resolved versions. **History of the bare `prisma` name.** Its `latest` served Prisma 7 (`7.9.1`) until the 2026-08-25 cutover, so the v8 RC line lived on `next` while it matured. The product-family packages (`@prisma/composer-cli`, `@prisma/orm-toolchain` and their siblings — not this repository's three) were never held back — all new names with no version-7 audience — so they always published releases straight to `latest`, pre-release versions included, and this repository follows `latest` for them (operator ruling 2026-08-17). @@ -28,7 +28,7 @@ How the packages published by *other* repositories relate to the engine's versio **A release of the CLI depends only on released versions of the products; a dev build of the CLI depends on their dev builds** (operator ruling 2026-08-17). The two channels are kept apart by two mechanisms: -- The committed manifests hold the products' **released** versions, and [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) keeps them current — so `main` always points at released versions, and every version change is a pull request that CI has tested. That workflow also releases the CLI, so a product release reaches `latest` without a maintainer ([release-automation.md](release-automation.md)). A release publish uses those pins exactly as committed, which is what keeps a release reproducible from its tag. Pointing at released versions is not the same as being ready to release: a released version can still be unusable, and what proves the difference is the conformance checks passing on the release channel. +- The committed manifests hold the products' **released** versions, and [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) keeps them current — so `main` always points at released versions, and every version change is a pull request that CI has tested. That workflow also releases the CLI, so a product release reaches npm under `rc` without a maintainer ([release-automation.md](release-automation.md)). A release publish uses those pins exactly as committed, which is what keeps a release reproducible from its tag. Pointing at released versions is not the same as being ready to release: a released version can still be unusable, and what proves the difference is the conformance checks passing on the release channel. - A **dev** publish rewrites them to each product's `dev` dist-tag in CI, ephemerally, exactly as it rewrites the CLI's own version. The build and the conformance checks run after that rewrite, in the same run, so a broken product dev build fails the dev publish instead of shipping inside it. This is enforced, not remembered: the conformance checks refuse to publish a release whose dependencies include any `-dev.` version. `prisma@8.0.0-rc.3` shipped two of them — `@prisma/composer@0.6.0-dev.16` and `@prisma/orm-toolchain@8.0.0-rc.1-dev.40` — because nothing looked. @@ -39,8 +39,9 @@ This is enforced, not remembered: the conformance checks refuse to publish a rel The npm registry exposes the CLI packages under these dist-tags: -- **`latest`** — what a bare `npm install` gets: the newest release, RC or stable. A merged release PR publishes here automatically (operator cutover ruling 2026-08-25; before it, `latest` stayed on the pre-8 CLI and the RC line lived on `next`). -- **`next`** — removed from all three packages on 2026-11-30. After the 2026-08-25 cutover nothing moved it. Pushes to `main` publish under `latest` or `dev`, never `next`. The workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish. Moving it by hand did not happen, so by November it still pointed at `8.0.0-rc.10` and `npx prisma@next` silently installed a CLI 26 releases old. Without the tag, an old `prisma@next` instruction fails with npm's "No matching version found" error, which is better than an out-of-date CLI installed with no warning. Do not add the tag back for the 8.0.0 line, by hand or by dispatching the publish workflow with `dist-tag: next` (when that version is not on the registry yet, it is published under `next` and the tag comes back; when it is, the workflow skips it and leaves the tags alone); new text should say plain `prisma`. +- **`latest`** — what a bare `npm install` gets: the newest promoted release, RC or stable. Only promoting a release moves it. A publish dispatch refuses `latest` as its dist-tag. From the 2026-08-25 cutover until December 2026 a merged release PR published here directly; before the cutover `latest` stayed on the pre-8 CLI and the RC line lived on `next`. +- **`rc`** — every release, as soon as it publishes. A merged release PR publishes here automatically. It is ahead of `latest` while a release waits to be checked and promoted, and the same version once promoted. Every release moves it, so it does not go stale the way `next` did. +- **`next`** — removed from all three packages on 2026-11-30. After the 2026-08-25 cutover nothing moved it. Pushes to `main` publish under `rc` or `dev`, never `next`. The workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish. Moving it by hand did not happen, so by November it still pointed at `8.0.0-rc.10` and `npx prisma@next` silently installed a CLI 26 releases old. Without the tag, an old `prisma@next` instruction fails with npm's "No matching version found" error, which is better than an out-of-date CLI installed with no warning. Do not add the tag back for the 8.0.0 line, by hand or by dispatching the publish workflow with `dist-tag: next` (when that version is not on the registry yet, it is published under `next` and the tag comes back; when it is, the workflow skips it and leaves the tags alone); new text should say plain `prisma`. - **`beta`** — reserved for hand-cut previews ahead of significant changes, published by dispatching the workflow with that dist-tag. Routine releases do not use this tag. - **`dev`** — every routine push to `main` publishes `-dev.` here automatically (operator ruling 2026-08-13, superseding the earlier "no dev channel" ruling). The suffix derives from the workflow run number and is stamped ephemerally in CI, never committed, so release versions remain exactly what a commit says. The channel exists so a product's new version reaches a working CLI without a human: every push to `main` ships a dev build. A product release goes further and cuts a real release on its own; see [release automation](./release-automation.md). Only a release for a change in this repository alone is a human act. @@ -68,7 +69,7 @@ This is by design. The alternatives cause silent problems: [`scripts/set-version.ts`](../../scripts/set-version.ts) is what enforces lockstep: a single invocation walks every lockstep workspace `package.json` and writes the requested version (rewriting `workspace:` dependency pins to match). It is a maintainer's tool, invoked through `pnpm bump-version`; the publish workflow does not run it. -The publish workflow is **triggered by a change to the root `version`**: a push to `main` whose root `package.json` carries a different `version` than the previous tip is recognised as a release bump and ships that version under `latest` (the accompanying GitHub Release is marked pre-release on the RC line). This is what makes "merge the release PR" the publish trigger; there is no separate dispatch step. Every push publishes a `dev` build; one that changes the version publishes a release as well (operator ruling 2026-08-18). Within a publish, `@prisma/cli-engine` goes first, then `@prisma/cli` (which depends on it), then `prisma`. +The publish workflow is **triggered by a change to the root `version`**: a push to `main` whose root `package.json` carries a different `version` than the previous tip is recognised as a release bump and ships that version under `rc` (the accompanying GitHub Release is marked pre-release on the RC line). This is what makes "merge the release PR" the publish trigger; there is no separate dispatch step. Every push publishes a `dev` build; one that changes the version publishes a release as well (operator ruling 2026-08-18). Within a publish, `@prisma/cli-engine` goes first, then `@prisma/cli` (which depends on it), then `prisma`. **Nothing rewrites a `version` field outside a commit.** `set-version.ts` is run by `pnpm bump-version`, whose output is committed by a maintainer or by `update-product-versions.yml`; the publish workflow never invokes it. That is what makes "the version is whatever `package.json` says" true rather than aspirational — CI has no way to ship a version no commit describes. It also keeps `pnpm-lock.yaml` honest: the lockfile records the `workspace:` specifiers that `set-version.ts` rewrites, so `bump-version` refreshes it in the same breath and the bump lands as one internally consistent commit. @@ -81,9 +82,10 @@ Before anything reaches the registry, the workflow verifies the artifact it is a The release cadence is one PR per release (on the RC line: one PR per `rc.N`). A product release cuts its own CLI release ([release-automation.md](release-automation.md)). For a change in this repository alone, a maintainer: 1. **Runs the [`publish-npm-version` skill](../../skills-contrib/publish-npm-version/SKILL.md)**, which drives `pnpm bump-version` in a fresh worktree off `origin/main` and opens the release PR under real maintainer credentials (so CI runs on it normally). The script reads the root version committed at HEAD, computes the next release version (`8.0.0-rc.N` → `8.0.0-rc.N+1`), and writes it to every lockstep `package.json`. `bump-version` refreshes `pnpm-lock.yaml` itself, because the lockfile records the `workspace:` pins it rewrites and a stale one fails every later frozen install. Commit both and open a `chore(release): 8.0.0-rc.N+1` PR. -2. **Reviews and merges the PR.** This is the point where a human verifies the release is intended — merging the bump PR is the deliberate act that publishes. The resulting push to `main` carries the bumped root `version`, the publish workflow detects the change, publishes under `latest`, and creates a matching GitHub Release (marked pre-release on the RC line). +2. **Reviews and merges the PR.** This is the point where a human verifies the release is intended — merging the bump PR is the deliberate act that publishes. The resulting push to `main` carries the bumped root `version`, the publish workflow detects the change, publishes under `rc`, and creates a matching GitHub Release (marked pre-release on the RC line). +3. **Checks the published release and promotes it.** Install the new version from npm by its exact number and check it, together with the ORM and Composer releases it ships beside. Then move `latest` to it with the promote workflow. -If the publish needs to be re-run (transient registry failure, etc.), a maintainer can dispatch the [`Publish to npm`](../../.github/workflows/publish.yml) workflow from `main` with `dist-tag: latest` and `dry-run=false`; the workflow re-publishes the version currently committed at HEAD, and because the chosen tag matches the canonical one it also re-creates the GitHub Release if it is missing. This is the same path used to cut a hand-rolled `beta` (`dist-tag=beta`, no Release). +If the publish needs to be re-run (transient registry failure, etc.), a maintainer can dispatch the [`Publish to npm`](../../.github/workflows/publish.yml) workflow from `main` with an empty `dist-tag` (or `rc`) and `dry-run=false`; the workflow re-publishes the version currently committed at HEAD under `rc`, and because that is the canonical tag it also re-creates the GitHub Release if it is missing. This is the same path used to cut a hand-rolled `beta` (`dist-tag=beta`, no Release). ## Procedure: validate publish changes diff --git a/docs/reference/glossary.md b/docs/reference/glossary.md index e5eb29154..24b87254d 100644 --- a/docs/reference/glossary.md +++ b/docs/reference/glossary.md @@ -26,7 +26,7 @@ output, and implementation. | Structured output | Explicit `--json` output intended for automation. | [Output conventions](../product/output-conventions.md) | | Human output | Status, prompts, summaries, and decoration intended for terminal users. | [Output conventions](../product/output-conventions.md) | | Error code | Stable machine-readable failure code. | [Error conventions](../product/error-conventions.md) | -| Beta package | Public prerelease package line for `@prisma/cli`; the RC line publishes on the `latest` dist-tag (see [versioning](../oss/versioning.md)). | [ADR 0001](../architecture/adrs/0001-preview-package-and-publishing.md) | +| Beta package | Public prerelease package line for `@prisma/cli`; the RC line publishes on the `rc` dist-tag and moves to `latest` once checked (see [versioning](../oss/versioning.md)). | [ADR 0001](../architecture/adrs/0001-preview-package-and-publishing.md) | | Dev package | Latest successful `main` build of `@prisma/cli` on the `dev` dist-tag. | [ADR 0001](../architecture/adrs/0001-preview-package-and-publishing.md) | | PR preview package | Installable pkg.pr.new package for a trusted same-repo pull request commit. | [ADR 0001](../architecture/adrs/0001-preview-package-and-publishing.md) | diff --git a/packages/cli/README.md b/packages/cli/README.md index 0742a3247..bf66a8dac 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -107,7 +107,7 @@ npx prisma-cli service version promote VERSION_ID - Requires Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer. - This is a release-candidate package and may change quickly. -- The 8.0.0 release candidates publish as `@prisma/cli` on the `latest` dist-tag. +- The 8.0.0 release candidates publish as `@prisma/cli` on the `rc` dist-tag, and move to `latest` once checked. - The package binary is `prisma-cli`; the sibling `prisma` package ships the same CLI under the `prisma` binary. - Local project context is cached in `.prisma/local.json`, which is gitignored and not a declarative repo config file. diff --git a/packages/prisma/README.md b/packages/prisma/README.md index 99ca71736..8108879af 100644 --- a/packages/prisma/README.md +++ b/packages/prisma/README.md @@ -104,7 +104,7 @@ npx prisma service version promote VERSION_ID - Requires Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer. - This is a release-candidate package and may change quickly. -- The 8.0.0 release candidates publish as `prisma` on the `latest` dist-tag. +- The 8.0.0 release candidates publish as `prisma` on the `rc` dist-tag, and move to `latest` once checked. - The package binary is `prisma`. - Local project context is cached in `.prisma/local.json`, which is gitignored and not a declarative repo config file. diff --git a/scripts/determine-version-utils.test.ts b/scripts/determine-version-utils.test.ts index 93b595a6f..bc29aa517 100644 --- a/scripts/determine-version-utils.test.ts +++ b/scripts/determine-version-utils.test.ts @@ -2,6 +2,7 @@ import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { assertCanonicalBase, + assertDispatchDistTag, assertValidDistTag, computeNextMinor, computeNextReleaseVersion, @@ -13,6 +14,7 @@ import { const NOT_CANONICAL = /not canonical/; const NOT_A_DIST_TAG = /not a valid dist-tag/; +const LATEST_REFUSED = /cannot use "latest"/; describe("parseVersion", () => { it("parses a clean release", () => { @@ -142,14 +144,14 @@ describe("assertCanonicalBase", () => { }); describe("releaseDistTag", () => { - it("sends an RC-line bump to latest — the cutover ruling of 2026-08-25", () => { - assert.equal(releaseDistTag("8.0.0-rc.1"), "latest"); - assert.equal(releaseDistTag("8.0.0-rc.12"), "latest"); + it("sends an RC-line bump to rc, never latest", () => { + assert.equal(releaseDistTag("8.0.0-rc.1"), "rc"); + assert.equal(releaseDistTag("8.0.0-rc.12"), "rc"); }); - it("sends a stable bump to latest", () => { - assert.equal(releaseDistTag("8.0.0"), "latest"); - assert.equal(releaseDistTag("8.1.0"), "latest"); + it("sends a stable bump to rc, never latest", () => { + assert.equal(releaseDistTag("8.0.0"), "rc"); + assert.equal(releaseDistTag("8.1.0"), "rc"); }); it("refuses a non-canonical base", () => { @@ -180,16 +182,33 @@ describe("isReleasePublish", () => { }); it("a publish under the base's canonical tag is a release", () => { - assert.equal(isReleasePublish("8.0.0-rc.2", "latest"), true); - assert.equal(isReleasePublish("8.1.0", "latest"), true); + assert.equal(isReleasePublish("8.0.0-rc.2", "rc"), true); + assert.equal(isReleasePublish("8.1.0", "rc"), true); }); it("a beta or off-tag publish is not a release", () => { assert.equal(isReleasePublish("8.0.0-rc.2", "beta"), false); + assert.equal(isReleasePublish("8.0.0-rc.2", "latest"), false); assert.equal(isReleasePublish("8.0.0-rc.2", "next"), false); }); }); +describe("assertDispatchDistTag", () => { + it("refuses latest, which only the promote workflow moves", () => { + assert.throws(() => assertDispatchDistTag("latest"), LATEST_REFUSED); + }); + + it("accepts rc and a hand-cut preview tag", () => { + for (const tag of ["rc", "beta"]) { + assert.doesNotThrow(() => assertDispatchDistTag(tag)); + } + }); + + it("refuses anything that is not a plain lowercase word", () => { + assert.throws(() => assertDispatchDistTag("a tag"), NOT_A_DIST_TAG); + }); +}); + describe("assertValidDistTag", () => { it("accepts the tags the contract uses", () => { for (const tag of ["latest", "next", "beta", "dev"]) { diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index e56e14dd4..a1a0f92c0 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -116,19 +116,28 @@ export function assertValidDistTag(tag: string): void { } /** - * The dist-tag a release-bump push publishes under: `latest`, on the - * RC line included. This is the rollout plan's step-5 cutover, ruled by - * the operator on 2026-08-25: `npm install prisma` serves the unified - * v8 CLI from the first release after this widening. Before it, RC - * releases went to `next` while `latest` kept serving the pre-8 CLI. - * `next` is not moved by the publish path anymore: it froze at the - * last pre-cutover RC, and the operator re-points or retires it by - * hand — npm has no token permission narrower than package write, so - * an automated sync would mean a standing publish-capable token. + * The dist-tag a release publishes under: `rc`. A release reaches npm + * without moving `latest`, so it can be checked from the registry, with + * the ORM and Composer releases it ships beside, before users get it. + * The promote workflow moves `latest` afterwards. From the 2026-08-25 + * cutover until December 2026, releases went straight to `latest`. */ -export function releaseDistTag(base: string): "latest" | "next" { +export function releaseDistTag(base: string): "rc" { assertCanonicalBase(base); - return "latest"; + return "rc"; +} + +/** + * Asserts that a dispatch's dist-tag is a plain word other than + * `latest`: only the promote workflow moves `latest`. + */ +export function assertDispatchDistTag(tag: string): void { + assertValidDistTag(tag); + if (tag === "latest") { + throw new Error( + 'A publish dispatch cannot use "latest": a release publishes under "rc", and the promote workflow moves "latest" afterwards.', + ); + } } /** diff --git a/scripts/determine-version.ts b/scripts/determine-version.ts index a90b2583c..eedecc420 100644 --- a/scripts/determine-version.ts +++ b/scripts/determine-version.ts @@ -16,7 +16,7 @@ import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { assertCanonicalBase, - assertValidDistTag, + assertDispatchDistTag, devVersion, isReleasePublish, releaseDistTag, @@ -106,7 +106,7 @@ switch (eventName) { case "workflow_dispatch": // `||`, not `??`: an empty INPUT_DIST_TAG must fall through to the // canonical tag, not become `pnpm publish --tag ""`. - if (inputDistTag) assertValidDistTag(inputDistTag); + if (inputDistTag) assertDispatchDistTag(inputDistTag); release = { version: baseVersion, tag: inputDistTag || releaseDistTag(baseVersion), @@ -115,7 +115,7 @@ switch (eventName) { case "push": { // An unreadable previous version means no release: a transient git - // error must never promote to `latest`. + // error must never publish a release. const previous = readPreviousRootVersion(); if (!previous.available) { console.log( diff --git a/scripts/update-product-versions.mjs b/scripts/update-product-versions.mjs index 4fe2ef39d..d4da10ff7 100644 --- a/scripts/update-product-versions.mjs +++ b/scripts/update-product-versions.mjs @@ -34,30 +34,32 @@ import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; // Where each product publishes its releases, most-preferred tag first: -// the first tag that exists wins. Every one of these is a NEW package -// with no pre-8 audience to protect, so its releases go to `latest`, -// pre-release versions and all (operator, 2026-08-17). Holding `latest` -// back behind `next` matters only for the bare `prisma` name, which THIS -// repo publishes and which still serves Prisma 7 there. +// the first tag that exists wins. From December 2026 the ORM, Composer +// and this CLI publish each release under `rc` and move `latest` later, +// once the releases are checked together. Following `rc` lets a product +// release reach the CLI when it publishes, and keeps this script from +// moving pins back to an older `latest` while a release waits to be +// promoted. `latest` remains the fallback for a product that does not +// publish `rc` yet. // // A list rather than a single tag name because asking for one tag is // what made the previous version of this script silently never update // the ORM: it asked for `next`, which no prisma/prisma package has ever // had, and a missing tag was indistinguishable from a missing package. const WATCHED = /** @type {const} */ ([ - { name: "@prisma/composer-cli", release: ["latest"] }, + { name: "@prisma/composer-cli", release: ["rc", "latest"] }, // The library. `deploy` builds a Composer config with it for a // repository that has none, and the startup probe imports it to prove // the eager-loading detector works. It must move with the CLI package // it ships beside, or the install resolves a second copy. - { name: "@prisma/composer", release: ["latest"] }, + { name: "@prisma/composer", release: ["rc", "latest"] }, // The Prisma Cloud target that the same `deploy` path loads. Composer // publishes it with the CLI package at one version. { name: "@prisma/composer-prisma-cloud", sameVersionAs: "@prisma/composer-cli", }, - { name: "@prisma/orm-toolchain", release: ["latest"] }, + { name: "@prisma/orm-toolchain", release: ["rc", "latest"] }, // The shell lists the framework so it does not rely on the toolchain // bringing it; from the ORM release after 8.0.0-rc.25 the toolchain // names it as an exact peer. It takes diff --git a/skills-contrib/publish-npm-version/SKILL.md b/skills-contrib/publish-npm-version/SKILL.md index f8c103fa5..5a0a3a360 100644 --- a/skills-contrib/publish-npm-version/SKILL.md +++ b/skills-contrib/publish-npm-version/SKILL.md @@ -6,7 +6,7 @@ description: >- propagates it to every lockstep workspace package, and opens a PR titled "chore(release): bump to ". When the maintainer merges the PR, the `Publish to npm` workflow ships @prisma/cli-engine - and @prisma/cli under dist-tag `latest` (RC versions get a + and @prisma/cli under dist-tag `rc` (RC versions get a pre-release GitHub Release). Use when a maintainer asks to "cut the next RC", "cut the next release", "bump to the next version", "open a release PR", or "prepare a publish PR". @@ -92,7 +92,7 @@ succeeds; if not, stop and surface the issue. **merging this PR ships the release** — the squashed push to `main` changes the root version with the release marker, the `Publish to npm` workflow publishes `@prisma/cli-engine` then `@prisma/cli` - under `latest`, and a GitHub Release (pre-release on the RC line) is + under `rc`, and a GitHub Release (pre-release on the RC line) is created with generated notes. This repo has no committed release-notes file gate; review the generated notes on the Release after merge. From a394cd9ffda6e3f07957e933e2f7401d6050160e Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:00:06 +1100 Subject: [PATCH 02/16] ci(promote): move latest to a checked release with promote.yml A manual workflow, dispatched from main with a version. It checks that prisma and @prisma/cli are on npm at that version and changes nothing if not; a real run moves latest on both and checks it moved. Dry run is the default. The npm token comes from the secret NPM_TOKEN of the npm-promote environment, which the promoter adds for one run and deletes after, so the repository holds no token between promotions. It is not a dispatch input, because inputs on a public repository are not treated as secrets. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 90 +++++++++++++++++++ .github/workflows/publish.yml | 2 +- .github/workflows/update-product-versions.yml | 2 +- docs/oss/release-automation.md | 2 +- docs/oss/versioning.md | 19 +++- scripts/determine-version-utils.ts | 6 +- 6 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/promote.yml diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml new file mode 100644 index 000000000..f079f0a4d --- /dev/null +++ b/.github/workflows/promote.yml @@ -0,0 +1,90 @@ +name: Promote a release to latest + +# A release publishes under `rc` (publish.yml). This moves `latest` for +# `prisma` and `@prisma/cli` to a version already on npm, once it has +# been checked. See docs/oss/versioning.md. +# +# Trusted publishing cannot move a tag on a published version, so the +# real run needs an npm token. It comes from the secret NPM_TOKEN in the +# `npm-promote` environment, which the promoter adds just before a run +# and deletes after: the repository holds no token between promotions. + +on: + workflow_dispatch: + inputs: + version: + description: "Version to move latest to, e.g. 8.0.0-rc.37. It must already be on npm for prisma and @prisma/cli." + required: true + type: string + dry-run: + description: "Check only; change no tags." + required: false + default: true + type: boolean + +concurrency: + group: npm-promote + cancel-in-progress: false + +permissions: {} + +jobs: + check: + name: Check the version is published + runs-on: ubuntu-latest + if: ${{ github.ref == 'refs/heads/main' }} + steps: + - name: Check every package is on npm at the version + env: + VERSION: ${{ inputs.version }} + run: | + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[1-9][0-9]*)?$ ]]; then + echo "\"$VERSION\" is not a release version such as 8.0.0-rc.37 or 8.0.0." >&2 + exit 1 + fi + for pkg in prisma @prisma/cli; do + if ! published=$(npm view "$pkg@$VERSION" version 2>/dev/null) || [ "$published" != "$VERSION" ]; then + echo "$pkg@$VERSION is not on npm; nothing was changed." >&2 + exit 1 + fi + echo "$pkg@$VERSION is on npm (latest is now $(npm view "$pkg" dist-tags.latest))." + done + + promote: + name: Move latest + needs: check + if: ${{ github.ref == 'refs/heads/main' && !inputs.dry-run }} + runs-on: ubuntu-latest + environment: npm-promote + steps: + - name: Set up npm + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: 24 + registry-url: https://registry.npmjs.org + + - name: Move latest + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + VERSION: ${{ inputs.version }} + run: | + if [ -z "$NODE_AUTH_TOKEN" ]; then + echo "The npm-promote environment has no NPM_TOKEN secret. Add a short-lived granular token there, run again, then delete it." >&2 + exit 1 + fi + for pkg in prisma @prisma/cli; do + npm dist-tag add "$pkg@$VERSION" latest + done + + - name: Check latest moved + env: + VERSION: ${{ inputs.version }} + run: | + for pkg in prisma @prisma/cli; do + latest=$(npm view "$pkg" dist-tags.latest) + if [ "$latest" != "$VERSION" ]; then + echo "$pkg latest is $latest, not $VERSION." >&2 + exit 1 + fi + echo "$pkg latest is $VERSION." + done diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0ced392a9..e1e012800 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ on: workflow_dispatch: inputs: dist-tag: - description: "npm dist-tag. Empty = rc, the tag every release publishes under. latest is refused: the promote workflow moves it. Pass another tag (e.g. beta) for a hand-cut preview." + description: "npm dist-tag. Empty = rc, the tag every release publishes under. latest is refused: promote.yml moves it. Pass another tag (e.g. beta) for a hand-cut preview." required: false default: "" type: string diff --git a/.github/workflows/update-product-versions.yml b/.github/workflows/update-product-versions.yml index b357844e9..7bb2e27fe 100644 --- a/.github/workflows/update-product-versions.yml +++ b/.github/workflows/update-product-versions.yml @@ -117,7 +117,7 @@ jobs: git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "$BRANCH" PR_URL=$(gh pr create \ --title "$TITLE" \ - --body "Opened automatically by update-product-versions.yml, following the products' release dist-tags ($SUMMARY). Merging publishes \`prisma@$VERSION\` under \`rc\`, and \`latest\` moves when a maintainer promotes it; the checks on this pull request are what stand between a product release and that CLI release." \ + --body "Opened automatically by update-product-versions.yml, following the products' release dist-tags ($SUMMARY). Merging publishes \`prisma@$VERSION\` under \`rc\`, and \`latest\` moves when a maintainer runs promote.yml; the checks on this pull request are what stand between a product release and that CLI release." \ --base main --head "$BRANCH") gh pr merge --auto --squash "$PR_URL" echo "Opened $PR_URL with auto-merge armed." diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 0af4e1d80..cbe51a555 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -19,7 +19,7 @@ A **release** of the CLI depends only on **released** versions of the products. 1. The product repository's publish workflow finishes and sends a `repository_dispatch` event of type `product-published` to `prisma/prisma-cli`. 2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. The ORM and Composer publish each release under `rc` and move `latest` later, once the releases are checked together, as this repository does (see [versioning.md](versioning.md)). So the script reads `rc` first and falls back to `latest` for a product that does not publish `rc`. Reading `rc` lets a product release reach the CLI as soon as it publishes, and keeps the script from moving pins back to an older `latest` while a release waits to be promoted. `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each other package carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". 3. If any pin changed, or `main` holds pins the last release (its `v` tag) did not ship, the workflow bumps the CLI to its next version with `pnpm bump-version` (which also refreshes `pnpm-lock.yaml`), opens a pull request titled `Release : follow the products' released versions: ...`, and arms auto-merge. Every earlier open pull request from this workflow, and every open `Bump to version` release pull request, is closed first: each bumps the same version, so only one can merge. -4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `rc` with the committed product versions, plus the usual `dev` build. `latest` moves when a maintainer promotes the release. +4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `rc` with the committed product versions, plus the usual `dev` build. `latest` moves when a maintainer promotes the release with [`promote.yml`](../../.github/workflows/promote.yml). A product release reaches a released CLI with no person in the loop, as long as CodeRabbit gives the approval the ruleset requires (see the troubleshooting table when it does not), because a CLI left on an older product version breaks every project on the newer one: `prisma@8.0.0-rc.29` pinned `@prisma/orm-toolchain` 8.0.0-rc.21 for four days after the ORM's rc.22 shipped, while its release pull request waited for a review. A release for a change in this repository alone is still cut by a maintainer (see [versioning.md](versioning.md)). Everything on `main` ships with either kind of release, so `main` must always be releasable. Any commit that changes a product pin on `main`, by hand or not, is released by the next run. diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index b02c3e6e4..e3d4ed30f 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -8,7 +8,7 @@ Prisma 8 ships as a release-candidate line ahead of `8.0.0` final: releases are RC respins may include breaking changes until `8.0.0` final ships. There are no patch releases on the RC line — a fix ships as the next `rc.N`. -For `prisma` and `@prisma/cli`, **every release publishes under `rc`, and `latest` moves later**, when a maintainer promotes the version. The ORM and Composer do the same. A CLI release usually ships beside ORM and Composer releases, and the reason for the split is to check those releases together, installed from npm by exact version, before `npm install prisma` gives them to users (December 2026; from the 2026-08-25 cutover until then, every release went straight to `latest`, and before that the RC line lived on `next`). Merging a version-bump PR publishes under `rc`; promoting moves `latest`; both are a maintainer's deliberate act. `@prisma/cli-engine` is the exception: nothing installs it by tag, because every package that uses it pins an exact version, so it still publishes under `latest` at its own version bump. Existing installs are unaffected — lockfiles pin resolved versions. +For `prisma` and `@prisma/cli`, **every release publishes under `rc`, and `latest` moves later**, when a maintainer promotes the version with [`promote.yml`](../../.github/workflows/promote.yml). The ORM and Composer do the same. A CLI release usually ships beside ORM and Composer releases, and the reason for the split is to check those releases together, installed from npm by exact version, before `npm install prisma` gives them to users (December 2026; from the 2026-08-25 cutover until then, every release went straight to `latest`, and before that the RC line lived on `next`). Merging a version-bump PR publishes under `rc`; promoting moves `latest`; both are a maintainer's deliberate act. `@prisma/cli-engine` is the exception: nothing installs it by tag, because every package that uses it pins an exact version, so it still publishes under `latest` at its own version bump. Existing installs are unaffected — lockfiles pin resolved versions. **History of the bare `prisma` name.** Its `latest` served Prisma 7 (`7.9.1`) until the 2026-08-25 cutover, so the v8 RC line lived on `next` while it matured. The product-family packages (`@prisma/composer-cli`, `@prisma/orm-toolchain` and their siblings — not this repository's three) were never held back — all new names with no version-7 audience — so they always published releases straight to `latest`, pre-release versions included, and this repository follows `latest` for them (operator ruling 2026-08-17). @@ -41,7 +41,7 @@ The npm registry exposes the CLI packages under these dist-tags: - **`latest`** — what a bare `npm install` gets: the newest promoted release, RC or stable. Only promoting a release moves it. A publish dispatch refuses `latest` as its dist-tag. From the 2026-08-25 cutover until December 2026 a merged release PR published here directly; before the cutover `latest` stayed on the pre-8 CLI and the RC line lived on `next`. - **`rc`** — every release, as soon as it publishes. A merged release PR publishes here automatically. It is ahead of `latest` while a release waits to be checked and promoted, and the same version once promoted. Every release moves it, so it does not go stale the way `next` did. -- **`next`** — removed from all three packages on 2026-11-30. After the 2026-08-25 cutover nothing moved it. Pushes to `main` publish under `rc` or `dev`, never `next`. The workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish. Moving it by hand did not happen, so by November it still pointed at `8.0.0-rc.10` and `npx prisma@next` silently installed a CLI 26 releases old. Without the tag, an old `prisma@next` instruction fails with npm's "No matching version found" error, which is better than an out-of-date CLI installed with no warning. Do not add the tag back for the 8.0.0 line, by hand or by dispatching the publish workflow with `dist-tag: next` (when that version is not on the registry yet, it is published under `next` and the tag comes back; when it is, the workflow skips it and leaves the tags alone); new text should say plain `prisma`. +- **`next`** — removed from all three packages on 2026-11-30. After the 2026-08-25 cutover nothing moved it. Pushes to `main` publish under `rc` or `dev`, never `next`. The publish workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish (the promote workflow gets around this with a token added for one run; see [Procedure: promote a release to `latest`](#procedure-promote-a-release-to-latest)). Moving it by hand did not happen, so by November it still pointed at `8.0.0-rc.10` and `npx prisma@next` silently installed a CLI 26 releases old. Without the tag, an old `prisma@next` instruction fails with npm's "No matching version found" error, which is better than an out-of-date CLI installed with no warning. Do not add the tag back for the 8.0.0 line, by hand or by dispatching the publish workflow with `dist-tag: next` (when that version is not on the registry yet, it is published under `next` and the tag comes back; when it is, the workflow skips it and leaves the tags alone); new text should say plain `prisma`. - **`beta`** — reserved for hand-cut previews ahead of significant changes, published by dispatching the workflow with that dist-tag. Routine releases do not use this tag. - **`dev`** — every routine push to `main` publishes `-dev.` here automatically (operator ruling 2026-08-13, superseding the earlier "no dev channel" ruling). The suffix derives from the workflow run number and is stamped ephemerally in CI, never committed, so release versions remain exactly what a commit says. The channel exists so a product's new version reaches a working CLI without a human: every push to `main` ships a dev build. A product release goes further and cuts a real release on its own; see [release automation](./release-automation.md). Only a release for a change in this repository alone is a human act. @@ -83,7 +83,20 @@ The release cadence is one PR per release (on the RC line: one PR per `rc.N`). A 1. **Runs the [`publish-npm-version` skill](../../skills-contrib/publish-npm-version/SKILL.md)**, which drives `pnpm bump-version` in a fresh worktree off `origin/main` and opens the release PR under real maintainer credentials (so CI runs on it normally). The script reads the root version committed at HEAD, computes the next release version (`8.0.0-rc.N` → `8.0.0-rc.N+1`), and writes it to every lockstep `package.json`. `bump-version` refreshes `pnpm-lock.yaml` itself, because the lockfile records the `workspace:` pins it rewrites and a stale one fails every later frozen install. Commit both and open a `chore(release): 8.0.0-rc.N+1` PR. 2. **Reviews and merges the PR.** This is the point where a human verifies the release is intended — merging the bump PR is the deliberate act that publishes. The resulting push to `main` carries the bumped root `version`, the publish workflow detects the change, publishes under `rc`, and creates a matching GitHub Release (marked pre-release on the RC line). -3. **Checks the published release and promotes it.** Install the new version from npm by its exact number and check it, together with the ORM and Composer releases it ships beside. Then move `latest` to it with the promote workflow. +3. **Checks the published release and promotes it.** Install the new version from npm by its exact number and check it, together with the ORM and Composer releases it ships beside. Then move `latest` to it with [`promote.yml`](../../.github/workflows/promote.yml), as the next section describes. + +## Procedure: promote a release to `latest` + +[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand from `main` with the version to promote. It first checks that `prisma` and `@prisma/cli` are on npm at that version, and changes nothing if either is missing. A real run then moves `latest` on both and checks that it moved. Running it twice is harmless. A dry run (the default) only does the check. + +Trusted publishing, which the publish workflow uses, can set a tag only on the version it is publishing, so moving `latest` on a published version needs an npm token. The repository holds none between promotions, because a stored token that can move a tag can also publish. For each promotion: + +1. Create a short-lived granular npm access token with write access to `prisma` and `@prisma/cli` only. +2. Add it as the secret `NPM_TOKEN` of the GitHub environment `npm-promote` (Settings → Environments). +3. Dispatch `promote.yml` with the version and `dry-run` off. +4. Delete the secret from the environment and revoke the token on npm. + +The token is not a dispatch input, because dispatch inputs on a public repository are not treated as secrets. The workflow reads it only in the step that moves the tags. If the publish needs to be re-run (transient registry failure, etc.), a maintainer can dispatch the [`Publish to npm`](../../.github/workflows/publish.yml) workflow from `main` with an empty `dist-tag` (or `rc`) and `dry-run=false`; the workflow re-publishes the version currently committed at HEAD under `rc`, and because that is the canonical tag it also re-creates the GitHub Release if it is missing. This is the same path used to cut a hand-rolled `beta` (`dist-tag=beta`, no Release). diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index a1a0f92c0..c6b6eeba1 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -119,7 +119,7 @@ export function assertValidDistTag(tag: string): void { * The dist-tag a release publishes under: `rc`. A release reaches npm * without moving `latest`, so it can be checked from the registry, with * the ORM and Composer releases it ships beside, before users get it. - * The promote workflow moves `latest` afterwards. From the 2026-08-25 + * promote.yml moves `latest` afterwards. From the 2026-08-25 * cutover until December 2026, releases went straight to `latest`. */ export function releaseDistTag(base: string): "rc" { @@ -129,13 +129,13 @@ export function releaseDistTag(base: string): "rc" { /** * Asserts that a dispatch's dist-tag is a plain word other than - * `latest`: only the promote workflow moves `latest`. + * `latest`: only promote.yml moves `latest`. */ export function assertDispatchDistTag(tag: string): void { assertValidDistTag(tag); if (tag === "latest") { throw new Error( - 'A publish dispatch cannot use "latest": a release publishes under "rc", and the promote workflow moves "latest" afterwards.', + 'A publish dispatch cannot use "latest": a release publishes under "rc", and promote.yml moves "latest" afterwards.', ); } } From 70d5f9d4d109c5aa1d14995fd8794e6317c6422d Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:02:58 +1100 Subject: [PATCH 03/16] fix(release): follow the newest of rc and latest; correct the remaining docs Review fixes for the rc release flow: - update-product-versions takes the newest version among a product's candidate tags, so a stale rc behind latest never moves a pin backwards. Tests pin the rc-then-latest order and cover a stale rc. - The release step no longer lists @prisma/cli-engine: the engine publishes under latest in its own step. - CONTRIBUTING, versioning, release-automation and the release skill no longer say a release publishes under latest, and the promotion procedure says to promote the ORM and Composer before the CLI. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/publish.yml | 2 +- CONTRIBUTING.md | 5 +- docs/oss/release-automation.md | 2 +- docs/oss/versioning.md | 6 +- scripts/update-product-versions.mjs | 68 +++++++++++++++++++-- scripts/update-product-versions.test.mjs | 65 ++++++++++++++++++++ skills-contrib/publish-npm-version/SKILL.md | 8 +-- 7 files changed, 141 insertions(+), 15 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e1e012800..a2456e6f4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -180,7 +180,7 @@ jobs: env: NPM_CONFIG_PROVENANCE: "true" DIST_TAG: ${{ steps.version.outputs.releaseTag }} - run: bash scripts/publish-packages.sh "$DIST_TAG" @prisma/cli-engine @prisma/cli prisma + run: bash scripts/publish-packages.sh "$DIST_TAG" @prisma/cli prisma - name: Verify the release resolves if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3fee1be2e..8384a53bd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -62,8 +62,9 @@ The CLI must preserve the unified command model: Releases use `@prisma/cli` (exposing the `prisma-cli` binary) plus its dependency `@prisma/cli-engine`, versioned in lockstep from the root -`package.json` on the Prisma 8 RC line (`8.0.0-rc.N`). The `latest` dist-tag moves -when a version-bump PR merges; see `docs/oss/versioning.md`. +`package.json` on the Prisma 8 RC line (`8.0.0-rc.N`). A merged version-bump PR +publishes under the `rc` dist-tag; `latest` moves when a maintainer promotes the +release with `promote.yml`; see `docs/oss/versioning.md`. The `dev` dist-tag points at the latest successful `main` build, published as `-dev.N`. Commit traceability comes from npm diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index cbe51a555..69a46db78 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -21,7 +21,7 @@ A **release** of the CLI depends only on **released** versions of the products. 3. If any pin changed, or `main` holds pins the last release (its `v` tag) did not ship, the workflow bumps the CLI to its next version with `pnpm bump-version` (which also refreshes `pnpm-lock.yaml`), opens a pull request titled `Release : follow the products' released versions: ...`, and arms auto-merge. Every earlier open pull request from this workflow, and every open `Bump to version` release pull request, is closed first: each bumps the same version, so only one can merge. 4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `rc` with the committed product versions, plus the usual `dev` build. `latest` moves when a maintainer promotes the release with [`promote.yml`](../../.github/workflows/promote.yml). -A product release reaches a released CLI with no person in the loop, as long as CodeRabbit gives the approval the ruleset requires (see the troubleshooting table when it does not), because a CLI left on an older product version breaks every project on the newer one: `prisma@8.0.0-rc.29` pinned `@prisma/orm-toolchain` 8.0.0-rc.21 for four days after the ORM's rc.22 shipped, while its release pull request waited for a review. A release for a change in this repository alone is still cut by a maintainer (see [versioning.md](versioning.md)). Everything on `main` ships with either kind of release, so `main` must always be releasable. Any commit that changes a product pin on `main`, by hand or not, is released by the next run. +A product release reaches a CLI release under `rc` with no person in the loop (a maintainer then checks the releases together and promotes them to `latest`), as long as CodeRabbit gives the approval the ruleset requires (see the troubleshooting table when it does not), because a CLI left on an older product version breaks every project on the newer one: `prisma@8.0.0-rc.29` pinned `@prisma/orm-toolchain` 8.0.0-rc.21 for four days after the ORM's rc.22 shipped, while its release pull request waited for a review. A release for a change in this repository alone is still cut by a maintainer (see [versioning.md](versioning.md)). Everything on `main` ships with either kind of release, so `main` must always be releasable. Any commit that changes a product pin on `main`, by hand or not, is released by the next run. A **daily schedule** runs the same comparison, so a lost dispatch event delays an update by at most a day rather than indefinitely. `workflow_dispatch` runs it on demand. diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index e3d4ed30f..c170ba979 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -10,7 +10,7 @@ RC respins may include breaking changes until `8.0.0` final ships. There are no For `prisma` and `@prisma/cli`, **every release publishes under `rc`, and `latest` moves later**, when a maintainer promotes the version with [`promote.yml`](../../.github/workflows/promote.yml). The ORM and Composer do the same. A CLI release usually ships beside ORM and Composer releases, and the reason for the split is to check those releases together, installed from npm by exact version, before `npm install prisma` gives them to users (December 2026; from the 2026-08-25 cutover until then, every release went straight to `latest`, and before that the RC line lived on `next`). Merging a version-bump PR publishes under `rc`; promoting moves `latest`; both are a maintainer's deliberate act. `@prisma/cli-engine` is the exception: nothing installs it by tag, because every package that uses it pins an exact version, so it still publishes under `latest` at its own version bump. Existing installs are unaffected — lockfiles pin resolved versions. -**History of the bare `prisma` name.** Its `latest` served Prisma 7 (`7.9.1`) until the 2026-08-25 cutover, so the v8 RC line lived on `next` while it matured. The product-family packages (`@prisma/composer-cli`, `@prisma/orm-toolchain` and their siblings — not this repository's three) were never held back — all new names with no version-7 audience — so they always published releases straight to `latest`, pre-release versions included, and this repository follows `latest` for them (operator ruling 2026-08-17). +**History of the bare `prisma` name.** Its `latest` served Prisma 7 (`7.9.1`) until the 2026-08-25 cutover, so the v8 RC line lived on `next` while it matured. The product-family packages (`@prisma/composer-cli`, `@prisma/orm-toolchain` and their siblings — not this repository's three) were never held back — all new names with no version-7 audience — so they always published releases straight to `latest`, pre-release versions included, and this repository followed `latest` for them (operator ruling 2026-08-17). From December 2026 they publish releases under `rc` like this repository, and it follows `rc`, falling back to `latest` ([release-automation.md](release-automation.md)). The transition onto the RC line is a one-time bump from the pre-8 base to `8.0.0-rc.1`; `pnpm bump-version` encodes it (a pre-8 stable base advances to `8.0.0-rc.1`, an RC base advances its counter). @@ -18,7 +18,7 @@ The transition onto the RC line is a one-time bump from the pre-8 base to `8.0.0 Every lockstep workspace package — publishable, private, and the workspace root — carries the same `version`. One read of root [`package.json`](../../package.json) answers "what version is this code?" for the repository. -**Exceptions:** `@prisma/compute` versions independently, pending extraction to another repository (operator ruling 2026-08-10), and keeps its own publish workflow ([`publish-compute.yml`](../../.github/workflows/publish-compute.yml)). `@prisma/cli-engine` also versions independently ([ADR 0004](../architecture/adrs/0004-engine-version-pinning.md), operator ruling 2026-08-13): an engine version means "the engine changed", not "the CLI released", which is what keeps the exact peer pins the product CLI packages hold on it cheap — they change only when the engine actually moves. The engine follows honest pre-1.0 semver (a breaking change bumps the minor); bumping it is one command — `pnpm bump-cli-engine-version ` — which edits `packages/cli-engine/package.json`, the `workspace:` pin in every consumer manifest (`packages/cli`, `packages/prisma`), and the lockfile together, landed as a reviewed commit like any other version change (run it in the PR that changes the engine). Both packages are hard-excluded in [`scripts/set-version.ts`](../../scripts/set-version.ts), which still sweeps their `workspace:` pins on lockstep siblings so those never go stale. At publish time the engine ships at its own manifest version **under `latest`**, on the first publish run that carries the bumped version — normally the merge of the PR that bumped it. That is the same rule every other package follows — a deliberately merged version-bump PR is what publishes a version under `latest` — applied at the engine's own bump instead of the root's. An already-published engine version is a no-op. The engine has no dev builds, for two reasons. First, the product CLI packages peer it at an exact release version, and so do their dev builds, so a dev-stamped engine would satisfy none of them and `npm install prisma@dev` would fail. Second, a dev build would expose nothing: CI refuses any change to the engine's published contents that does not bump its version, and that merge publishes the new version, so merged engine work is never unreleased. (Before 2026-08-26 the workflow published the engine inside the dev-build half under `--tag dev`, so a new engine version reached the registry with its `latest` tag stuck on the previous version until an operator moved it by hand — `0.2.x` and `0.3.0` shipped that way.) The engine's own line continues from `0.1.0` (after the published `0.0.x` series); the `8.0.0-rc.N` engine versions that shipped while it was still in lockstep are burned values — they exist on the registry, nothing pins them, and version numbers are never reused. +**Exceptions:** `@prisma/compute` versions independently, pending extraction to another repository (operator ruling 2026-08-10), and keeps its own publish workflow ([`publish-compute.yml`](../../.github/workflows/publish-compute.yml)). `@prisma/cli-engine` also versions independently ([ADR 0004](../architecture/adrs/0004-engine-version-pinning.md), operator ruling 2026-08-13): an engine version means "the engine changed", not "the CLI released", which is what keeps the exact peer pins the product CLI packages hold on it cheap — they change only when the engine actually moves. The engine follows honest pre-1.0 semver (a breaking change bumps the minor); bumping it is one command — `pnpm bump-cli-engine-version ` — which edits `packages/cli-engine/package.json`, the `workspace:` pin in every consumer manifest (`packages/cli`, `packages/prisma`), and the lockfile together, landed as a reviewed commit like any other version change (run it in the PR that changes the engine). Both packages are hard-excluded in [`scripts/set-version.ts`](../../scripts/set-version.ts), which still sweeps their `workspace:` pins on lockstep siblings so those never go stale. At publish time the engine ships at its own manifest version **under `latest`**, on the first publish run that carries the bumped version — normally the merge of the PR that bumped it. That is the rule `prisma` and `@prisma/cli` followed until December 2026 — a deliberately merged version-bump PR publishes a version under `latest` — and the engine keeps it, because nothing installs the engine by tag: every package that uses it pins an exact version. `prisma` and `@prisma/cli` now publish under `rc` and are promoted to `latest` separately. An already-published engine version is a no-op. The engine has no dev builds, for two reasons. First, the product CLI packages peer it at an exact release version, and so do their dev builds, so a dev-stamped engine would satisfy none of them and `npm install prisma@dev` would fail. Second, a dev build would expose nothing: CI refuses any change to the engine's published contents that does not bump its version, and that merge publishes the new version, so merged engine work is never unreleased. (Before 2026-08-26 the workflow published the engine inside the dev-build half under `--tag dev`, so a new engine version reached the registry with its `latest` tag stuck on the previous version until an operator moved it by hand — `0.2.x` and `0.3.0` shipped that way.) The engine's own line continues from `0.1.0` (after the published `0.0.x` series); the `8.0.0-rc.N` engine versions that shipped while it was still in lockstep are burned values — they exist on the registry, nothing pins them, and version numbers are never reused. The lockstep set is: the workspace root, `packages/cli`, `packages/prisma`, `packages/cli-telemetry`, `packages/cli-conformance`, and `packages/tsconfig`. Private packages are never published (`pnpm publish` skips them), but they still version in lockstep so a contributor cloning the repo at any commit sees one consistent answer to "what version is this code?". Workspace-internal dependencies are pinned as `workspace:` (e.g. `workspace:8.0.0-rc.1`); pnpm resolves them locally during development and rewrites them to the exact version at publish time, so every published package carries an exact-version pin on its siblings. @@ -93,7 +93,7 @@ Trusted publishing, which the publish workflow uses, can set a tag only on the v 1. Create a short-lived granular npm access token with write access to `prisma` and `@prisma/cli` only. 2. Add it as the secret `NPM_TOKEN` of the GitHub environment `npm-promote` (Settings → Environments). -3. Dispatch `promote.yml` with the version and `dry-run` off. +3. Dispatch `promote.yml` with the version and `dry-run` off. When the release ships beside ORM and Composer releases, promote those first: a CLI release pins the products' versions exactly, so a promoted CLI ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not yet `latest`. 4. Delete the secret from the environment and revoke the token on npm. The token is not a dispatch input, because dispatch inputs on a public repository are not treated as secrets. The workflow reads it only in the step that moves the tags. diff --git a/scripts/update-product-versions.mjs b/scripts/update-product-versions.mjs index d4da10ff7..1a37e9412 100644 --- a/scripts/update-product-versions.mjs +++ b/scripts/update-product-versions.mjs @@ -93,19 +93,79 @@ export function tagsFor(entry, channel) { } /** - * The first candidate tag the package actually publishes. Pure; - * exported for tests. + * Semver precedence of two versions: negative when `a` is older. + * Build metadata is not used by any watched package. Pure; exported + * for tests. + * + * @param {string} a + * @param {string} b + * @returns {number} + */ +export function compareVersions(a, b) { + const [coreA, preA] = splitVersion(a); + const [coreB, preB] = splitVersion(b); + for (let i = 0; i < 3; i++) { + if (coreA[i] !== coreB[i]) return coreA[i] - coreB[i]; + } + // A release is newer than any pre-release of the same core. + if (preA === undefined || preB === undefined) { + return (preA === undefined ? 1 : 0) - (preB === undefined ? 1 : 0); + } + const length = Math.max(preA.length, preB.length); + for (let i = 0; i < length; i++) { + const order = compareIdentifiers(preA[i], preB[i]); + if (order !== 0) return order; + } + return 0; +} + +const NUMERIC = /^\d+$/; + +/** + * @param {string | undefined} a + * @param {string | undefined} b + */ +function compareIdentifiers(a, b) { + if (a === b) return 0; + if (a === undefined) return -1; + if (b === undefined) return 1; + const numA = NUMERIC.test(a); + const numB = NUMERIC.test(b); + if (numA && numB) return Number(a) - Number(b); + if (numA !== numB) return numA ? -1 : 1; + return a < b ? -1 : 1; +} + +/** @param {string} version */ +function splitVersion(version) { + const dash = version.indexOf("-"); + const core = (dash === -1 ? version : version.slice(0, dash)) + .split(".") + .map(Number); + const pre = dash === -1 ? undefined : version.slice(dash + 1).split("."); + return /** @type {const} */ ([core, pre]); +} + +/** + * The newest version among the candidate tags the package publishes, + * the earlier candidate winning a tie. Taking the newest rather than the + * first tag that exists means a stale `rc` behind `latest` never moves a + * pin backwards. Pure; exported for tests. * * @param {Record} distTags * @param {readonly string[]} candidates * @returns {{ tag: string; version: string } | undefined} */ export function selectTag(distTags, candidates) { + let chosen; for (const tag of candidates) { const version = distTags[tag]; - if (version !== undefined) return { tag, version }; + if (version === undefined) continue; + if (chosen === undefined || compareVersions(version, chosen.version) > 0) { + chosen = { tag, version }; + } } - return undefined; + return chosen; } /** diff --git a/scripts/update-product-versions.test.mjs b/scripts/update-product-versions.test.mjs index d220831d0..3c3e9cdfe 100644 --- a/scripts/update-product-versions.test.mjs +++ b/scripts/update-product-versions.test.mjs @@ -2,6 +2,7 @@ import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { applyUpdates, + compareVersions, computeUpdates, isPackageAbsent, pinChanges, @@ -52,6 +53,27 @@ describe("selectTag", () => { ); }); + it("takes rc while a release waits to be promoted", () => { + assert.deepEqual( + selectTag({ rc: "8.0.0-rc.26", latest: "8.0.0-rc.25" }, ["rc", "latest"]), + { tag: "rc", version: "8.0.0-rc.26" }, + ); + }); + + it("takes rc once it and latest name the same version", () => { + assert.deepEqual( + selectTag({ rc: "0.41.0", latest: "0.41.0" }, ["rc", "latest"]), + { tag: "rc", version: "0.41.0" }, + ); + }); + + it("never takes a stale rc behind latest, so no pin moves backwards", () => { + assert.deepEqual( + selectTag({ rc: "8.0.0-rc.25", latest: "8.0.0-rc.27" }, ["rc", "latest"]), + { tag: "latest", version: "8.0.0-rc.27" }, + ); + }); + it("finds nothing when the package publishes none of them", () => { assert.equal( selectTag({ dev: "0.1.0-dev.1" }, ["next", "latest"]), @@ -229,6 +251,49 @@ describe("computeUpdates", () => { }); }); +describe("compareVersions", () => { + it("orders the version shapes the products publish", () => { + const ascending = [ + "0.40.0", + "0.41.0", + "8.0.0-rc.2", + "8.0.0-rc.10", + "8.0.0", + "8.0.1-dev.40", + "8.0.1", + "8.1.0", + ]; + for (let i = 0; i < ascending.length - 1; i++) { + assert.ok( + compareVersions(ascending[i], ascending[i + 1]) < 0, + `${ascending[i]} < ${ascending[i + 1]}`, + ); + assert.ok(compareVersions(ascending[i + 1], ascending[i]) > 0); + } + assert.equal(compareVersions("8.0.0-rc.26", "8.0.0-rc.26"), 0); + }); +}); + +describe("the release table", () => { + /** + * The ORM, Composer and this CLI publish a release under `rc` and move + * `latest` only once the releases are checked together. Following only + * `latest` would miss a product release until it is promoted, and open + * pull requests that move pins back to the older `latest`. + */ + it("reads rc before latest for every product it asks the registry about", () => { + const asked = new Map(); + publishedVersions("release", (name, tags) => { + asked.set(name, tags); + return "1.0.0"; + }); + assert.ok(asked.size > 0); + for (const [name, tags] of asked) { + assert.deepEqual(tags, ["rc", "latest"], name); + } + }); +}); + describe("publishedVersions", () => { const registry = { "@prisma/composer-cli": "0.41.0", diff --git a/skills-contrib/publish-npm-version/SKILL.md b/skills-contrib/publish-npm-version/SKILL.md index 5a0a3a360..bee057a8e 100644 --- a/skills-contrib/publish-npm-version/SKILL.md +++ b/skills-contrib/publish-npm-version/SKILL.md @@ -5,8 +5,8 @@ description: >- package.json version (on the Prisma 8 RC line: 8.0.0-rc.N → rc.N+1), propagates it to every lockstep workspace package, and opens a PR titled "chore(release): bump to ". When the maintainer - merges the PR, the `Publish to npm` workflow ships @prisma/cli-engine - and @prisma/cli under dist-tag `rc` (RC versions get a + merges the PR, the `Publish to npm` workflow ships prisma and + @prisma/cli under dist-tag `rc` (RC versions get a pre-release GitHub Release). Use when a maintainer asks to "cut the next RC", "cut the next release", "bump to the next version", "open a release PR", or "prepare a publish PR". @@ -91,8 +91,8 @@ succeeds; if not, stop and surface the issue. [`docs/oss/versioning.md`](../../docs/oss/versioning.md); note that **merging this PR ships the release** — the squashed push to `main` changes the root version with the release marker, the `Publish to - npm` workflow publishes `@prisma/cli-engine` then `@prisma/cli` - under `rc`, and a GitHub Release (pre-release on the RC line) is + npm` workflow publishes `@prisma/cli` and `prisma` under `rc` + (the engine, at a new version only, under `latest`), and a GitHub Release (pre-release on the RC line) is created with generated notes. This repo has no committed release-notes file gate; review the generated notes on the Release after merge. From 10587ef48d00278642ba54bf424ed576dee40fd3 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:04:00 +1100 Subject: [PATCH 04/16] ci(release): GitHub marks a release Latest only when promote.yml moves latest The publish workflow creates and publishes every GitHub Release with make_latest=false. promote.yml marks the release Latest when it moves npm's latest, for a stable version; GitHub never marks a pre-release Latest. So GitHub's latest release matches npm's latest. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 14 ++++++++++++++ .github/workflows/publish.yml | 4 +++- docs/oss/versioning.md | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index f079f0a4d..7052d0346 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -56,6 +56,8 @@ jobs: if: ${{ github.ref == 'refs/heads/main' && !inputs.dry-run }} runs-on: ubuntu-latest environment: npm-promote + permissions: + contents: write # Marks the GitHub Release as Latest steps: - name: Set up npm uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 @@ -88,3 +90,15 @@ jobs: fi echo "$pkg latest is $VERSION." done + + # GitHub never marks a pre-release as Latest, so only a stable + # version gets the mark. + - name: Mark the GitHub Release as Latest + if: ${{ !contains(inputs.version, '-') }} + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ inputs.version }} + run: | + release_id=$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/v$VERSION" --jq .id) + gh api -X PATCH "repos/$GITHUB_REPOSITORY/releases/$release_id" -f make_latest=true >/dev/null + echo "GitHub Release v$VERSION is marked Latest." diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a2456e6f4..1db12a534 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -224,6 +224,7 @@ jobs: -f name="v$VERSION" \ -F draft=true \ -F prerelease=$PRERELEASE \ + -f make_latest=false \ -F generate_release_notes=true \ --jq .id) if [ -z "$release_id" ]; then @@ -237,6 +238,7 @@ jobs: "https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id/assets?name=$(basename "$tarball")" \ --input "$tarball" >/dev/null done + # promote.yml marks it Latest when it moves npm's latest. gh api -X PATCH "repos/$GITHUB_REPOSITORY/releases/$release_id" \ - -F draft=false >/dev/null + -F draft=false -f make_latest=false >/dev/null echo "Published release v$VERSION with $(find artifacts/tarballs -name '*.tgz' | wc -l | tr -d ' ') asset(s)." diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index c170ba979..f99adaf27 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -87,7 +87,7 @@ The release cadence is one PR per release (on the RC line: one PR per `rc.N`). A ## Procedure: promote a release to `latest` -[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand from `main` with the version to promote. It first checks that `prisma` and `@prisma/cli` are on npm at that version, and changes nothing if either is missing. A real run then moves `latest` on both and checks that it moved. Running it twice is harmless. A dry run (the default) only does the check. +[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand from `main` with the version to promote. It first checks that `prisma` and `@prisma/cli` are on npm at that version, and changes nothing if either is missing. A real run then moves `latest` on both and checks that it moved. For a stable version it also marks the GitHub Release as Latest: the publish workflow creates every GitHub Release without that mark, so GitHub's latest release matches npm's `latest` (GitHub never marks a pre-release as Latest). Running it twice is harmless. A dry run (the default) only does the check. Trusted publishing, which the publish workflow uses, can set a tag only on the version it is publishing, so moving `latest` on a published version needs an npm token. The repository holds none between promotions, because a stored token that can move a tag can also publish. For each promotion: From ce060546859b40ebdb7f272d8d0f4c677fcf9a01 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:09:43 +1100 Subject: [PATCH 05/16] fix(promote): check the promotion before moving latest; document the environment Round 2 review fixes: - scripts/check-promotion.mjs (tested) refuses unless prisma and @prisma/cli are on npm at the version, the version is not older than latest (allow-older rolls back), and every ORM and Composer version the CLI pins is already latest, so the promotion order is checked. - A run off main fails instead of skipping; the moved-latest check polls. - The docs say to limit the npm-promote environment to main, which is what protects the token, give the token's scope, expiry and package setting, and the release skill points at promotion. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 48 +++++--- docs/oss/release-automation.md | 2 +- docs/oss/versioning.md | 27 +++-- package.json | 2 +- scripts/check-promotion.mjs | 117 ++++++++++++++++++++ scripts/check-promotion.test.mjs | 92 +++++++++++++++ skills-contrib/publish-npm-version/SKILL.md | 4 + 7 files changed, 268 insertions(+), 24 deletions(-) create mode 100644 scripts/check-promotion.mjs create mode 100644 scripts/check-promotion.test.mjs diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 7052d0346..0e0da7060 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -21,6 +21,11 @@ on: required: false default: true type: boolean + allow-older: + description: "Allow moving latest back to an older version (a rollback)." + required: false + default: false + type: boolean concurrency: group: npm-promote @@ -30,25 +35,35 @@ permissions: {} jobs: check: - name: Check the version is published + name: Check the version can be promoted runs-on: ubuntu-latest - if: ${{ github.ref == 'refs/heads/main' }} steps: - - name: Check every package is on npm at the version + - name: Refuse a branch other than main + if: ${{ github.ref != 'refs/heads/main' }} + run: | + echo "promote.yml runs only from main." >&2 + exit 1 + + - name: Checkout + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + persist-credentials: false + + - name: Set up Node.js + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version-file: .node-version + + - name: Check the version can be promoted env: VERSION: ${{ inputs.version }} + ALLOW_OLDER: ${{ inputs.allow-older }} run: | - if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[1-9][0-9]*)?$ ]]; then - echo "\"$VERSION\" is not a release version such as 8.0.0-rc.37 or 8.0.0." >&2 - exit 1 + if [ "$ALLOW_OLDER" = "true" ]; then + node scripts/check-promotion.mjs "$VERSION" --allow-older + else + node scripts/check-promotion.mjs "$VERSION" fi - for pkg in prisma @prisma/cli; do - if ! published=$(npm view "$pkg@$VERSION" version 2>/dev/null) || [ "$published" != "$VERSION" ]; then - echo "$pkg@$VERSION is not on npm; nothing was changed." >&2 - exit 1 - fi - echo "$pkg@$VERSION is on npm (latest is now $(npm view "$pkg" dist-tags.latest))." - done promote: name: Move latest @@ -78,12 +93,17 @@ jobs: npm dist-tag add "$pkg@$VERSION" latest done + # The registry is eventually consistent: poll before calling it a failure. - name: Check latest moved env: VERSION: ${{ inputs.version }} run: | for pkg in prisma @prisma/cli; do - latest=$(npm view "$pkg" dist-tags.latest) + for _ in $(seq 10); do + latest=$(npm view "$pkg" dist-tags.latest) + [ "$latest" = "$VERSION" ] && break + sleep 15 + done if [ "$latest" != "$VERSION" ]; then echo "$pkg latest is $latest, not $VERSION." >&2 exit 1 diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 69a46db78..7e4b7a406 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -1,6 +1,6 @@ # Release automation across the three repositories -The unified CLI is assembled from three repositories. This page explains how a new product version reaches a released CLI without anyone editing a file or approving a release, what the one shared secret is for, and how to repair the machinery when it stops. +The unified CLI is assembled from three repositories. This page explains how a new product version reaches a CLI release under `rc` without anyone editing a file or approving a release (a maintainer then promotes it to `latest`), what the one shared secret is for, and how to repair the machinery when it stops. | Repository | Publishes | Consumed by the CLI as | | --- | --- | --- | diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index f99adaf27..60a37b1c7 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -44,7 +44,7 @@ The npm registry exposes the CLI packages under these dist-tags: - **`next`** — removed from all three packages on 2026-11-30. After the 2026-08-25 cutover nothing moved it. Pushes to `main` publish under `rc` or `dev`, never `next`. The publish workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish (the promote workflow gets around this with a token added for one run; see [Procedure: promote a release to `latest`](#procedure-promote-a-release-to-latest)). Moving it by hand did not happen, so by November it still pointed at `8.0.0-rc.10` and `npx prisma@next` silently installed a CLI 26 releases old. Without the tag, an old `prisma@next` instruction fails with npm's "No matching version found" error, which is better than an out-of-date CLI installed with no warning. Do not add the tag back for the 8.0.0 line, by hand or by dispatching the publish workflow with `dist-tag: next` (when that version is not on the registry yet, it is published under `next` and the tag comes back; when it is, the workflow skips it and leaves the tags alone); new text should say plain `prisma`. - **`beta`** — reserved for hand-cut previews ahead of significant changes, published by dispatching the workflow with that dist-tag. Routine releases do not use this tag. -- **`dev`** — every routine push to `main` publishes `-dev.` here automatically (operator ruling 2026-08-13, superseding the earlier "no dev channel" ruling). The suffix derives from the workflow run number and is stamped ephemerally in CI, never committed, so release versions remain exactly what a commit says. The channel exists so a product's new version reaches a working CLI without a human: every push to `main` ships a dev build. A product release goes further and cuts a real release on its own; see [release automation](./release-automation.md). Only a release for a change in this repository alone is a human act. +- **`dev`** — every routine push to `main` publishes `-dev.` here automatically (operator ruling 2026-08-13, superseding the earlier "no dev channel" ruling). The suffix derives from the workflow run number and is stamped ephemerally in CI, never committed, so release versions remain exactly what a commit says. The channel exists so a product's new version reaches a working CLI without a human: every push to `main` ships a dev build. A product release goes further and cuts a real release on its own; see [release automation](./release-automation.md). Only a release for a change in this repository alone is a human act, and so is promoting any release to `latest`. **Every** run of the publish workflow ships a dev build, including the one that cuts a release — the release publish is an additional half, not an alternative (operator ruling 2026-08-18). When they were alternatives, the release commit was the one merge to `main` that never reached the dev channel, so `dev` named an older version than the release until an unrelated commit landed. The dev build is published as its own version rather than by moving the `dev` tag, because OIDC trusted publishing authorises `npm publish` and nothing else. The dev channel covers `@prisma/cli` and `prisma` only. The engine has no dev builds; [Lockstep across the workspace](#lockstep-across-the-workspace) gives the reasons. @@ -56,6 +56,7 @@ Publishing requires: - **Push access to `main`** — pushing to `main` or merging a release PR is restricted to maintainers. - **A green run of the [`Publish to npm`](../../.github/workflows/publish.yml) workflow.** The workflow uses npm OIDC trusted publishing — no long-lived `NPM_TOKEN` exists in repository secrets, so a leaked secret cannot be used to publish out-of-band. Each published tarball carries an [npm provenance attestation](https://docs.npmjs.com/generating-provenance-statements) tying it to this repository and the workflow run that produced it. +- Moving `latest` takes an npm token that a maintainer adds for one run of [`promote.yml`](../../.github/workflows/promote.yml) and deletes after; see [Procedure: promote a release to `latest`](#procedure-promote-a-release-to-latest). - The workflow only publishes from `main`. Dry-runs are permitted from any branch (see "validate publish changes" below); every step that would mutate external state is independently guarded. ## Mechanism: how we deliver the contract @@ -85,21 +86,31 @@ The release cadence is one PR per release (on the RC line: one PR per `rc.N`). A 2. **Reviews and merges the PR.** This is the point where a human verifies the release is intended — merging the bump PR is the deliberate act that publishes. The resulting push to `main` carries the bumped root `version`, the publish workflow detects the change, publishes under `rc`, and creates a matching GitHub Release (marked pre-release on the RC line). 3. **Checks the published release and promotes it.** Install the new version from npm by its exact number and check it, together with the ORM and Composer releases it ships beside. Then move `latest` to it with [`promote.yml`](../../.github/workflows/promote.yml), as the next section describes. +If the publish needs to be re-run (transient registry failure, etc.), a maintainer can dispatch the [`Publish to npm`](../../.github/workflows/publish.yml) workflow from `main` with an empty `dist-tag` (or `rc`) and `dry-run=false`; the workflow re-publishes the version currently committed at HEAD under `rc`, and because that is the canonical tag it also re-creates the GitHub Release if it is missing. This is the same path used to cut a hand-rolled `beta` (`dist-tag=beta`, no Release). + ## Procedure: promote a release to `latest` -[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand from `main` with the version to promote. It first checks that `prisma` and `@prisma/cli` are on npm at that version, and changes nothing if either is missing. A real run then moves `latest` on both and checks that it moved. For a stable version it also marks the GitHub Release as Latest: the publish workflow creates every GitHub Release without that mark, so GitHub's latest release matches npm's `latest` (GitHub never marks a pre-release as Latest). Running it twice is harmless. A dry run (the default) only does the check. +[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand from `main` with the version to promote. Its check job runs [`scripts/check-promotion.mjs`](../../scripts/check-promotion.mjs), and nothing changes unless every check passes: + +- `prisma` and `@prisma/cli` are on npm at that version. +- The version is not older than their current `latest`. To roll back, run with `allow-older` on. +- Every ORM and Composer version that `@prisma/cli` pins at that version is already `latest`. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. + +A real run then moves `latest` on both packages and polls the registry until it shows the move. For a stable version it also marks the GitHub Release as Latest: the publish workflow creates every GitHub Release without that mark, so GitHub's latest release matches npm's `latest` (GitHub never marks a pre-release as Latest). Running it twice is harmless. A dry run (the default) only does the check, and needs no token. A run from any branch other than `main` fails. -Trusted publishing, which the publish workflow uses, can set a tag only on the version it is publishing, so moving `latest` on a published version needs an npm token. The repository holds none between promotions, because a stored token that can move a tag can also publish. For each promotion: +Trusted publishing, which the publish workflow uses, can set a tag only on the version it is publishing, so moving `latest` on a published version needs an npm token. The repository holds none between promotions, because a stored token that can move a tag can also publish. -1. Create a short-lived granular npm access token with write access to `prisma` and `@prisma/cli` only. -2. Add it as the secret `NPM_TOKEN` of the GitHub environment `npm-promote` (Settings → Environments). -3. Dispatch `promote.yml` with the version and `dry-run` off. When the release ships beside ORM and Composer releases, promote those first: a CLI release pins the products' versions exactly, so a promoted CLI ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not yet `latest`. +Once per repository, an admin creates the GitHub environment `npm-promote` (Settings → Environments) and limits it to `main` (Deployment branches and tags → Selected branches → `main`). The branch check in `promote.yml` does not protect the token on its own: a workflow on another branch can be edited to name the environment, and only the environment's branch rule stops it reading the secret. + +For each promotion: + +1. Create a granular npm access token with read and write access to `prisma` and `@prisma/cli` only, expiring in one day. If either package's publishing access setting disallows tokens, the run fails; the setting must allow them. +2. Add it as the secret `NPM_TOKEN` of the `npm-promote` environment. +3. Dispatch `promote.yml` with the version and `dry-run` off. 4. Delete the secret from the environment and revoke the token on npm. The token is not a dispatch input, because dispatch inputs on a public repository are not treated as secrets. The workflow reads it only in the step that moves the tags. -If the publish needs to be re-run (transient registry failure, etc.), a maintainer can dispatch the [`Publish to npm`](../../.github/workflows/publish.yml) workflow from `main` with an empty `dist-tag` (or `rc`) and `dry-run=false`; the workflow re-publishes the version currently committed at HEAD under `rc`, and because that is the canonical tag it also re-creates the GitHub Release if it is missing. This is the same path used to cut a hand-rolled `beta` (`dist-tag=beta`, no Release). - ## Procedure: validate publish changes The publish workflow's `dry-run` mode (the input default) can be invoked from any branch to validate that the publish pipeline still works after touching `publish.yml`, `set-version.ts`, `determine-version.ts`, or the build scripts. A dry-run exercises `pnpm publish --dry-run` against both CLI packages and skips the registry publish + GitHub Release. diff --git a/package.json b/package.json index 719137f59..a80cea4e6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "lint:fix": "biome check . --write", "bump-version": "node scripts/bump-version.ts", "test": "turbo run test", - "test:scripts": "node --test scripts/determine-version-utils.test.ts scripts/set-version-utils.test.ts scripts/bump-cli-engine-version-utils.test.ts scripts/resolve-package-version.test.mjs scripts/update-product-versions.test.mjs scripts/verify-published.test.mjs scripts/node-engines.test.mjs scripts/check-cloud-deploy-action.test.mjs", + "test:scripts": "node --test scripts/determine-version-utils.test.ts scripts/set-version-utils.test.ts scripts/bump-cli-engine-version-utils.test.ts scripts/resolve-package-version.test.mjs scripts/update-product-versions.test.mjs scripts/verify-published.test.mjs scripts/node-engines.test.mjs scripts/check-cloud-deploy-action.test.mjs scripts/check-promotion.test.mjs", "typecheck": "turbo run typecheck", "prisma-cli": "tsx packages/cli/src/bin.ts", "prisma": "tsx packages/cli/src/bin.ts", diff --git a/scripts/check-promotion.mjs b/scripts/check-promotion.mjs new file mode 100644 index 000000000..fe52804a2 --- /dev/null +++ b/scripts/check-promotion.mjs @@ -0,0 +1,117 @@ +#!/usr/bin/env node + +// What must hold before promote.yml moves `latest` to a version: both CLI +// packages are on npm at it, it is not older than their current `latest` +// unless the promoter asked for that, and the ORM and Composer versions it +// pins are already `latest`, so `npm install prisma` never gets a CLI ahead +// of its products. +// +// Usage: node scripts/check-promotion.mjs [--allow-older] + +import { execFileSync } from "node:child_process"; +import { pathToFileURL } from "node:url"; +import { compareVersions } from "./update-product-versions.mjs"; + +export const PROMOTED = ["prisma", "@prisma/cli"]; + +const RELEASE_VERSION = /^\d+\.\d+\.\d+(-rc\.[1-9]\d*)?$/; +const PRODUCT_PIN = /^@prisma\/(orm|composer)/; +const NPM_NOT_FOUND = /\bE404\b/; + +/** + * Every reason not to promote. Pure; exported for tests. + * + * @param {{ + * version: string; + * allowOlder: boolean; + * cli: Record; + * pins: Record; + * }} state + * @returns {string[]} + */ +export function promotionProblems({ version, allowOlder, cli, pins }) { + if (!RELEASE_VERSION.test(version)) { + return [ + `"${version}" is not a release version such as 8.0.0-rc.37 or 8.0.0.`, + ]; + } + const problems = []; + for (const [name, { published, latest }] of Object.entries(cli)) { + if (!published) { + problems.push(`${name}@${version} is not on npm.`); + } else if ( + !allowOlder && + latest !== undefined && + compareVersions(version, latest) < 0 + ) { + problems.push( + `${name}@${version} is older than its latest, ${latest}. Run again with allow-older to roll back.`, + ); + } + } + for (const [name, { pinned, latest }] of Object.entries(pins)) { + if (pinned !== latest) { + problems.push( + `${version} pins ${name}@${pinned}, but its latest is ${latest ?? "unset"}. Promote the ORM and Composer releases first.`, + ); + } + } + return problems; +} + +function npmView(spec, field) { + try { + const out = execFileSync("npm", ["view", spec, field, "--json"], { + encoding: "utf-8", + stdio: ["ignore", "pipe", "pipe"], + }).trim(); + return out.length === 0 ? undefined : JSON.parse(out); + } catch (error) { + const stderr = typeof error?.stderr === "string" ? error.stderr : ""; + if (NPM_NOT_FOUND.test(stderr)) return undefined; + throw error; + } +} + +function readState(version, allowOlder) { + const cli = {}; + for (const name of PROMOTED) { + cli[name] = { + published: npmView(`${name}@${version}`, "version") === version, + latest: npmView(name, "dist-tags.latest"), + }; + } + const pins = {}; + const dependencies = npmView(`@prisma/cli@${version}`, "dependencies") ?? {}; + for (const [name, pinned] of Object.entries(dependencies)) { + if (PRODUCT_PIN.test(name)) { + pins[name] = { pinned, latest: npmView(name, "dist-tags.latest") }; + } + } + return { version, allowOlder, cli, pins }; +} + +function main() { + const [version, ...flags] = process.argv.slice(2); + if (version === undefined) { + console.error( + "Usage: node scripts/check-promotion.mjs [--allow-older]", + ); + process.exit(1); + } + const allowOlder = flags.includes("--allow-older"); + const problems = RELEASE_VERSION.test(version) + ? promotionProblems(readState(version, allowOlder)) + : promotionProblems({ version, allowOlder, cli: {}, pins: {} }); + for (const problem of problems) console.error(problem); + if (problems.length > 0) { + console.error("Nothing was changed."); + process.exit(1); + } + console.log(`${PROMOTED.join(" and ")} can be promoted to ${version}.`); +} + +const isDirectRun = + process.argv[1] !== undefined && + import.meta.url === pathToFileURL(process.argv[1]).href; +if (isDirectRun) main(); diff --git a/scripts/check-promotion.test.mjs b/scripts/check-promotion.test.mjs new file mode 100644 index 000000000..39e7a2829 --- /dev/null +++ b/scripts/check-promotion.test.mjs @@ -0,0 +1,92 @@ +import assert from "node:assert/strict"; +import { describe, it } from "node:test"; +import { promotionProblems } from "./check-promotion.mjs"; + +const PRODUCTS_FIRST = /Promote the ORM and Composer releases first/; + +const published = (latest) => ({ + prisma: { published: true, latest }, + "@prisma/cli": { published: true, latest }, +}); + +const promotedPins = { + "@prisma/orm-toolchain": { pinned: "8.0.0-rc.26", latest: "8.0.0-rc.26" }, + "@prisma/composer": { pinned: "0.41.0", latest: "0.41.0" }, +}; + +describe("promotionProblems", () => { + it("allows a published, newer version whose products are already latest", () => { + assert.deepEqual( + promotionProblems({ + version: "8.0.0-rc.37", + allowOlder: false, + cli: published("8.0.0-rc.36"), + pins: promotedPins, + }), + [], + ); + }); + + it("allows promoting the version that is already latest, so a second run is harmless", () => { + assert.deepEqual( + promotionProblems({ + version: "8.0.0-rc.37", + allowOlder: false, + cli: published("8.0.0-rc.37"), + pins: promotedPins, + }), + [], + ); + }); + + it("refuses a version that is not on npm", () => { + const problems = promotionProblems({ + version: "8.0.0-rc.37", + allowOlder: false, + cli: { + prisma: { published: true, latest: "8.0.0-rc.36" }, + "@prisma/cli": { published: false, latest: "8.0.0-rc.36" }, + }, + pins: promotedPins, + }); + assert.deepEqual(problems, ["@prisma/cli@8.0.0-rc.37 is not on npm."]); + }); + + it("refuses a version older than latest unless the promoter allows it", () => { + const state = { + version: "8.0.0-rc.35", + cli: published("8.0.0-rc.36"), + pins: promotedPins, + }; + assert.equal(promotionProblems({ ...state, allowOlder: false }).length, 2); + assert.deepEqual(promotionProblems({ ...state, allowOlder: true }), []); + }); + + it("refuses a CLI whose ORM or Composer pins are not latest yet", () => { + const problems = promotionProblems({ + version: "8.0.0-rc.37", + allowOlder: false, + cli: published("8.0.0-rc.36"), + pins: { + ...promotedPins, + "@prisma/orm-toolchain": { + pinned: "8.0.0-rc.26", + latest: "8.0.0-rc.25", + }, + }, + }); + assert.equal(problems.length, 1); + assert.match(problems[0], PRODUCTS_FIRST); + }); + + it("refuses a malformed version before reading anything else", () => { + for (const version of ["8.0.0-rc.37; rm -rf /", "latest", "8.0.0-dev.3"]) { + assert.equal( + promotionProblems({ version, allowOlder: false, cli: {}, pins: {} }) + .length, + 1, + version, + ); + } + }); +}); diff --git a/skills-contrib/publish-npm-version/SKILL.md b/skills-contrib/publish-npm-version/SKILL.md index bee057a8e..9e3f5ffc1 100644 --- a/skills-contrib/publish-npm-version/SKILL.md +++ b/skills-contrib/publish-npm-version/SKILL.md @@ -101,6 +101,10 @@ succeeds; if not, stop and surface the issue. the merge is the human gate that triggers the publish. The maintainer removes the worktree after merge (`git worktree remove ../release-`). +10. **After the publish, the release is on `rc` only.** `npm install + prisma` keeps the previous release until a maintainer checks the + new one and promotes it with `promote.yml`; see "Procedure: promote + a release to `latest`" in `docs/oss/versioning.md`. ## Idempotency From 863c820099a513b87affb99947e920eede7797c4 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:15:30 +1100 Subject: [PATCH 06/16] fix(release): stage releases under next; promote checks before npm changes - The staging dist-tag is `next`, not `rc`: the ORM's docs already use "RC" for a version's release-candidate stage. Every release moves `next`, so it no longer goes stale; the versioning doc says so. The follow script reads `next`, then `latest`. - The promotion secret is NPM_PROMOTE_TOKEN. - check-promotion separates pins newer than latest (promote the products first) from older ones (refused unless rolling back), and its registry reads are injectable and tested. - promote.yml checks the stable version's GitHub Release is published before npm changes, marks it Latest in its own job so the job holding the npm token has no repository write access, and polls the uncached dist-tag endpoint. - The procedure starts with a dry run and names the token's two-factor bypass option and the package setting it needs. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 49 ++++++++++---- .github/workflows/publish.yml | 2 +- .github/workflows/update-product-versions.yml | 2 +- CONTRIBUTING.md | 2 +- README.md | 4 +- docs/oss/release-automation.md | 8 +-- docs/oss/versioning.md | 32 ++++----- docs/reference/glossary.md | 2 +- packages/cli/README.md | 2 +- packages/prisma/README.md | 2 +- scripts/check-promotion.mjs | 39 +++++++---- scripts/check-promotion.test.mjs | 65 ++++++++++++++++++- scripts/determine-version-utils.test.ts | 22 +++---- scripts/determine-version-utils.ts | 8 +-- scripts/update-product-versions.mjs | 14 ++-- scripts/update-product-versions.test.mjs | 28 ++++---- skills-contrib/publish-npm-version/SKILL.md | 6 +- 17 files changed, 198 insertions(+), 89 deletions(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 0e0da7060..b326a4bab 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -1,11 +1,11 @@ name: Promote a release to latest -# A release publishes under `rc` (publish.yml). This moves `latest` for +# A release publishes under `next` (publish.yml). This moves `latest` for # `prisma` and `@prisma/cli` to a version already on npm, once it has # been checked. See docs/oss/versioning.md. # # Trusted publishing cannot move a tag on a published version, so the -# real run needs an npm token. It comes from the secret NPM_TOKEN in the +# real run needs an npm token. It comes from the secret NPM_PROMOTE_TOKEN in the # `npm-promote` environment, which the promoter adds just before a run # and deletes after: the repository holds no token between promotions. @@ -37,6 +37,8 @@ jobs: check: name: Check the version can be promoted runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Refuse a branch other than main if: ${{ github.ref != 'refs/heads/main' }} @@ -65,14 +67,27 @@ jobs: node scripts/check-promotion.mjs "$VERSION" fi + # Checked here, before npm changes, so a missing release cannot + # leave npm and GitHub disagreeing. The by-tag endpoint does not see + # drafts, which is right: a draft cannot be marked Latest. + - name: Check the stable version's GitHub Release is published + if: ${{ !contains(inputs.version, '-') }} + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ inputs.version }} + run: | + if ! gh api "repos/$GITHUB_REPOSITORY/releases/tags/v$VERSION" --jq .id >/dev/null; then + echo "GitHub Release v$VERSION is missing or still a draft; nothing was changed." >&2 + exit 1 + fi + promote: name: Move latest needs: check if: ${{ github.ref == 'refs/heads/main' && !inputs.dry-run }} runs-on: ubuntu-latest environment: npm-promote - permissions: - contents: write # Marks the GitHub Release as Latest + permissions: {} steps: - name: Set up npm uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 @@ -82,39 +97,47 @@ jobs: - name: Move latest env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} VERSION: ${{ inputs.version }} run: | if [ -z "$NODE_AUTH_TOKEN" ]; then - echo "The npm-promote environment has no NPM_TOKEN secret. Add a short-lived granular token there, run again, then delete it." >&2 + echo "The npm-promote environment has no NPM_PROMOTE_TOKEN secret. Add a short-lived granular token there, run again, then delete it." >&2 exit 1 fi for pkg in prisma @prisma/cli; do npm dist-tag add "$pkg@$VERSION" latest done - # The registry is eventually consistent: poll before calling it a failure. + # `npm dist-tag ls` reads the tags uncached; a failed read is retried. - name: Check latest moved env: VERSION: ${{ inputs.version }} run: | for pkg in prisma @prisma/cli; do + latest="" for _ in $(seq 10); do - latest=$(npm view "$pkg" dist-tags.latest) + latest=$(npm dist-tag ls "$pkg" 2>/dev/null | sed -n 's/^latest: //p') || true [ "$latest" = "$VERSION" ] && break - sleep 15 + sleep 30 done if [ "$latest" != "$VERSION" ]; then - echo "$pkg latest is $latest, not $VERSION." >&2 + echo "$pkg latest is ${latest:-unreadable}, not $VERSION." >&2 exit 1 fi echo "$pkg latest is $VERSION." done - # GitHub never marks a pre-release as Latest, so only a stable - # version gets the mark. + # Its own job, so the job holding the npm token cannot write to the + # repository. GitHub never marks a pre-release as Latest. + mark-latest: + name: Mark the GitHub Release as Latest + needs: promote + if: ${{ !contains(inputs.version, '-') }} + runs-on: ubuntu-latest + permissions: + contents: write + steps: - name: Mark the GitHub Release as Latest - if: ${{ !contains(inputs.version, '-') }} env: GH_TOKEN: ${{ github.token }} VERSION: ${{ inputs.version }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1db12a534..09dfaf866 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ on: workflow_dispatch: inputs: dist-tag: - description: "npm dist-tag. Empty = rc, the tag every release publishes under. latest is refused: promote.yml moves it. Pass another tag (e.g. beta) for a hand-cut preview." + description: "npm dist-tag. Empty = next, the tag every release publishes under. latest is refused: promote.yml moves it. Pass another tag (e.g. beta) for a hand-cut preview." required: false default: "" type: string diff --git a/.github/workflows/update-product-versions.yml b/.github/workflows/update-product-versions.yml index 7bb2e27fe..c90c086b7 100644 --- a/.github/workflows/update-product-versions.yml +++ b/.github/workflows/update-product-versions.yml @@ -117,7 +117,7 @@ jobs: git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "$BRANCH" PR_URL=$(gh pr create \ --title "$TITLE" \ - --body "Opened automatically by update-product-versions.yml, following the products' release dist-tags ($SUMMARY). Merging publishes \`prisma@$VERSION\` under \`rc\`, and \`latest\` moves when a maintainer runs promote.yml; the checks on this pull request are what stand between a product release and that CLI release." \ + --body "Opened automatically by update-product-versions.yml, following the products' release dist-tags ($SUMMARY). Merging publishes \`prisma@$VERSION\` under \`next\`, and \`latest\` moves when a maintainer runs promote.yml; the checks on this pull request are what stand between a product release and that CLI release." \ --base main --head "$BRANCH") gh pr merge --auto --squash "$PR_URL" echo "Opened $PR_URL with auto-merge armed." diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8384a53bd..f6f09ccc8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,7 +63,7 @@ The CLI must preserve the unified command model: Releases use `@prisma/cli` (exposing the `prisma-cli` binary) plus its dependency `@prisma/cli-engine`, versioned in lockstep from the root `package.json` on the Prisma 8 RC line (`8.0.0-rc.N`). A merged version-bump PR -publishes under the `rc` dist-tag; `latest` moves when a maintainer promotes the +publishes under the `next` dist-tag; `latest` moves when a maintainer promotes the release with `promote.yml`; see `docs/oss/versioning.md`. The `dev` dist-tag points at the latest successful `main` build, published as diff --git a/README.md b/README.md index 87c32b322..d38357209 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ branches, services, service versions, environment variables, and the Prisma ORM schema and migration workflow. The 8.0.0 release candidates publish as `prisma` (binary `prisma`) and -`@prisma/cli` (binary `prisma-cli`) on the `rc` dist-tag, and move to `latest` +`@prisma/cli` (binary `prisma-cli`) on the `next` dist-tag, and move to `latest` once checked. ## Install @@ -136,7 +136,7 @@ lockstep) is the release source of truth. The workflow publishes Release channels: -- `rc`: every release on the Prisma 8 RC line (`8.0.0-rc.N`), as soon as it publishes. A merged PR that bumps the root version (via `pnpm bump-version`) publishes automatically: a maintainer's release PR, or the version-follow PR a product release opens; `workflow_dispatch` is the manual escape hatch and the dry-run path. +- `next`: every release on the Prisma 8 RC line (`8.0.0-rc.N`), as soon as it publishes. A merged PR that bumps the root version (via `pnpm bump-version`) publishes automatically: a maintainer's release PR, or the version-follow PR a product release opens; `workflow_dispatch` is the manual escape hatch and the dry-run path. - `latest`: the release a maintainer has checked and promoted. See [versioning](docs/oss/versioning.md). - `dev`: latest successful `main` build. Every push to `main` that does not change the root version publishes `-dev.N` under the `dev` dist-tag. diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 7e4b7a406..32d116ebf 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -1,6 +1,6 @@ # Release automation across the three repositories -The unified CLI is assembled from three repositories. This page explains how a new product version reaches a CLI release under `rc` without anyone editing a file or approving a release (a maintainer then promotes it to `latest`), what the one shared secret is for, and how to repair the machinery when it stops. +The unified CLI is assembled from three repositories. This page explains how a new product version reaches a CLI release under `next` without anyone editing a file or approving a release (a maintainer then promotes it to `latest`), what the one shared secret is for, and how to repair the machinery when it stops. | Repository | Publishes | Consumed by the CLI as | | --- | --- | --- | @@ -17,11 +17,11 @@ A **release** of the CLI depends only on **released** versions of the products. ## What happens when a product publishes 1. The product repository's publish workflow finishes and sends a `repository_dispatch` event of type `product-published` to `prisma/prisma-cli`. -2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. The ORM and Composer publish each release under `rc` and move `latest` later, once the releases are checked together, as this repository does (see [versioning.md](versioning.md)). So the script reads `rc` first and falls back to `latest` for a product that does not publish `rc`. Reading `rc` lets a product release reach the CLI as soon as it publishes, and keeps the script from moving pins back to an older `latest` while a release waits to be promoted. `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each other package carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". +2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. The ORM and Composer publish each release under `next` and move `latest` later, once the releases are checked together, as this repository does (see [versioning.md](versioning.md)). So the script reads `next` first and falls back to `latest` for a product that does not publish `next`. Reading `next` lets a product release reach the CLI as soon as it publishes, and keeps the script from moving pins back to an older `latest` while a release waits to be promoted. `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each other package carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". 3. If any pin changed, or `main` holds pins the last release (its `v` tag) did not ship, the workflow bumps the CLI to its next version with `pnpm bump-version` (which also refreshes `pnpm-lock.yaml`), opens a pull request titled `Release : follow the products' released versions: ...`, and arms auto-merge. Every earlier open pull request from this workflow, and every open `Bump to version` release pull request, is closed first: each bumps the same version, so only one can merge. -4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `rc` with the committed product versions, plus the usual `dev` build. `latest` moves when a maintainer promotes the release with [`promote.yml`](../../.github/workflows/promote.yml). +4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `next` with the committed product versions, plus the usual `dev` build. `latest` moves when a maintainer promotes the release with [`promote.yml`](../../.github/workflows/promote.yml). -A product release reaches a CLI release under `rc` with no person in the loop (a maintainer then checks the releases together and promotes them to `latest`), as long as CodeRabbit gives the approval the ruleset requires (see the troubleshooting table when it does not), because a CLI left on an older product version breaks every project on the newer one: `prisma@8.0.0-rc.29` pinned `@prisma/orm-toolchain` 8.0.0-rc.21 for four days after the ORM's rc.22 shipped, while its release pull request waited for a review. A release for a change in this repository alone is still cut by a maintainer (see [versioning.md](versioning.md)). Everything on `main` ships with either kind of release, so `main` must always be releasable. Any commit that changes a product pin on `main`, by hand or not, is released by the next run. +A product release reaches a CLI release under `next` with no person in the loop (a maintainer then checks the releases together and promotes them to `latest`), as long as CodeRabbit gives the approval the ruleset requires (see the troubleshooting table when it does not), because a CLI left on an older product version breaks every project on the newer one: `prisma@8.0.0-rc.29` pinned `@prisma/orm-toolchain` 8.0.0-rc.21 for four days after the ORM's rc.22 shipped, while its release pull request waited for a review. A release for a change in this repository alone is still cut by a maintainer (see [versioning.md](versioning.md)). Everything on `main` ships with either kind of release, so `main` must always be releasable. Any commit that changes a product pin on `main`, by hand or not, is released by the next run. A **daily schedule** runs the same comparison, so a lost dispatch event delays an update by at most a day rather than indefinitely. `workflow_dispatch` runs it on demand. diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 60a37b1c7..2a2cd367b 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -8,9 +8,9 @@ Prisma 8 ships as a release-candidate line ahead of `8.0.0` final: releases are RC respins may include breaking changes until `8.0.0` final ships. There are no patch releases on the RC line — a fix ships as the next `rc.N`. -For `prisma` and `@prisma/cli`, **every release publishes under `rc`, and `latest` moves later**, when a maintainer promotes the version with [`promote.yml`](../../.github/workflows/promote.yml). The ORM and Composer do the same. A CLI release usually ships beside ORM and Composer releases, and the reason for the split is to check those releases together, installed from npm by exact version, before `npm install prisma` gives them to users (December 2026; from the 2026-08-25 cutover until then, every release went straight to `latest`, and before that the RC line lived on `next`). Merging a version-bump PR publishes under `rc`; promoting moves `latest`; both are a maintainer's deliberate act. `@prisma/cli-engine` is the exception: nothing installs it by tag, because every package that uses it pins an exact version, so it still publishes under `latest` at its own version bump. Existing installs are unaffected — lockfiles pin resolved versions. +For `prisma` and `@prisma/cli`, **every release publishes under `next`, and `latest` moves later**, when a maintainer promotes the version with [`promote.yml`](../../.github/workflows/promote.yml). The ORM and Composer do the same. A CLI release usually ships beside ORM and Composer releases, and the reason for the split is to check those releases together, installed from npm by exact version, before `npm install prisma` gives them to users (December 2026; from the 2026-08-25 cutover until then, every release went straight to `latest`, and before that the RC line lived on `next`). Merging a version-bump PR publishes under `next`; promoting moves `latest`; both are a maintainer's deliberate act. `@prisma/cli-engine` is the exception: nothing installs it by tag, because every package that uses it pins an exact version, so it still publishes under `latest` at its own version bump. Existing installs are unaffected — lockfiles pin resolved versions. -**History of the bare `prisma` name.** Its `latest` served Prisma 7 (`7.9.1`) until the 2026-08-25 cutover, so the v8 RC line lived on `next` while it matured. The product-family packages (`@prisma/composer-cli`, `@prisma/orm-toolchain` and their siblings — not this repository's three) were never held back — all new names with no version-7 audience — so they always published releases straight to `latest`, pre-release versions included, and this repository followed `latest` for them (operator ruling 2026-08-17). From December 2026 they publish releases under `rc` like this repository, and it follows `rc`, falling back to `latest` ([release-automation.md](release-automation.md)). +**History of the bare `prisma` name.** Its `latest` served Prisma 7 (`7.9.1`) until the 2026-08-25 cutover, so the v8 RC line lived on `next` while it matured. The product-family packages (`@prisma/composer-cli`, `@prisma/orm-toolchain` and their siblings — not this repository's three) were never held back — all new names with no version-7 audience — so they always published releases straight to `latest`, pre-release versions included, and this repository followed `latest` for them (operator ruling 2026-08-17). From December 2026 they publish releases under `next` like this repository, and it follows `next`, falling back to `latest` ([release-automation.md](release-automation.md)). The transition onto the RC line is a one-time bump from the pre-8 base to `8.0.0-rc.1`; `pnpm bump-version` encodes it (a pre-8 stable base advances to `8.0.0-rc.1`, an RC base advances its counter). @@ -18,7 +18,7 @@ The transition onto the RC line is a one-time bump from the pre-8 base to `8.0.0 Every lockstep workspace package — publishable, private, and the workspace root — carries the same `version`. One read of root [`package.json`](../../package.json) answers "what version is this code?" for the repository. -**Exceptions:** `@prisma/compute` versions independently, pending extraction to another repository (operator ruling 2026-08-10), and keeps its own publish workflow ([`publish-compute.yml`](../../.github/workflows/publish-compute.yml)). `@prisma/cli-engine` also versions independently ([ADR 0004](../architecture/adrs/0004-engine-version-pinning.md), operator ruling 2026-08-13): an engine version means "the engine changed", not "the CLI released", which is what keeps the exact peer pins the product CLI packages hold on it cheap — they change only when the engine actually moves. The engine follows honest pre-1.0 semver (a breaking change bumps the minor); bumping it is one command — `pnpm bump-cli-engine-version ` — which edits `packages/cli-engine/package.json`, the `workspace:` pin in every consumer manifest (`packages/cli`, `packages/prisma`), and the lockfile together, landed as a reviewed commit like any other version change (run it in the PR that changes the engine). Both packages are hard-excluded in [`scripts/set-version.ts`](../../scripts/set-version.ts), which still sweeps their `workspace:` pins on lockstep siblings so those never go stale. At publish time the engine ships at its own manifest version **under `latest`**, on the first publish run that carries the bumped version — normally the merge of the PR that bumped it. That is the rule `prisma` and `@prisma/cli` followed until December 2026 — a deliberately merged version-bump PR publishes a version under `latest` — and the engine keeps it, because nothing installs the engine by tag: every package that uses it pins an exact version. `prisma` and `@prisma/cli` now publish under `rc` and are promoted to `latest` separately. An already-published engine version is a no-op. The engine has no dev builds, for two reasons. First, the product CLI packages peer it at an exact release version, and so do their dev builds, so a dev-stamped engine would satisfy none of them and `npm install prisma@dev` would fail. Second, a dev build would expose nothing: CI refuses any change to the engine's published contents that does not bump its version, and that merge publishes the new version, so merged engine work is never unreleased. (Before 2026-08-26 the workflow published the engine inside the dev-build half under `--tag dev`, so a new engine version reached the registry with its `latest` tag stuck on the previous version until an operator moved it by hand — `0.2.x` and `0.3.0` shipped that way.) The engine's own line continues from `0.1.0` (after the published `0.0.x` series); the `8.0.0-rc.N` engine versions that shipped while it was still in lockstep are burned values — they exist on the registry, nothing pins them, and version numbers are never reused. +**Exceptions:** `@prisma/compute` versions independently, pending extraction to another repository (operator ruling 2026-08-10), and keeps its own publish workflow ([`publish-compute.yml`](../../.github/workflows/publish-compute.yml)). `@prisma/cli-engine` also versions independently ([ADR 0004](../architecture/adrs/0004-engine-version-pinning.md), operator ruling 2026-08-13): an engine version means "the engine changed", not "the CLI released", which is what keeps the exact peer pins the product CLI packages hold on it cheap — they change only when the engine actually moves. The engine follows honest pre-1.0 semver (a breaking change bumps the minor); bumping it is one command — `pnpm bump-cli-engine-version ` — which edits `packages/cli-engine/package.json`, the `workspace:` pin in every consumer manifest (`packages/cli`, `packages/prisma`), and the lockfile together, landed as a reviewed commit like any other version change (run it in the PR that changes the engine). Both packages are hard-excluded in [`scripts/set-version.ts`](../../scripts/set-version.ts), which still sweeps their `workspace:` pins on lockstep siblings so those never go stale. At publish time the engine ships at its own manifest version **under `latest`**, on the first publish run that carries the bumped version — normally the merge of the PR that bumped it. That is the rule `prisma` and `@prisma/cli` followed until December 2026 — a deliberately merged version-bump PR publishes a version under `latest` — and the engine keeps it, because nothing installs the engine by tag: every package that uses it pins an exact version. `prisma` and `@prisma/cli` now publish under `next` and are promoted to `latest` separately. An already-published engine version is a no-op. The engine has no dev builds, for two reasons. First, the product CLI packages peer it at an exact release version, and so do their dev builds, so a dev-stamped engine would satisfy none of them and `npm install prisma@dev` would fail. Second, a dev build would expose nothing: CI refuses any change to the engine's published contents that does not bump its version, and that merge publishes the new version, so merged engine work is never unreleased. (Before 2026-08-26 the workflow published the engine inside the dev-build half under `--tag dev`, so a new engine version reached the registry with its `latest` tag stuck on the previous version until an operator moved it by hand — `0.2.x` and `0.3.0` shipped that way.) The engine's own line continues from `0.1.0` (after the published `0.0.x` series); the `8.0.0-rc.N` engine versions that shipped while it was still in lockstep are burned values — they exist on the registry, nothing pins them, and version numbers are never reused. The lockstep set is: the workspace root, `packages/cli`, `packages/prisma`, `packages/cli-telemetry`, `packages/cli-conformance`, and `packages/tsconfig`. Private packages are never published (`pnpm publish` skips them), but they still version in lockstep so a contributor cloning the repo at any commit sees one consistent answer to "what version is this code?". Workspace-internal dependencies are pinned as `workspace:` (e.g. `workspace:8.0.0-rc.1`); pnpm resolves them locally during development and rewrites them to the exact version at publish time, so every published package carries an exact-version pin on its siblings. @@ -28,7 +28,7 @@ How the packages published by *other* repositories relate to the engine's versio **A release of the CLI depends only on released versions of the products; a dev build of the CLI depends on their dev builds** (operator ruling 2026-08-17). The two channels are kept apart by two mechanisms: -- The committed manifests hold the products' **released** versions, and [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) keeps them current — so `main` always points at released versions, and every version change is a pull request that CI has tested. That workflow also releases the CLI, so a product release reaches npm under `rc` without a maintainer ([release-automation.md](release-automation.md)). A release publish uses those pins exactly as committed, which is what keeps a release reproducible from its tag. Pointing at released versions is not the same as being ready to release: a released version can still be unusable, and what proves the difference is the conformance checks passing on the release channel. +- The committed manifests hold the products' **released** versions, and [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) keeps them current — so `main` always points at released versions, and every version change is a pull request that CI has tested. That workflow also releases the CLI, so a product release reaches npm under `next` without a maintainer ([release-automation.md](release-automation.md)). A release publish uses those pins exactly as committed, which is what keeps a release reproducible from its tag. Pointing at released versions is not the same as being ready to release: a released version can still be unusable, and what proves the difference is the conformance checks passing on the release channel. - A **dev** publish rewrites them to each product's `dev` dist-tag in CI, ephemerally, exactly as it rewrites the CLI's own version. The build and the conformance checks run after that rewrite, in the same run, so a broken product dev build fails the dev publish instead of shipping inside it. This is enforced, not remembered: the conformance checks refuse to publish a release whose dependencies include any `-dev.` version. `prisma@8.0.0-rc.3` shipped two of them — `@prisma/composer@0.6.0-dev.16` and `@prisma/orm-toolchain@8.0.0-rc.1-dev.40` — because nothing looked. @@ -40,8 +40,8 @@ This is enforced, not remembered: the conformance checks refuse to publish a rel The npm registry exposes the CLI packages under these dist-tags: - **`latest`** — what a bare `npm install` gets: the newest promoted release, RC or stable. Only promoting a release moves it. A publish dispatch refuses `latest` as its dist-tag. From the 2026-08-25 cutover until December 2026 a merged release PR published here directly; before the cutover `latest` stayed on the pre-8 CLI and the RC line lived on `next`. -- **`rc`** — every release, as soon as it publishes. A merged release PR publishes here automatically. It is ahead of `latest` while a release waits to be checked and promoted, and the same version once promoted. Every release moves it, so it does not go stale the way `next` did. -- **`next`** — removed from all three packages on 2026-11-30. After the 2026-08-25 cutover nothing moved it. Pushes to `main` publish under `rc` or `dev`, never `next`. The publish workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish (the promote workflow gets around this with a token added for one run; see [Procedure: promote a release to `latest`](#procedure-promote-a-release-to-latest)). Moving it by hand did not happen, so by November it still pointed at `8.0.0-rc.10` and `npx prisma@next` silently installed a CLI 26 releases old. Without the tag, an old `prisma@next` instruction fails with npm's "No matching version found" error, which is better than an out-of-date CLI installed with no warning. Do not add the tag back for the 8.0.0 line, by hand or by dispatching the publish workflow with `dist-tag: next` (when that version is not on the registry yet, it is published under `next` and the tag comes back; when it is, the workflow skips it and leaves the tags alone); new text should say plain `prisma`. +- **`next`** — every release, as soon as it publishes: a merged release PR publishes here automatically, and nothing else does. It is ahead of `latest` while a release waits to be checked and promoted, and names the same version once promoted. It does not go stale, because every release moves it. History: from the 2026-08-25 cutover until December 2026 releases went straight to `latest`, nothing moved `next`, and by November it still pointed at `8.0.0-rc.10`, so `npx prisma@next` silently installed a CLI 26 releases old. It was removed on 2026-11-30 for that reason, and came back as the staging tag in December 2026. It is called `next` and not `rc` because the ORM's docs already use "RC" for the release-candidate stage of a version. +- The publish workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish. That is why promotion uses a token added for one run; see [Procedure: promote a release to `latest`](#procedure-promote-a-release-to-latest). - **`beta`** — reserved for hand-cut previews ahead of significant changes, published by dispatching the workflow with that dist-tag. Routine releases do not use this tag. - **`dev`** — every routine push to `main` publishes `-dev.` here automatically (operator ruling 2026-08-13, superseding the earlier "no dev channel" ruling). The suffix derives from the workflow run number and is stamped ephemerally in CI, never committed, so release versions remain exactly what a commit says. The channel exists so a product's new version reaches a working CLI without a human: every push to `main` ships a dev build. A product release goes further and cuts a real release on its own; see [release automation](./release-automation.md). Only a release for a change in this repository alone is a human act, and so is promoting any release to `latest`. @@ -70,7 +70,7 @@ This is by design. The alternatives cause silent problems: [`scripts/set-version.ts`](../../scripts/set-version.ts) is what enforces lockstep: a single invocation walks every lockstep workspace `package.json` and writes the requested version (rewriting `workspace:` dependency pins to match). It is a maintainer's tool, invoked through `pnpm bump-version`; the publish workflow does not run it. -The publish workflow is **triggered by a change to the root `version`**: a push to `main` whose root `package.json` carries a different `version` than the previous tip is recognised as a release bump and ships that version under `rc` (the accompanying GitHub Release is marked pre-release on the RC line). This is what makes "merge the release PR" the publish trigger; there is no separate dispatch step. Every push publishes a `dev` build; one that changes the version publishes a release as well (operator ruling 2026-08-18). Within a publish, `@prisma/cli-engine` goes first, then `@prisma/cli` (which depends on it), then `prisma`. +The publish workflow is **triggered by a change to the root `version`**: a push to `main` whose root `package.json` carries a different `version` than the previous tip is recognised as a release bump and ships that version under `next` (the accompanying GitHub Release is marked pre-release on the RC line). This is what makes "merge the release PR" the publish trigger; there is no separate dispatch step. Every push publishes a `dev` build; one that changes the version publishes a release as well (operator ruling 2026-08-18). Within a publish, `@prisma/cli-engine` goes first, then `@prisma/cli` (which depends on it), then `prisma`. **Nothing rewrites a `version` field outside a commit.** `set-version.ts` is run by `pnpm bump-version`, whose output is committed by a maintainer or by `update-product-versions.yml`; the publish workflow never invokes it. That is what makes "the version is whatever `package.json` says" true rather than aspirational — CI has no way to ship a version no commit describes. It also keeps `pnpm-lock.yaml` honest: the lockfile records the `workspace:` specifiers that `set-version.ts` rewrites, so `bump-version` refreshes it in the same breath and the bump lands as one internally consistent commit. @@ -83,10 +83,10 @@ Before anything reaches the registry, the workflow verifies the artifact it is a The release cadence is one PR per release (on the RC line: one PR per `rc.N`). A product release cuts its own CLI release ([release-automation.md](release-automation.md)). For a change in this repository alone, a maintainer: 1. **Runs the [`publish-npm-version` skill](../../skills-contrib/publish-npm-version/SKILL.md)**, which drives `pnpm bump-version` in a fresh worktree off `origin/main` and opens the release PR under real maintainer credentials (so CI runs on it normally). The script reads the root version committed at HEAD, computes the next release version (`8.0.0-rc.N` → `8.0.0-rc.N+1`), and writes it to every lockstep `package.json`. `bump-version` refreshes `pnpm-lock.yaml` itself, because the lockfile records the `workspace:` pins it rewrites and a stale one fails every later frozen install. Commit both and open a `chore(release): 8.0.0-rc.N+1` PR. -2. **Reviews and merges the PR.** This is the point where a human verifies the release is intended — merging the bump PR is the deliberate act that publishes. The resulting push to `main` carries the bumped root `version`, the publish workflow detects the change, publishes under `rc`, and creates a matching GitHub Release (marked pre-release on the RC line). +2. **Reviews and merges the PR.** This is the point where a human verifies the release is intended — merging the bump PR is the deliberate act that publishes. The resulting push to `main` carries the bumped root `version`, the publish workflow detects the change, publishes under `next`, and creates a matching GitHub Release (marked pre-release on the RC line). 3. **Checks the published release and promotes it.** Install the new version from npm by its exact number and check it, together with the ORM and Composer releases it ships beside. Then move `latest` to it with [`promote.yml`](../../.github/workflows/promote.yml), as the next section describes. -If the publish needs to be re-run (transient registry failure, etc.), a maintainer can dispatch the [`Publish to npm`](../../.github/workflows/publish.yml) workflow from `main` with an empty `dist-tag` (or `rc`) and `dry-run=false`; the workflow re-publishes the version currently committed at HEAD under `rc`, and because that is the canonical tag it also re-creates the GitHub Release if it is missing. This is the same path used to cut a hand-rolled `beta` (`dist-tag=beta`, no Release). +If the publish needs to be re-run (transient registry failure, etc.), a maintainer can dispatch the [`Publish to npm`](../../.github/workflows/publish.yml) workflow from `main` with an empty `dist-tag` (or `next`) and `dry-run=false`; the workflow re-publishes the version currently committed at HEAD under `next`, and because that is the canonical tag it also re-creates the GitHub Release if it is missing. This is the same path used to cut a hand-rolled `beta` (`dist-tag=beta`, no Release). ## Procedure: promote a release to `latest` @@ -94,9 +94,10 @@ If the publish needs to be re-run (transient registry failure, etc.), a maintain - `prisma` and `@prisma/cli` are on npm at that version. - The version is not older than their current `latest`. To roll back, run with `allow-older` on. -- Every ORM and Composer version that `@prisma/cli` pins at that version is already `latest`. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. +- For a stable version, its GitHub Release is published (not a draft), so marking it Latest cannot fail after npm has changed. +- Every ORM and Composer version that `@prisma/cli` pins at that version is exactly `latest`. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. A CLI that pins older products than `latest` is refused too, except in a rollback. -A real run then moves `latest` on both packages and polls the registry until it shows the move. For a stable version it also marks the GitHub Release as Latest: the publish workflow creates every GitHub Release without that mark, so GitHub's latest release matches npm's `latest` (GitHub never marks a pre-release as Latest). Running it twice is harmless. A dry run (the default) only does the check, and needs no token. A run from any branch other than `main` fails. +A real run then moves `latest` on both packages and polls the registry until it shows the move. For a stable version a separate job then marks the GitHub Release as Latest (separate so the job that holds the npm token cannot write to the repository): the publish workflow creates every GitHub Release without that mark, so GitHub's latest release matches npm's `latest` (GitHub never marks a pre-release as Latest). Running it twice is harmless. A dry run (the default) only does the check, and needs no token. A run from any branch other than `main` fails. Trusted publishing, which the publish workflow uses, can set a tag only on the version it is publishing, so moving `latest` on a published version needs an npm token. The repository holds none between promotions, because a stored token that can move a tag can also publish. @@ -104,10 +105,11 @@ Once per repository, an admin creates the GitHub environment `npm-promote` (Sett For each promotion: -1. Create a granular npm access token with read and write access to `prisma` and `@prisma/cli` only, expiring in one day. If either package's publishing access setting disallows tokens, the run fails; the setting must allow them. -2. Add it as the secret `NPM_TOKEN` of the `npm-promote` environment. -3. Dispatch `promote.yml` with the version and `dry-run` off. -4. Delete the secret from the environment and revoke the token on npm. +1. Dispatch `promote.yml` with the version and `dry-run` on (the default). It needs no token, and shows whether the checks pass. +2. Create a granular npm access token with read and write access to `prisma` and `@prisma/cli` only, expiring in one day, with "Bypass two-factor authentication" ticked: moving a tag is a write, and npm asks a token without that option for a one-time code it cannot give. This works while each package's publishing access setting is npm's default, "Require two-factor authentication or a granular access token with bypass 2FA enabled". Do not loosen that setting for a promotion; under "disallow tokens" the run fails, and the fix is a person running `npm dist-tag add` with their own two-factor code instead. +3. Add the token as the secret `NPM_PROMOTE_TOKEN` of the `npm-promote` environment. +4. Dispatch `promote.yml` again with `dry-run` off. +5. Delete the secret from the environment and revoke the token on npm. The token is not a dispatch input, because dispatch inputs on a public repository are not treated as secrets. The workflow reads it only in the step that moves the tags. diff --git a/docs/reference/glossary.md b/docs/reference/glossary.md index 24b87254d..2f84336a6 100644 --- a/docs/reference/glossary.md +++ b/docs/reference/glossary.md @@ -26,7 +26,7 @@ output, and implementation. | Structured output | Explicit `--json` output intended for automation. | [Output conventions](../product/output-conventions.md) | | Human output | Status, prompts, summaries, and decoration intended for terminal users. | [Output conventions](../product/output-conventions.md) | | Error code | Stable machine-readable failure code. | [Error conventions](../product/error-conventions.md) | -| Beta package | Public prerelease package line for `@prisma/cli`; the RC line publishes on the `rc` dist-tag and moves to `latest` once checked (see [versioning](../oss/versioning.md)). | [ADR 0001](../architecture/adrs/0001-preview-package-and-publishing.md) | +| Beta package | Public prerelease package line for `@prisma/cli`; the RC line publishes on the `next` dist-tag and moves to `latest` once checked (see [versioning](../oss/versioning.md)). | [ADR 0001](../architecture/adrs/0001-preview-package-and-publishing.md) | | Dev package | Latest successful `main` build of `@prisma/cli` on the `dev` dist-tag. | [ADR 0001](../architecture/adrs/0001-preview-package-and-publishing.md) | | PR preview package | Installable pkg.pr.new package for a trusted same-repo pull request commit. | [ADR 0001](../architecture/adrs/0001-preview-package-and-publishing.md) | diff --git a/packages/cli/README.md b/packages/cli/README.md index bf66a8dac..da6248bc3 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -107,7 +107,7 @@ npx prisma-cli service version promote VERSION_ID - Requires Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer. - This is a release-candidate package and may change quickly. -- The 8.0.0 release candidates publish as `@prisma/cli` on the `rc` dist-tag, and move to `latest` once checked. +- The 8.0.0 release candidates publish as `@prisma/cli` on the `next` dist-tag, and move to `latest` once checked. - The package binary is `prisma-cli`; the sibling `prisma` package ships the same CLI under the `prisma` binary. - Local project context is cached in `.prisma/local.json`, which is gitignored and not a declarative repo config file. diff --git a/packages/prisma/README.md b/packages/prisma/README.md index 8108879af..0a81c7e64 100644 --- a/packages/prisma/README.md +++ b/packages/prisma/README.md @@ -104,7 +104,7 @@ npx prisma service version promote VERSION_ID - Requires Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer. - This is a release-candidate package and may change quickly. -- The 8.0.0 release candidates publish as `prisma` on the `rc` dist-tag, and move to `latest` once checked. +- The 8.0.0 release candidates publish as `prisma` on the `next` dist-tag, and move to `latest` once checked. - The package binary is `prisma`. - Local project context is cached in `.prisma/local.json`, which is gitignored and not a declarative repo config file. diff --git a/scripts/check-promotion.mjs b/scripts/check-promotion.mjs index fe52804a2..1b8bc1208 100644 --- a/scripts/check-promotion.mjs +++ b/scripts/check-promotion.mjs @@ -3,20 +3,23 @@ // What must hold before promote.yml moves `latest` to a version: both CLI // packages are on npm at it, it is not older than their current `latest` // unless the promoter asked for that, and the ORM and Composer versions it -// pins are already `latest`, so `npm install prisma` never gets a CLI ahead -// of its products. +// pins are exactly `latest`, so `npm install prisma` gets a CLI that +// matches the products users install. A rollback (--allow-older) may pin +// older products, never newer ones. // // Usage: node scripts/check-promotion.mjs [--allow-older] import { execFileSync } from "node:child_process"; import { pathToFileURL } from "node:url"; -import { compareVersions } from "./update-product-versions.mjs"; +import { + compareVersions, + isPackageAbsent, +} from "./update-product-versions.mjs"; export const PROMOTED = ["prisma", "@prisma/cli"]; const RELEASE_VERSION = /^\d+\.\d+\.\d+(-rc\.[1-9]\d*)?$/; const PRODUCT_PIN = /^@prisma\/(orm|composer)/; -const NPM_NOT_FOUND = /\bE404\b/; /** * Every reason not to promote. Pure; exported for tests. @@ -50,15 +53,20 @@ export function promotionProblems({ version, allowOlder, cli, pins }) { } } for (const [name, { pinned, latest }] of Object.entries(pins)) { - if (pinned !== latest) { + if (latest === undefined || compareVersions(pinned, latest) > 0) { problems.push( `${version} pins ${name}@${pinned}, but its latest is ${latest ?? "unset"}. Promote the ORM and Composer releases first.`, ); + } else if (!allowOlder && compareVersions(pinned, latest) < 0) { + problems.push( + `${version} pins ${name}@${pinned}, older than its latest, ${latest}. Promote a CLI release that pins ${latest}, or run with allow-older to roll back.`, + ); } } return problems; } +/** `npm view `, or undefined when the package or version does not exist. */ function npmView(spec, field) { try { const out = execFileSync("npm", ["view", spec, field, "--json"], { @@ -68,24 +76,31 @@ function npmView(spec, field) { return out.length === 0 ? undefined : JSON.parse(out); } catch (error) { const stderr = typeof error?.stderr === "string" ? error.stderr : ""; - if (NPM_NOT_FOUND.test(stderr)) return undefined; + if (isPackageAbsent(stderr)) return undefined; throw error; } } -function readState(version, allowOlder) { +/** + * What promotionProblems needs, read through `view`. Exported for tests. + * + * @param {string} version + * @param {boolean} allowOlder + * @param {(spec: string, field: string) => unknown} view + */ +export function readState(version, allowOlder, view) { const cli = {}; for (const name of PROMOTED) { cli[name] = { - published: npmView(`${name}@${version}`, "version") === version, - latest: npmView(name, "dist-tags.latest"), + published: view(`${name}@${version}`, "version") === version, + latest: view(name, "dist-tags.latest"), }; } const pins = {}; - const dependencies = npmView(`@prisma/cli@${version}`, "dependencies") ?? {}; + const dependencies = view(`@prisma/cli@${version}`, "dependencies") ?? {}; for (const [name, pinned] of Object.entries(dependencies)) { if (PRODUCT_PIN.test(name)) { - pins[name] = { pinned, latest: npmView(name, "dist-tags.latest") }; + pins[name] = { pinned, latest: view(name, "dist-tags.latest") }; } } return { version, allowOlder, cli, pins }; @@ -101,7 +116,7 @@ function main() { } const allowOlder = flags.includes("--allow-older"); const problems = RELEASE_VERSION.test(version) - ? promotionProblems(readState(version, allowOlder)) + ? promotionProblems(readState(version, allowOlder, npmView)) : promotionProblems({ version, allowOlder, cli: {}, pins: {} }); for (const problem of problems) console.error(problem); if (problems.length > 0) { diff --git a/scripts/check-promotion.test.mjs b/scripts/check-promotion.test.mjs index 39e7a2829..0c50d20ae 100644 --- a/scripts/check-promotion.test.mjs +++ b/scripts/check-promotion.test.mjs @@ -1,8 +1,9 @@ import assert from "node:assert/strict"; import { describe, it } from "node:test"; -import { promotionProblems } from "./check-promotion.mjs"; +import { promotionProblems, readState } from "./check-promotion.mjs"; const PRODUCTS_FIRST = /Promote the ORM and Composer releases first/; +const OLDER_PIN = /older than its latest, 8.0.0-rc.26/; const published = (latest) => ({ prisma: { published: true, latest }, @@ -89,4 +90,66 @@ describe("promotionProblems", () => { ); } }); + + it("refuses a CLI that pins an older product than latest, unless it is a rollback", () => { + const state = { + version: "8.0.0-rc.37", + cli: published("8.0.0-rc.36"), + pins: { + "@prisma/orm-toolchain": { + pinned: "8.0.0-rc.25", + latest: "8.0.0-rc.26", + }, + }, + }; + const problems = promotionProblems({ ...state, allowOlder: false }); + assert.equal(problems.length, 1); + assert.match(problems[0], OLDER_PIN); + assert.deepEqual(promotionProblems({ ...state, allowOlder: true }), []); + }); + + it("refuses a rollback whose pins are newer than the products' latest", () => { + const problems = promotionProblems({ + version: "8.0.0-rc.30", + allowOlder: true, + cli: published("8.0.0-rc.36"), + pins: { + "@prisma/orm-toolchain": { + pinned: "8.0.0-rc.27", + latest: "8.0.0-rc.26", + }, + }, + }); + assert.match(problems[0], PRODUCTS_FIRST); + }); +}); + +describe("readState", () => { + const registry = { + "prisma@8.0.0-rc.37 version": "8.0.0-rc.37", + "prisma dist-tags.latest": "8.0.0-rc.36", + "@prisma/cli dist-tags.latest": "8.0.0-rc.36", + "@prisma/cli@8.0.0-rc.37 dependencies": { + "@prisma/orm-toolchain": "8.0.0-rc.26", + "@prisma/composer": "0.41.0", + "@prisma/cli-engine": "0.10.4", + effect: "4.1.4", + }, + "@prisma/orm-toolchain dist-tags.latest": "8.0.0-rc.26", + "@prisma/composer dist-tags.latest": "0.41.0", + }; + const view = (spec, field) => registry[`${spec} ${field}`]; + + it("checks only the ORM and Composer pins, not the engine or third-party packages", () => { + assert.deepEqual(Object.keys(readState("8.0.0-rc.37", false, view).pins), [ + "@prisma/orm-toolchain", + "@prisma/composer", + ]); + }); + + it("reports a version npm does not have as unpublished", () => { + const { cli } = readState("8.0.0-rc.37", false, view); + assert.equal(cli.prisma.published, true); + assert.equal(cli["@prisma/cli"].published, false); + }); }); diff --git a/scripts/determine-version-utils.test.ts b/scripts/determine-version-utils.test.ts index bc29aa517..347b1df30 100644 --- a/scripts/determine-version-utils.test.ts +++ b/scripts/determine-version-utils.test.ts @@ -144,14 +144,14 @@ describe("assertCanonicalBase", () => { }); describe("releaseDistTag", () => { - it("sends an RC-line bump to rc, never latest", () => { - assert.equal(releaseDistTag("8.0.0-rc.1"), "rc"); - assert.equal(releaseDistTag("8.0.0-rc.12"), "rc"); + it("sends an RC-line bump to next, never latest", () => { + assert.equal(releaseDistTag("8.0.0-rc.1"), "next"); + assert.equal(releaseDistTag("8.0.0-rc.12"), "next"); }); - it("sends a stable bump to rc, never latest", () => { - assert.equal(releaseDistTag("8.0.0"), "rc"); - assert.equal(releaseDistTag("8.1.0"), "rc"); + it("sends a stable bump to next, never latest", () => { + assert.equal(releaseDistTag("8.0.0"), "next"); + assert.equal(releaseDistTag("8.1.0"), "next"); }); it("refuses a non-canonical base", () => { @@ -182,14 +182,14 @@ describe("isReleasePublish", () => { }); it("a publish under the base's canonical tag is a release", () => { - assert.equal(isReleasePublish("8.0.0-rc.2", "rc"), true); - assert.equal(isReleasePublish("8.1.0", "rc"), true); + assert.equal(isReleasePublish("8.0.0-rc.2", "next"), true); + assert.equal(isReleasePublish("8.1.0", "next"), true); }); it("a beta or off-tag publish is not a release", () => { assert.equal(isReleasePublish("8.0.0-rc.2", "beta"), false); assert.equal(isReleasePublish("8.0.0-rc.2", "latest"), false); - assert.equal(isReleasePublish("8.0.0-rc.2", "next"), false); + assert.equal(isReleasePublish("8.0.0-rc.2", "rc"), false); }); }); @@ -198,8 +198,8 @@ describe("assertDispatchDistTag", () => { assert.throws(() => assertDispatchDistTag("latest"), LATEST_REFUSED); }); - it("accepts rc and a hand-cut preview tag", () => { - for (const tag of ["rc", "beta"]) { + it("accepts next and a hand-cut preview tag", () => { + for (const tag of ["next", "beta"]) { assert.doesNotThrow(() => assertDispatchDistTag(tag)); } }); diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index c6b6eeba1..a73acf2ed 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -116,15 +116,15 @@ export function assertValidDistTag(tag: string): void { } /** - * The dist-tag a release publishes under: `rc`. A release reaches npm + * The dist-tag a release publishes under: `next`. A release reaches npm * without moving `latest`, so it can be checked from the registry, with * the ORM and Composer releases it ships beside, before users get it. * promote.yml moves `latest` afterwards. From the 2026-08-25 * cutover until December 2026, releases went straight to `latest`. */ -export function releaseDistTag(base: string): "rc" { +export function releaseDistTag(base: string): "next" { assertCanonicalBase(base); - return "rc"; + return "next"; } /** @@ -135,7 +135,7 @@ export function assertDispatchDistTag(tag: string): void { assertValidDistTag(tag); if (tag === "latest") { throw new Error( - 'A publish dispatch cannot use "latest": a release publishes under "rc", and promote.yml moves "latest" afterwards.', + 'A publish dispatch cannot use "latest": a release publishes under "next", and promote.yml moves "latest" afterwards.', ); } } diff --git a/scripts/update-product-versions.mjs b/scripts/update-product-versions.mjs index 1a37e9412..26c2566e9 100644 --- a/scripts/update-product-versions.mjs +++ b/scripts/update-product-versions.mjs @@ -35,31 +35,31 @@ import { fileURLToPath } from "node:url"; // Where each product publishes its releases, most-preferred tag first: // the first tag that exists wins. From December 2026 the ORM, Composer -// and this CLI publish each release under `rc` and move `latest` later, -// once the releases are checked together. Following `rc` lets a product +// and this CLI publish each release under `next` and move `latest` later, +// once the releases are checked together. Following `next` lets a product // release reach the CLI when it publishes, and keeps this script from // moving pins back to an older `latest` while a release waits to be // promoted. `latest` remains the fallback for a product that does not -// publish `rc` yet. +// publish `next` yet. // // A list rather than a single tag name because asking for one tag is // what made the previous version of this script silently never update // the ORM: it asked for `next`, which no prisma/prisma package has ever // had, and a missing tag was indistinguishable from a missing package. const WATCHED = /** @type {const} */ ([ - { name: "@prisma/composer-cli", release: ["rc", "latest"] }, + { name: "@prisma/composer-cli", release: ["next", "latest"] }, // The library. `deploy` builds a Composer config with it for a // repository that has none, and the startup probe imports it to prove // the eager-loading detector works. It must move with the CLI package // it ships beside, or the install resolves a second copy. - { name: "@prisma/composer", release: ["rc", "latest"] }, + { name: "@prisma/composer", release: ["next", "latest"] }, // The Prisma Cloud target that the same `deploy` path loads. Composer // publishes it with the CLI package at one version. { name: "@prisma/composer-prisma-cloud", sameVersionAs: "@prisma/composer-cli", }, - { name: "@prisma/orm-toolchain", release: ["rc", "latest"] }, + { name: "@prisma/orm-toolchain", release: ["next", "latest"] }, // The shell lists the framework so it does not rely on the toolchain // bringing it; from the ORM release after 8.0.0-rc.25 the toolchain // names it as an exact peer. It takes @@ -149,7 +149,7 @@ function splitVersion(version) { /** * The newest version among the candidate tags the package publishes, * the earlier candidate winning a tie. Taking the newest rather than the - * first tag that exists means a stale `rc` behind `latest` never moves a + * first tag that exists means a stale `next` behind `latest` never moves a * pin backwards. Pure; exported for tests. * * @param {Record} distTags diff --git a/scripts/update-product-versions.test.mjs b/scripts/update-product-versions.test.mjs index 3c3e9cdfe..3b2e5ce1e 100644 --- a/scripts/update-product-versions.test.mjs +++ b/scripts/update-product-versions.test.mjs @@ -53,23 +53,29 @@ describe("selectTag", () => { ); }); - it("takes rc while a release waits to be promoted", () => { + it("takes next while a release waits to be promoted", () => { assert.deepEqual( - selectTag({ rc: "8.0.0-rc.26", latest: "8.0.0-rc.25" }, ["rc", "latest"]), - { tag: "rc", version: "8.0.0-rc.26" }, + selectTag({ next: "8.0.0-rc.26", latest: "8.0.0-rc.25" }, [ + "next", + "latest", + ]), + { tag: "next", version: "8.0.0-rc.26" }, ); }); - it("takes rc once it and latest name the same version", () => { + it("takes next once it and latest name the same version", () => { assert.deepEqual( - selectTag({ rc: "0.41.0", latest: "0.41.0" }, ["rc", "latest"]), - { tag: "rc", version: "0.41.0" }, + selectTag({ next: "0.41.0", latest: "0.41.0" }, ["next", "latest"]), + { tag: "next", version: "0.41.0" }, ); }); - it("never takes a stale rc behind latest, so no pin moves backwards", () => { + it("never takes a stale next behind latest, so no pin moves backwards", () => { assert.deepEqual( - selectTag({ rc: "8.0.0-rc.25", latest: "8.0.0-rc.27" }, ["rc", "latest"]), + selectTag({ next: "8.0.0-rc.25", latest: "8.0.0-rc.27" }, [ + "next", + "latest", + ]), { tag: "latest", version: "8.0.0-rc.27" }, ); }); @@ -276,12 +282,12 @@ describe("compareVersions", () => { describe("the release table", () => { /** - * The ORM, Composer and this CLI publish a release under `rc` and move + * The ORM, Composer and this CLI publish a release under `next` and move * `latest` only once the releases are checked together. Following only * `latest` would miss a product release until it is promoted, and open * pull requests that move pins back to the older `latest`. */ - it("reads rc before latest for every product it asks the registry about", () => { + it("reads next before latest for every product it asks the registry about", () => { const asked = new Map(); publishedVersions("release", (name, tags) => { asked.set(name, tags); @@ -289,7 +295,7 @@ describe("the release table", () => { }); assert.ok(asked.size > 0); for (const [name, tags] of asked) { - assert.deepEqual(tags, ["rc", "latest"], name); + assert.deepEqual(tags, ["next", "latest"], name); } }); }); diff --git a/skills-contrib/publish-npm-version/SKILL.md b/skills-contrib/publish-npm-version/SKILL.md index 9e3f5ffc1..34e39534d 100644 --- a/skills-contrib/publish-npm-version/SKILL.md +++ b/skills-contrib/publish-npm-version/SKILL.md @@ -6,7 +6,7 @@ description: >- propagates it to every lockstep workspace package, and opens a PR titled "chore(release): bump to ". When the maintainer merges the PR, the `Publish to npm` workflow ships prisma and - @prisma/cli under dist-tag `rc` (RC versions get a + @prisma/cli under dist-tag `next` (RC versions get a pre-release GitHub Release). Use when a maintainer asks to "cut the next RC", "cut the next release", "bump to the next version", "open a release PR", or "prepare a publish PR". @@ -91,7 +91,7 @@ succeeds; if not, stop and surface the issue. [`docs/oss/versioning.md`](../../docs/oss/versioning.md); note that **merging this PR ships the release** — the squashed push to `main` changes the root version with the release marker, the `Publish to - npm` workflow publishes `@prisma/cli` and `prisma` under `rc` + npm` workflow publishes `@prisma/cli` and `prisma` under `next` (the engine, at a new version only, under `latest`), and a GitHub Release (pre-release on the RC line) is created with generated notes. This repo has no committed release-notes file gate; review the generated notes on the Release @@ -101,7 +101,7 @@ succeeds; if not, stop and surface the issue. the merge is the human gate that triggers the publish. The maintainer removes the worktree after merge (`git worktree remove ../release-`). -10. **After the publish, the release is on `rc` only.** `npm install +10. **After the publish, the release is on `next` only.** `npm install prisma` keeps the previous release until a maintainer checks the new one and promotes it with `promote.yml`; see "Procedure: promote a release to `latest`" in `docs/oss/versioning.md`. From 175a869bc0223891f7a2b33aab660634c4841a60 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:21:13 +1100 Subject: [PATCH 07/16] fix(promote): allow older pins only in a rollback; read latest uncached Round 4 review fixes: - allow-older lets a CLI pin products older than their latest only when the version itself is older than latest, so it cannot wave through a forward promotion. Tests cover that and a product with no latest. - check-promotion reads latest with `npm dist-tag ls`, which npm does not cache, so a product promoted minutes earlier is seen. - The docs say a rollback leaves next on the withdrawn release until the next release moves it. Stale comments about next in cli-command and the follow script are corrected, and the trusted-publishing note is no longer a dist-tag list item. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- README.md | 2 +- docs/oss/versioning.md | 7 +- packages/cli/src/cli-command.ts | 4 +- packages/cli/tests/cli-command.test.ts | 7 +- scripts/check-promotion.mjs | 97 ++++++++++++++++++-------- scripts/check-promotion.test.mjs | 51 +++++++++++--- scripts/update-product-versions.mjs | 4 +- 7 files changed, 121 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index d38357209..a23510727 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ lockstep) is the release source of truth. The workflow publishes Release channels: -- `next`: every release on the Prisma 8 RC line (`8.0.0-rc.N`), as soon as it publishes. A merged PR that bumps the root version (via `pnpm bump-version`) publishes automatically: a maintainer's release PR, or the version-follow PR a product release opens; `workflow_dispatch` is the manual escape hatch and the dry-run path. +- `next`: every release, as soon as it publishes (today, the Prisma 8 RC line, `8.0.0-rc.N`). A merged PR that bumps the root version (via `pnpm bump-version`) publishes automatically: a maintainer's release PR, or the version-follow PR a product release opens; `workflow_dispatch` is the manual escape hatch and the dry-run path. - `latest`: the release a maintainer has checked and promoted. See [versioning](docs/oss/versioning.md). - `dev`: latest successful `main` build. Every push to `main` that does not change the root version publishes `-dev.N` under the `dev` dist-tag. diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 2a2cd367b..7b95fad85 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -40,14 +40,15 @@ This is enforced, not remembered: the conformance checks refuse to publish a rel The npm registry exposes the CLI packages under these dist-tags: - **`latest`** — what a bare `npm install` gets: the newest promoted release, RC or stable. Only promoting a release moves it. A publish dispatch refuses `latest` as its dist-tag. From the 2026-08-25 cutover until December 2026 a merged release PR published here directly; before the cutover `latest` stayed on the pre-8 CLI and the RC line lived on `next`. -- **`next`** — every release, as soon as it publishes: a merged release PR publishes here automatically, and nothing else does. It is ahead of `latest` while a release waits to be checked and promoted, and names the same version once promoted. It does not go stale, because every release moves it. History: from the 2026-08-25 cutover until December 2026 releases went straight to `latest`, nothing moved `next`, and by November it still pointed at `8.0.0-rc.10`, so `npx prisma@next` silently installed a CLI 26 releases old. It was removed on 2026-11-30 for that reason, and came back as the staging tag in December 2026. It is called `next` and not `rc` because the ORM's docs already use "RC" for the release-candidate stage of a version. -- The publish workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish. That is why promotion uses a token added for one run; see [Procedure: promote a release to `latest`](#procedure-promote-a-release-to-latest). +- **`next`** — every release, as soon as it publishes: a merged release PR publishes here automatically, and a publish dispatch re-run publishes here too. It is ahead of `latest` while a release waits to be checked and promoted, and names the same version once promoted. It does not go stale, because every release moves it; the exception is a rollback, after which it still names the withdrawn release until the next release moves it. History: from the 2026-08-25 cutover until December 2026 releases went straight to `latest`, nothing moved `next`, and by November it still pointed at `8.0.0-rc.10`, so `npx prisma@next` silently installed a CLI 26 releases old. It was removed on 2026-11-30 for that reason, and came back as the staging tag in December 2026. It is called `next` and not `rc` because the ORM's docs already use "RC" for the release-candidate stage of a version. - **`beta`** — reserved for hand-cut previews ahead of significant changes, published by dispatching the workflow with that dist-tag. Routine releases do not use this tag. - **`dev`** — every routine push to `main` publishes `-dev.` here automatically (operator ruling 2026-08-13, superseding the earlier "no dev channel" ruling). The suffix derives from the workflow run number and is stamped ephemerally in CI, never committed, so release versions remain exactly what a commit says. The channel exists so a product's new version reaches a working CLI without a human: every push to `main` ships a dev build. A product release goes further and cuts a real release on its own; see [release automation](./release-automation.md). Only a release for a change in this repository alone is a human act, and so is promoting any release to `latest`. **Every** run of the publish workflow ships a dev build, including the one that cuts a release — the release publish is an additional half, not an alternative (operator ruling 2026-08-18). When they were alternatives, the release commit was the one merge to `main` that never reached the dev channel, so `dev` named an older version than the release until an unrelated commit landed. The dev build is published as its own version rather than by moving the `dev` tag, because OIDC trusted publishing authorises `npm publish` and nothing else. The dev channel covers `@prisma/cli` and `prisma` only. The engine has no dev builds; [Lockstep across the workspace](#lockstep-across-the-workspace) gives the reasons. +The publish workflow logs in to npm through OIDC trusted publishing, which can set a tag only on the version it is publishing, never on one already on the registry, and a stored token that could re-point a tag would also be able to publish. That is why promotion uses a token added for one run; see [Procedure: promote a release to `latest`](#procedure-promote-a-release-to-latest). + PR previews go through [`pkg.pr.new`](https://pkg.pr.new) ([`preview-cli-package.yml`](../../.github/workflows/preview-cli-package.yml)); they carry the committed base version and install via per-commit URLs, not dist-tags. ## Who can publish @@ -93,7 +94,7 @@ If the publish needs to be re-run (transient registry failure, etc.), a maintain [`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand from `main` with the version to promote. Its check job runs [`scripts/check-promotion.mjs`](../../scripts/check-promotion.mjs), and nothing changes unless every check passes: - `prisma` and `@prisma/cli` are on npm at that version. -- The version is not older than their current `latest`. To roll back, run with `allow-older` on. +- The version is not older than their current `latest`. To roll back, run with `allow-older` on. A rollback leaves `next` on the withdrawn release, and the version-follow script follows `next`, so ship a fixed release soon after; for an ORM or Composer rollback, the CLI cannot be promoted until that product's fix release is followed. - For a stable version, its GitHub Release is published (not a draft), so marking it Latest cannot fail after npm has changed. - Every ORM and Composer version that `@prisma/cli` pins at that version is exactly `latest`. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. A CLI that pins older products than `latest` is refused too, except in a rollback. diff --git a/packages/cli/src/cli-command.ts b/packages/cli/src/cli-command.ts index 9ef811024..08a8baf9a 100644 --- a/packages/cli/src/cli-command.ts +++ b/packages/cli/src/cli-command.ts @@ -1,8 +1,8 @@ import { CLI_NAME } from "./cli-name"; export const PRISMA_CLI_PACKAGE_NAME = "@prisma/cli"; -// `latest` is where every release publishes, RC line included; `next` is -// moved by hand and can lag (docs/oss/versioning.md). +// `latest` is the release a maintainer has checked and promoted; `next` can +// hold a newer release still waiting for that check (docs/oss/versioning.md). export const PRISMA_CLI_PACKAGE_SPEC = `${PRISMA_CLI_PACKAGE_NAME}@latest`; export const DEFAULT_PRISMA_CLI_PACKAGE_RUNNER = ["npx", "-y"]; export const PRISMA_CLI_BINARY = CLI_NAME; diff --git a/packages/cli/tests/cli-command.test.ts b/packages/cli/tests/cli-command.test.ts index a26b63264..e7ce759e7 100644 --- a/packages/cli/tests/cli-command.test.ts +++ b/packages/cli/tests/cli-command.test.ts @@ -1,7 +1,6 @@ -// The package spec the CLI prints in its own hints. `latest` carries the -// RC line since the 2026-08-25 cutover and the publish path no longer -// moves `next` (docs/oss/versioning.md), so a hint spelling `@next` -// installs a release that lags the current one. +// The package spec the CLI prints in its own hints. `latest` is the checked, +// promoted release; `next` can hold one still waiting for that check +// (docs/oss/versioning.md), so a hint spelling `@next` could install it. import { describe, expect, it } from "vitest"; import { diff --git a/scripts/check-promotion.mjs b/scripts/check-promotion.mjs index 1b8bc1208..64ba77f83 100644 --- a/scripts/check-promotion.mjs +++ b/scripts/check-promotion.mjs @@ -20,6 +20,7 @@ export const PROMOTED = ["prisma", "@prisma/cli"]; const RELEASE_VERSION = /^\d+\.\d+\.\d+(-rc\.[1-9]\d*)?$/; const PRODUCT_PIN = /^@prisma\/(orm|composer)/; +const LATEST_LINE = /^latest: (\S+)$/m; /** * Every reason not to promote. Pure; exported for tests. @@ -38,32 +39,45 @@ export function promotionProblems({ version, allowOlder, cli, pins }) { `"${version}" is not a release version such as 8.0.0-rc.37 or 8.0.0.`, ]; } - const problems = []; - for (const [name, { published, latest }] of Object.entries(cli)) { - if (!published) { - problems.push(`${name}@${version} is not on npm.`); - } else if ( - !allowOlder && - latest !== undefined && - compareVersions(version, latest) < 0 - ) { - problems.push( - `${name}@${version} is older than its latest, ${latest}. Run again with allow-older to roll back.`, - ); - } + const isOlder = (latest) => + latest !== undefined && compareVersions(version, latest) < 0; + const rollback = + allowOlder && Object.values(cli).some(({ latest }) => isOlder(latest)); + return [ + ...Object.entries(cli).flatMap(([name, { published, latest }]) => { + if (!published) return [`${name}@${version} is not on npm.`]; + if (!allowOlder && isOlder(latest)) { + return [ + `${name}@${version} is older than its latest, ${latest}. Run again with allow-older to roll back.`, + ]; + } + return []; + }), + ...Object.entries(pins).flatMap(([name, { pinned, latest }]) => + pinProblems(version, name, pinned, latest, rollback), + ), + ]; +} + +/** + * @param {string} version + * @param {string} name + * @param {string} pinned + * @param {string | undefined} latest + * @param {boolean} rollback + */ +function pinProblems(version, name, pinned, latest, rollback) { + if (latest === undefined || compareVersions(pinned, latest) > 0) { + return [ + `${version} pins ${name}@${pinned}, but its latest is ${latest ?? "unset"}. Promote the ORM and Composer releases first.`, + ]; } - for (const [name, { pinned, latest }] of Object.entries(pins)) { - if (latest === undefined || compareVersions(pinned, latest) > 0) { - problems.push( - `${version} pins ${name}@${pinned}, but its latest is ${latest ?? "unset"}. Promote the ORM and Composer releases first.`, - ); - } else if (!allowOlder && compareVersions(pinned, latest) < 0) { - problems.push( - `${version} pins ${name}@${pinned}, older than its latest, ${latest}. Promote a CLI release that pins ${latest}, or run with allow-older to roll back.`, - ); - } + if (!rollback && compareVersions(pinned, latest) < 0) { + return [ + `${version} pins ${name}@${pinned}, older than its latest, ${latest}. Promote a CLI release that pins ${latest}.`, + ]; } - return problems; + return []; } /** `npm view `, or undefined when the package or version does not exist. */ @@ -82,25 +96,46 @@ function npmView(spec, field) { } /** - * What promotionProblems needs, read through `view`. Exported for tests. + * The package's `latest` from `npm dist-tag ls`, which is not cached the + * way `npm view` is, so a promotion minutes earlier is already visible. + * + * @param {string} name + */ +function npmLatest(name) { + try { + const out = execFileSync("npm", ["dist-tag", "ls", name], { + encoding: "utf-8", + stdio: ["ignore", "pipe", "pipe"], + }); + return LATEST_LINE.exec(out)?.[1]; + } catch (error) { + const stderr = typeof error?.stderr === "string" ? error.stderr : ""; + if (isPackageAbsent(stderr)) return undefined; + throw error; + } +} + +/** + * What promotionProblems needs, read through `view` and `latestOf`. + * Exported for tests. * * @param {string} version * @param {boolean} allowOlder - * @param {(spec: string, field: string) => unknown} view + * @param {{ view: (spec: string, field: string) => unknown; latestOf: (name: string) => string | undefined }} registry */ -export function readState(version, allowOlder, view) { +export function readState(version, allowOlder, { view, latestOf }) { const cli = {}; for (const name of PROMOTED) { cli[name] = { published: view(`${name}@${version}`, "version") === version, - latest: view(name, "dist-tags.latest"), + latest: latestOf(name), }; } const pins = {}; const dependencies = view(`@prisma/cli@${version}`, "dependencies") ?? {}; for (const [name, pinned] of Object.entries(dependencies)) { if (PRODUCT_PIN.test(name)) { - pins[name] = { pinned, latest: view(name, "dist-tags.latest") }; + pins[name] = { pinned, latest: latestOf(name) }; } } return { version, allowOlder, cli, pins }; @@ -116,7 +151,9 @@ function main() { } const allowOlder = flags.includes("--allow-older"); const problems = RELEASE_VERSION.test(version) - ? promotionProblems(readState(version, allowOlder, npmView)) + ? promotionProblems( + readState(version, allowOlder, { view: npmView, latestOf: npmLatest }), + ) : promotionProblems({ version, allowOlder, cli: {}, pins: {} }); for (const problem of problems) console.error(problem); if (problems.length > 0) { diff --git a/scripts/check-promotion.test.mjs b/scripts/check-promotion.test.mjs index 0c50d20ae..ba7805eb3 100644 --- a/scripts/check-promotion.test.mjs +++ b/scripts/check-promotion.test.mjs @@ -93,7 +93,7 @@ describe("promotionProblems", () => { it("refuses a CLI that pins an older product than latest, unless it is a rollback", () => { const state = { - version: "8.0.0-rc.37", + version: "8.0.0-rc.35", cli: published("8.0.0-rc.36"), pins: { "@prisma/orm-toolchain": { @@ -103,9 +103,36 @@ describe("promotionProblems", () => { }, }; const problems = promotionProblems({ ...state, allowOlder: false }); + assert.ok(problems.some((problem) => OLDER_PIN.test(problem))); + assert.deepEqual(promotionProblems({ ...state, allowOlder: true }), []); + }); + + it("does not let allow-older pass older pins when the version is not a rollback", () => { + const problems = promotionProblems({ + version: "8.0.0-rc.37", + allowOlder: true, + cli: published("8.0.0-rc.36"), + pins: { + "@prisma/orm-toolchain": { + pinned: "8.0.0-rc.25", + latest: "8.0.0-rc.26", + }, + }, + }); assert.equal(problems.length, 1); assert.match(problems[0], OLDER_PIN); - assert.deepEqual(promotionProblems({ ...state, allowOlder: true }), []); + }); + + it("refuses a CLI pinning a product that has no latest", () => { + const problems = promotionProblems({ + version: "8.0.0-rc.37", + allowOlder: false, + cli: published("8.0.0-rc.36"), + pins: { + "@prisma/orm-toolchain": { pinned: "8.0.0-rc.26", latest: undefined }, + }, + }); + assert.match(problems[0], PRODUCTS_FIRST); }); it("refuses a rollback whose pins are newer than the products' latest", () => { @@ -127,28 +154,34 @@ describe("promotionProblems", () => { describe("readState", () => { const registry = { "prisma@8.0.0-rc.37 version": "8.0.0-rc.37", - "prisma dist-tags.latest": "8.0.0-rc.36", - "@prisma/cli dist-tags.latest": "8.0.0-rc.36", + "@prisma/cli@8.0.0-rc.37 dependencies": { "@prisma/orm-toolchain": "8.0.0-rc.26", "@prisma/composer": "0.41.0", "@prisma/cli-engine": "0.10.4", effect: "4.1.4", }, - "@prisma/orm-toolchain dist-tags.latest": "8.0.0-rc.26", - "@prisma/composer dist-tags.latest": "0.41.0", }; - const view = (spec, field) => registry[`${spec} ${field}`]; + const latest = { + prisma: "8.0.0-rc.36", + "@prisma/cli": "8.0.0-rc.36", + "@prisma/orm-toolchain": "8.0.0-rc.26", + "@prisma/composer": "0.41.0", + }; + const reads = { + view: (spec, field) => registry[`${spec} ${field}`], + latestOf: (name) => latest[name], + }; it("checks only the ORM and Composer pins, not the engine or third-party packages", () => { - assert.deepEqual(Object.keys(readState("8.0.0-rc.37", false, view).pins), [ + assert.deepEqual(Object.keys(readState("8.0.0-rc.37", false, reads).pins), [ "@prisma/orm-toolchain", "@prisma/composer", ]); }); it("reports a version npm does not have as unpublished", () => { - const { cli } = readState("8.0.0-rc.37", false, view); + const { cli } = readState("8.0.0-rc.37", false, reads); assert.equal(cli.prisma.published, true); assert.equal(cli["@prisma/cli"].published, false); }); diff --git a/scripts/update-product-versions.mjs b/scripts/update-product-versions.mjs index 26c2566e9..57f1ef9e5 100644 --- a/scripts/update-product-versions.mjs +++ b/scripts/update-product-versions.mjs @@ -343,8 +343,8 @@ function distTags(name) { * A package that exists but publishes none of its candidate tags is a * mistake in this script's table, or a product that moved where it * publishes. Either way it must fail rather than look like "nothing to - * move to": the previous version of this script asked for `next` on the - * ORM, which has never had that tag, and silently never updated it. + * move to": a 2026 version of this script asked for `next` on the ORM + * before the ORM published that tag, and silently never updated it. * * @param {readonly string[]} candidates */ From dd0722143e3d7d2eba55cc777e6088815208cf03 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:34:50 +1100 Subject: [PATCH 08/16] docs(release): correct two stale statements about next and candidate tags Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- docs/oss/release-automation.md | 2 +- scripts/update-product-versions.mjs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 32d116ebf..1549e5590 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -17,7 +17,7 @@ A **release** of the CLI depends only on **released** versions of the products. ## What happens when a product publishes 1. The product repository's publish workflow finishes and sends a `repository_dispatch` event of type `product-published` to `prisma/prisma-cli`. -2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. The ORM and Composer publish each release under `next` and move `latest` later, once the releases are checked together, as this repository does (see [versioning.md](versioning.md)). So the script reads `next` first and falls back to `latest` for a product that does not publish `next`. Reading `next` lets a product release reach the CLI as soon as it publishes, and keeps the script from moving pins back to an older `latest` while a release waits to be promoted. `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each other package carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". +2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. The ORM and Composer publish each release under `next` and move `latest` later, once the releases are checked together, as this repository does (see [versioning.md](versioning.md)). So the script reads `next` first and falls back to `latest` for a product that does not publish `next`. Reading `next` lets a product release reach the CLI as soon as it publishes, and keeps the script from moving pins back to an older `latest` while a release waits to be promoted. `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each package that reads a tag of its own (`@prisma/composer-cli`, `@prisma/composer` and `@prisma/orm-toolchain`; the rest copy one of these) carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". 3. If any pin changed, or `main` holds pins the last release (its `v` tag) did not ship, the workflow bumps the CLI to its next version with `pnpm bump-version` (which also refreshes `pnpm-lock.yaml`), opens a pull request titled `Release : follow the products' released versions: ...`, and arms auto-merge. Every earlier open pull request from this workflow, and every open `Bump to version` release pull request, is closed first: each bumps the same version, so only one can merge. 4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `next` with the committed product versions, plus the usual `dev` build. `latest` moves when a maintainer promotes the release with [`promote.yml`](../../.github/workflows/promote.yml). diff --git a/scripts/update-product-versions.mjs b/scripts/update-product-versions.mjs index 57f1ef9e5..de9d0e672 100644 --- a/scripts/update-product-versions.mjs +++ b/scripts/update-product-versions.mjs @@ -43,9 +43,9 @@ import { fileURLToPath } from "node:url"; // publish `next` yet. // // A list rather than a single tag name because asking for one tag is -// what made the previous version of this script silently never update -// the ORM: it asked for `next`, which no prisma/prisma package has ever -// had, and a missing tag was indistinguishable from a missing package. +// what made an earlier version of this script silently never update the +// ORM: it asked for `next` before the ORM published that tag, and a +// missing tag was indistinguishable from a missing package. const WATCHED = /** @type {const} */ ([ { name: "@prisma/composer-cli", release: ["next", "latest"] }, // The library. `deploy` builds a Composer config with it for a From f490ed992178abd75c0023e1472580147d949c8b Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:42:55 +1100 Subject: [PATCH 09/16] ci(promote): follow the ORM's promote.yml: plan from the release tag, then move promote.yml now has the shape of prisma/orm's (prisma/orm#31329): - check (no token, read-only) checks out the release's tag v as data, confirms it is on main, and runs scripts/promote-release.ts, which plans the moves and refuses a missing version, a move back to an older latest (unless allow-downgrade), and, for the CLI, ORM or Composer pins that are not exactly latest. A dry run can run from any branch. - promote (main only, the token's only job, no checkout, no permissions) validates the plan, moves latest per package, and reports partial moves. - mark-latest marks a stable GitHub Release Latest. scripts/promote-release.ts replaces scripts/check-promotion.mjs; the workflow test runs the move step against a stand-in npm, as the ORM's does. Adds yaml as a dev dependency to read the workflow in that test. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 196 ++++++++++++++-------- docs/oss/versioning.md | 14 +- package.json | 5 +- pnpm-lock.yaml | 12 +- scripts/check-promotion.mjs | 169 ------------------- scripts/check-promotion.test.mjs | 188 --------------------- scripts/promote-release-utils.test.ts | 226 ++++++++++++++++++++++++++ scripts/promote-release-utils.ts | 198 ++++++++++++++++++++++ scripts/promote-release.ts | 148 +++++++++++++++++ scripts/promote-workflow.test.mjs | 169 +++++++++++++++++++ 10 files changed, 880 insertions(+), 445 deletions(-) delete mode 100644 scripts/check-promotion.mjs delete mode 100644 scripts/check-promotion.test.mjs create mode 100644 scripts/promote-release-utils.test.ts create mode 100644 scripts/promote-release-utils.ts create mode 100644 scripts/promote-release.ts create mode 100644 scripts/promote-workflow.test.mjs diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index b326a4bab..657528035 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -1,28 +1,35 @@ name: Promote a release to latest -# A release publishes under `next` (publish.yml). This moves `latest` for -# `prisma` and `@prisma/cli` to a version already on npm, once it has -# been checked. See docs/oss/versioning.md. +# A release is published under the `next` dist-tag (publish.yml); a bare install +# resolves `latest`. This workflow moves `latest` for `prisma` and `@prisma/cli` +# to a published release, by hand, once the Prisma ORM, Composer and CLI +# versions that work together are all released and checked, and refuses while +# the ORM and Composer versions the release pins are not `latest` yet. See +# docs/oss/versioning.md. The same shape as prisma/orm's promote.yml. # -# Trusted publishing cannot move a tag on a published version, so the -# real run needs an npm token. It comes from the secret NPM_PROMOTE_TOKEN in the -# `npm-promote` environment, which the promoter adds just before a run -# and deletes after: the repository holds no token between promotions. +# Three jobs, so that the npm token meets no code from the repository and no +# repository write access: +# - check: no token, read-only. Runs this workflow's own scripts on the +# release's tag, checked out as data only, and outputs what to move. A dry +# run ends here, from any branch. +# - promote: main only, not a dry run. Holds the token from the npm-promote +# environment, checks out nothing, and has no repository permissions. +# - mark-latest: marks the GitHub Release as Latest, for a stable release. on: workflow_dispatch: inputs: version: - description: "Version to move latest to, e.g. 8.0.0-rc.37. It must already be on npm for prisma and @prisma/cli." + description: "Release version to promote, such as 8.0.0-rc.37" required: true type: string dry-run: - description: "Check only; change no tags." + description: "Dry run: check the release and print the moves, without changing any tag" required: false default: true type: boolean - allow-older: - description: "Allow moving latest back to an older version (a rollback)." + allow-downgrade: + description: "Allow moving latest back to an older release (a rollback)" required: false default: false type: boolean @@ -35,113 +42,158 @@ permissions: {} jobs: check: - name: Check the version can be promoted + name: Check the release runs-on: ubuntu-latest permissions: contents: read + outputs: + plan: ${{ steps.plan.outputs.plan }} + steps: - - name: Refuse a branch other than main - if: ${{ github.ref != 'refs/heads/main' }} + - name: Check the inputs + env: + VERSION: ${{ inputs.version }} + DRY_RUN: ${{ inputs.dry-run }} run: | - echo "promote.yml runs only from main." >&2 - exit 1 + if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$'; then + echo "::error::\"$VERSION\" is not a release version, such as 8.0.0-rc.37 or 8.1.0." + exit 1 + fi + if [ "$DRY_RUN" != "true" ] && [ "$GITHUB_REF" != "refs/heads/main" ]; then + echo "::error::A real promotion runs only from main. Run from $GITHUB_REF as a dry run, or dispatch from main." + exit 1 + fi - - name: Checkout + - name: Checkout this workflow's ref uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: + fetch-depth: 0 persist-credentials: false - - name: Set up Node.js - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + # Data only: nothing in this folder is run. + - name: Checkout the release's tag as data + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: - node-version-file: .node-version + ref: v${{ inputs.version }} + path: release-data + persist-credentials: false - - name: Check the version can be promoted + - name: Check the release's tag is on main env: VERSION: ${{ inputs.version }} - ALLOW_OLDER: ${{ inputs.allow-older }} run: | - if [ "$ALLOW_OLDER" = "true" ]; then - node scripts/check-promotion.mjs "$VERSION" --allow-older - else - node scripts/check-promotion.mjs "$VERSION" + tagged="$(git rev-parse "v$VERSION^{commit}")" + if [ "$(git -C release-data rev-parse HEAD)" != "$tagged" ]; then + echo "::error::The two checkouts of v$VERSION differ; the tag moved during the run." + exit 1 + fi + if ! git merge-base --is-ancestor "$tagged" origin/main; then + echo "::error::v$VERSION points at $tagged, which is not on main. Only a release published from main can be promoted." + exit 1 fi - # Checked here, before npm changes, so a missing release cannot - # leave npm and GitHub disagreeing. The by-tag endpoint does not see - # drafts, which is right: a draft cannot be marked Latest. - - name: Check the stable version's GitHub Release is published - if: ${{ !contains(inputs.version, '-') }} + - name: Set up Node.js + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version-file: .node-version + + - name: Plan the promotion + id: plan env: - GH_TOKEN: ${{ github.token }} VERSION: ${{ inputs.version }} + ALLOW_DOWNGRADE: ${{ inputs.allow-downgrade }} run: | - if ! gh api "repos/$GITHUB_REPOSITORY/releases/tags/v$VERSION" --jq .id >/dev/null; then - echo "GitHub Release v$VERSION is missing or still a draft; nothing was changed." >&2 - exit 1 - fi + flags=() + if [ "$ALLOW_DOWNGRADE" = "true" ]; then flags+=(--allow-downgrade); fi + node scripts/promote-release.ts "$VERSION" --release-root release-data --plan-out "$RUNNER_TEMP/plan.json" "${flags[@]}" + echo "plan=$(jq -c . "$RUNNER_TEMP/plan.json")" >> "$GITHUB_OUTPUT" promote: - name: Move latest + name: Move latest to the release needs: check if: ${{ github.ref == 'refs/heads/main' && !inputs.dry-run }} runs-on: ubuntu-latest environment: npm-promote permissions: {} - steps: - - name: Set up npm - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 - with: - node-version: 24 - registry-url: https://registry.npmjs.org + outputs: + version: ${{ steps.move.outputs.version }} - - name: Move latest + steps: + - name: Check the npm token env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} - VERSION: ${{ inputs.version }} + NPM_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} run: | - if [ -z "$NODE_AUTH_TOKEN" ]; then - echo "The npm-promote environment has no NPM_PROMOTE_TOKEN secret. Add a short-lived granular token there, run again, then delete it." >&2 + if [ -z "$NPM_TOKEN" ]; then + echo "::error::The npm-promote environment has no NPM_PROMOTE_TOKEN secret. Create a short-lived npm token, add it to that environment as NPM_PROMOTE_TOKEN, run again, then delete the secret and revoke the token. See docs/oss/versioning.md." exit 1 fi - for pkg in prisma @prisma/cli; do - npm dist-tag add "$pkg@$VERSION" latest - done + echo "::add-mask::$NPM_TOKEN" - # `npm dist-tag ls` reads the tags uncached; a failed read is retried. - - name: Check latest moved + # Runs no code from the repository: the plan comes from the check job, and + # each name and version in it is checked before use. The token reaches npm + # only through this step's environment, by a config file outside any + # checkout that refers to NODE_AUTH_TOKEN rather than holding it. + - name: Move latest + id: move env: - VERSION: ${{ inputs.version }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} + PLAN: ${{ needs.check.outputs.plan }} run: | - for pkg in prisma @prisma/cli; do - latest="" - for _ in $(seq 10); do - latest=$(npm dist-tag ls "$pkg" 2>/dev/null | sed -n 's/^latest: //p') || true - [ "$latest" = "$VERSION" ] && break - sleep 30 - done - if [ "$latest" != "$VERSION" ]; then - echo "$pkg latest is ${latest:-unreadable}, not $VERSION." >&2 + set -euo pipefail + version_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$' + name_re='^(prisma|@prisma/cli)$' + release="$(jq -r '.version' <<<"$PLAN")" + entries="$(jq -r '.packages[] | "\(.name) \(.version)"' <<<"$PLAN")" + [[ $release =~ $version_re ]] || { echo "::error::The plan's version \"$release\" is not a version."; exit 1; } + [ -n "$entries" ] || { echo "::error::The plan lists no package."; exit 1; } + while read -r name version <&3; do + [[ $name =~ $name_re ]] || { echo "::error::The plan names \"$name\", which is not one of ours."; exit 1; } + [[ $version =~ $version_re ]] || { echo "::error::The plan gives $name \"$version\", which is not a version."; exit 1; } + done 3<<<"$entries" + + npmrc="$RUNNER_TEMP/promote.npmrc" + printf '%s\n' 'registry=https://registry.npmjs.org/' "//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}" > "$npmrc" + export NPM_CONFIG_USERCONFIG="$npmrc" + + while read -r name version <&3; do + if [ "$(npm view "$name@$version" version 2>/dev/null || true)" != "$version" ]; then + echo "::error::$name@$version is not on the registry. Nothing moved." + exit 1 + fi + done 3<<<"$entries" + + moved=() + while read -r name version <&3; do + if [ "$(npm view "$name" dist-tags.latest)" = "$version" ]; then + echo "$name: latest is already $version" + continue + fi + if npm dist-tag add "$name@$version" latest || npm dist-tag add "$name@$version" latest; then + moved+=("$name") + echo "$name: latest moved to $version" + else + echo "::error::Moving latest failed for $name@$version. Moved in this run: ${moved[*]:-none}. Run the workflow again to move the rest; packages already moved are left alone." exit 1 fi - echo "$pkg latest is $VERSION." - done + done 3<<<"$entries" + echo "version=$release" >> "$GITHUB_OUTPUT" - # Its own job, so the job holding the npm token cannot write to the - # repository. GitHub never marks a pre-release as Latest. mark-latest: name: Mark the GitHub Release as Latest needs: promote - if: ${{ !contains(inputs.version, '-') }} runs-on: ubuntu-latest permissions: contents: write steps: + # publish.yml creates the GitHub Release without the Latest mark. GitHub + # does not let a pre-release be Latest, so a release candidate stays as it is. - name: Mark the GitHub Release as Latest env: GH_TOKEN: ${{ github.token }} - VERSION: ${{ inputs.version }} + VERSION: ${{ needs.promote.outputs.version }} run: | - release_id=$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/v$VERSION" --jq .id) - gh api -X PATCH "repos/$GITHUB_REPOSITORY/releases/$release_id" -f make_latest=true >/dev/null - echo "GitHub Release v$VERSION is marked Latest." + if [ "$(gh release view "v$VERSION" --repo "$GITHUB_REPOSITORY" --json isPrerelease --jq .isPrerelease)" = "true" ]; then + echo "v$VERSION is a pre-release, which GitHub does not let be Latest; leaving it as it is." + else + gh release edit "v$VERSION" --repo "$GITHUB_REPOSITORY" --latest + fi diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 7b95fad85..6f83f6cdf 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -91,14 +91,16 @@ If the publish needs to be re-run (transient registry failure, etc.), a maintain ## Procedure: promote a release to `latest` -[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand from `main` with the version to promote. Its check job runs [`scripts/check-promotion.mjs`](../../scripts/check-promotion.mjs), and nothing changes unless every check passes: +[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand with the version to promote. It has the same shape as the ORM's and Composer's promotion workflows, in three jobs: -- `prisma` and `@prisma/cli` are on npm at that version. -- The version is not older than their current `latest`. To roll back, run with `allow-older` on. A rollback leaves `next` on the withdrawn release, and the version-follow script follows `next`, so ship a fixed release soon after; for an ORM or Composer rollback, the CLI cannot be promoted until that product's fix release is followed. -- For a stable version, its GitHub Release is published (not a draft), so marking it Latest cannot fail after npm has changed. -- Every ORM and Composer version that `@prisma/cli` pins at that version is exactly `latest`. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. A CLI that pins older products than `latest` is refused too, except in a rollback. +1. `check` holds no token and only reads. It checks out the release's git tag `v` as data, confirms that the tag's commit is on `main`, and runs this workflow's own [`scripts/promote-release.ts`](../../scripts/promote-release.ts) on it. Nothing changes unless every check passes: + - `prisma` and `@prisma/cli` are on npm at that version. + - The move does not take `latest` back to an older version. To roll back, run with `allow-downgrade` on. A rollback leaves `next` on the withdrawn release, and the version-follow script follows `next`, so ship a fixed release soon after; for an ORM or Composer rollback, the CLI cannot be promoted until that product's fix release is followed. + - Every ORM and Composer version that `@prisma/cli` pins at that version is exactly `latest`. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. A CLI that pins older products than `latest` is refused too, except in a rollback. +2. `promote` runs only from `main` and only when `dry-run` is off. It is the only job in the `npm-promote` environment and the only one that reads the token; it checks out no code and has no repository permissions. It checks the plan `check` produced, moves `latest` for each package not already there, and says which moved if one fails, so a second run finishes the rest. +3. `mark-latest` marks the GitHub Release as Latest when it is a stable release. The publish workflow creates every GitHub Release without that mark, so GitHub's latest release matches npm's `latest` (GitHub never lets a pre-release be Latest). -A real run then moves `latest` on both packages and polls the registry until it shows the move. For a stable version a separate job then marks the GitHub Release as Latest (separate so the job that holds the npm token cannot write to the repository): the publish workflow creates every GitHub Release without that mark, so GitHub's latest release matches npm's `latest` (GitHub never marks a pre-release as Latest). Running it twice is harmless. A dry run (the default) only does the check, and needs no token. A run from any branch other than `main` fails. +Running it twice is harmless. A dry run (the default) only does the check, needs no token, and can run from any branch. Trusted publishing, which the publish workflow uses, can set a tag only on the version it is publishing, so moving `latest` on a published version needs an npm token. The repository holds none between promotions, because a stored token that can move a tag can also publish. diff --git a/package.json b/package.json index a80cea4e6..b4807a0f5 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "lint:fix": "biome check . --write", "bump-version": "node scripts/bump-version.ts", "test": "turbo run test", - "test:scripts": "node --test scripts/determine-version-utils.test.ts scripts/set-version-utils.test.ts scripts/bump-cli-engine-version-utils.test.ts scripts/resolve-package-version.test.mjs scripts/update-product-versions.test.mjs scripts/verify-published.test.mjs scripts/node-engines.test.mjs scripts/check-cloud-deploy-action.test.mjs scripts/check-promotion.test.mjs", + "test:scripts": "node --test scripts/determine-version-utils.test.ts scripts/set-version-utils.test.ts scripts/bump-cli-engine-version-utils.test.ts scripts/resolve-package-version.test.mjs scripts/update-product-versions.test.mjs scripts/verify-published.test.mjs scripts/node-engines.test.mjs scripts/check-cloud-deploy-action.test.mjs scripts/promote-release-utils.test.ts scripts/promote-workflow.test.mjs", "typecheck": "turbo run typecheck", "prisma-cli": "tsx packages/cli/src/bin.ts", "prisma": "tsx packages/cli/src/bin.ts", @@ -29,6 +29,7 @@ "@biomejs/biome": "2.4.16", "pkg-pr-new": "^0.0.75", "tsx": "^4.22.4", - "turbo": "^2.10.9" + "turbo": "^2.10.9", + "yaml": "2.9.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d4ea5868d..82245d425 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: turbo: specifier: ^2.10.9 version: 2.10.9 + yaml: + specifier: 2.9.1 + version: 2.9.1 packages/cli: dependencies: @@ -2808,11 +2811,6 @@ packages: resolution: {integrity: sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==} engines: {node: '>=18'} - yaml@2.9.0: - resolution: {integrity: sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==} - engines: {node: '>= 14.6'} - hasBin: true - yaml@2.9.1: resolution: {integrity: sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==} engines: {node: '>= 14.6'} @@ -3217,7 +3215,7 @@ snapshots: dependencies: jju: 1.4.0 tinyglobby: 0.2.17 - yaml: 2.9.0 + yaml: 2.9.1 '@mapbox/node-pre-gyp@2.0.3': dependencies: @@ -4975,8 +4973,6 @@ snapshots: yallist@5.0.0: {} - yaml@2.9.0: {} - yaml@2.9.1: {} yoctocolors@2.1.2: {} diff --git a/scripts/check-promotion.mjs b/scripts/check-promotion.mjs deleted file mode 100644 index 64ba77f83..000000000 --- a/scripts/check-promotion.mjs +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env node - -// What must hold before promote.yml moves `latest` to a version: both CLI -// packages are on npm at it, it is not older than their current `latest` -// unless the promoter asked for that, and the ORM and Composer versions it -// pins are exactly `latest`, so `npm install prisma` gets a CLI that -// matches the products users install. A rollback (--allow-older) may pin -// older products, never newer ones. -// -// Usage: node scripts/check-promotion.mjs [--allow-older] - -import { execFileSync } from "node:child_process"; -import { pathToFileURL } from "node:url"; -import { - compareVersions, - isPackageAbsent, -} from "./update-product-versions.mjs"; - -export const PROMOTED = ["prisma", "@prisma/cli"]; - -const RELEASE_VERSION = /^\d+\.\d+\.\d+(-rc\.[1-9]\d*)?$/; -const PRODUCT_PIN = /^@prisma\/(orm|composer)/; -const LATEST_LINE = /^latest: (\S+)$/m; - -/** - * Every reason not to promote. Pure; exported for tests. - * - * @param {{ - * version: string; - * allowOlder: boolean; - * cli: Record; - * pins: Record; - * }} state - * @returns {string[]} - */ -export function promotionProblems({ version, allowOlder, cli, pins }) { - if (!RELEASE_VERSION.test(version)) { - return [ - `"${version}" is not a release version such as 8.0.0-rc.37 or 8.0.0.`, - ]; - } - const isOlder = (latest) => - latest !== undefined && compareVersions(version, latest) < 0; - const rollback = - allowOlder && Object.values(cli).some(({ latest }) => isOlder(latest)); - return [ - ...Object.entries(cli).flatMap(([name, { published, latest }]) => { - if (!published) return [`${name}@${version} is not on npm.`]; - if (!allowOlder && isOlder(latest)) { - return [ - `${name}@${version} is older than its latest, ${latest}. Run again with allow-older to roll back.`, - ]; - } - return []; - }), - ...Object.entries(pins).flatMap(([name, { pinned, latest }]) => - pinProblems(version, name, pinned, latest, rollback), - ), - ]; -} - -/** - * @param {string} version - * @param {string} name - * @param {string} pinned - * @param {string | undefined} latest - * @param {boolean} rollback - */ -function pinProblems(version, name, pinned, latest, rollback) { - if (latest === undefined || compareVersions(pinned, latest) > 0) { - return [ - `${version} pins ${name}@${pinned}, but its latest is ${latest ?? "unset"}. Promote the ORM and Composer releases first.`, - ]; - } - if (!rollback && compareVersions(pinned, latest) < 0) { - return [ - `${version} pins ${name}@${pinned}, older than its latest, ${latest}. Promote a CLI release that pins ${latest}.`, - ]; - } - return []; -} - -/** `npm view `, or undefined when the package or version does not exist. */ -function npmView(spec, field) { - try { - const out = execFileSync("npm", ["view", spec, field, "--json"], { - encoding: "utf-8", - stdio: ["ignore", "pipe", "pipe"], - }).trim(); - return out.length === 0 ? undefined : JSON.parse(out); - } catch (error) { - const stderr = typeof error?.stderr === "string" ? error.stderr : ""; - if (isPackageAbsent(stderr)) return undefined; - throw error; - } -} - -/** - * The package's `latest` from `npm dist-tag ls`, which is not cached the - * way `npm view` is, so a promotion minutes earlier is already visible. - * - * @param {string} name - */ -function npmLatest(name) { - try { - const out = execFileSync("npm", ["dist-tag", "ls", name], { - encoding: "utf-8", - stdio: ["ignore", "pipe", "pipe"], - }); - return LATEST_LINE.exec(out)?.[1]; - } catch (error) { - const stderr = typeof error?.stderr === "string" ? error.stderr : ""; - if (isPackageAbsent(stderr)) return undefined; - throw error; - } -} - -/** - * What promotionProblems needs, read through `view` and `latestOf`. - * Exported for tests. - * - * @param {string} version - * @param {boolean} allowOlder - * @param {{ view: (spec: string, field: string) => unknown; latestOf: (name: string) => string | undefined }} registry - */ -export function readState(version, allowOlder, { view, latestOf }) { - const cli = {}; - for (const name of PROMOTED) { - cli[name] = { - published: view(`${name}@${version}`, "version") === version, - latest: latestOf(name), - }; - } - const pins = {}; - const dependencies = view(`@prisma/cli@${version}`, "dependencies") ?? {}; - for (const [name, pinned] of Object.entries(dependencies)) { - if (PRODUCT_PIN.test(name)) { - pins[name] = { pinned, latest: latestOf(name) }; - } - } - return { version, allowOlder, cli, pins }; -} - -function main() { - const [version, ...flags] = process.argv.slice(2); - if (version === undefined) { - console.error( - "Usage: node scripts/check-promotion.mjs [--allow-older]", - ); - process.exit(1); - } - const allowOlder = flags.includes("--allow-older"); - const problems = RELEASE_VERSION.test(version) - ? promotionProblems( - readState(version, allowOlder, { view: npmView, latestOf: npmLatest }), - ) - : promotionProblems({ version, allowOlder, cli: {}, pins: {} }); - for (const problem of problems) console.error(problem); - if (problems.length > 0) { - console.error("Nothing was changed."); - process.exit(1); - } - console.log(`${PROMOTED.join(" and ")} can be promoted to ${version}.`); -} - -const isDirectRun = - process.argv[1] !== undefined && - import.meta.url === pathToFileURL(process.argv[1]).href; -if (isDirectRun) main(); diff --git a/scripts/check-promotion.test.mjs b/scripts/check-promotion.test.mjs deleted file mode 100644 index ba7805eb3..000000000 --- a/scripts/check-promotion.test.mjs +++ /dev/null @@ -1,188 +0,0 @@ -import assert from "node:assert/strict"; -import { describe, it } from "node:test"; -import { promotionProblems, readState } from "./check-promotion.mjs"; - -const PRODUCTS_FIRST = /Promote the ORM and Composer releases first/; -const OLDER_PIN = /older than its latest, 8.0.0-rc.26/; - -const published = (latest) => ({ - prisma: { published: true, latest }, - "@prisma/cli": { published: true, latest }, -}); - -const promotedPins = { - "@prisma/orm-toolchain": { pinned: "8.0.0-rc.26", latest: "8.0.0-rc.26" }, - "@prisma/composer": { pinned: "0.41.0", latest: "0.41.0" }, -}; - -describe("promotionProblems", () => { - it("allows a published, newer version whose products are already latest", () => { - assert.deepEqual( - promotionProblems({ - version: "8.0.0-rc.37", - allowOlder: false, - cli: published("8.0.0-rc.36"), - pins: promotedPins, - }), - [], - ); - }); - - it("allows promoting the version that is already latest, so a second run is harmless", () => { - assert.deepEqual( - promotionProblems({ - version: "8.0.0-rc.37", - allowOlder: false, - cli: published("8.0.0-rc.37"), - pins: promotedPins, - }), - [], - ); - }); - - it("refuses a version that is not on npm", () => { - const problems = promotionProblems({ - version: "8.0.0-rc.37", - allowOlder: false, - cli: { - prisma: { published: true, latest: "8.0.0-rc.36" }, - "@prisma/cli": { published: false, latest: "8.0.0-rc.36" }, - }, - pins: promotedPins, - }); - assert.deepEqual(problems, ["@prisma/cli@8.0.0-rc.37 is not on npm."]); - }); - - it("refuses a version older than latest unless the promoter allows it", () => { - const state = { - version: "8.0.0-rc.35", - cli: published("8.0.0-rc.36"), - pins: promotedPins, - }; - assert.equal(promotionProblems({ ...state, allowOlder: false }).length, 2); - assert.deepEqual(promotionProblems({ ...state, allowOlder: true }), []); - }); - - it("refuses a CLI whose ORM or Composer pins are not latest yet", () => { - const problems = promotionProblems({ - version: "8.0.0-rc.37", - allowOlder: false, - cli: published("8.0.0-rc.36"), - pins: { - ...promotedPins, - "@prisma/orm-toolchain": { - pinned: "8.0.0-rc.26", - latest: "8.0.0-rc.25", - }, - }, - }); - assert.equal(problems.length, 1); - assert.match(problems[0], PRODUCTS_FIRST); - }); - - it("refuses a malformed version before reading anything else", () => { - for (const version of ["8.0.0-rc.37; rm -rf /", "latest", "8.0.0-dev.3"]) { - assert.equal( - promotionProblems({ version, allowOlder: false, cli: {}, pins: {} }) - .length, - 1, - version, - ); - } - }); - - it("refuses a CLI that pins an older product than latest, unless it is a rollback", () => { - const state = { - version: "8.0.0-rc.35", - cli: published("8.0.0-rc.36"), - pins: { - "@prisma/orm-toolchain": { - pinned: "8.0.0-rc.25", - latest: "8.0.0-rc.26", - }, - }, - }; - const problems = promotionProblems({ ...state, allowOlder: false }); - assert.ok(problems.some((problem) => OLDER_PIN.test(problem))); - assert.deepEqual(promotionProblems({ ...state, allowOlder: true }), []); - }); - - it("does not let allow-older pass older pins when the version is not a rollback", () => { - const problems = promotionProblems({ - version: "8.0.0-rc.37", - allowOlder: true, - cli: published("8.0.0-rc.36"), - pins: { - "@prisma/orm-toolchain": { - pinned: "8.0.0-rc.25", - latest: "8.0.0-rc.26", - }, - }, - }); - assert.equal(problems.length, 1); - assert.match(problems[0], OLDER_PIN); - }); - - it("refuses a CLI pinning a product that has no latest", () => { - const problems = promotionProblems({ - version: "8.0.0-rc.37", - allowOlder: false, - cli: published("8.0.0-rc.36"), - pins: { - "@prisma/orm-toolchain": { pinned: "8.0.0-rc.26", latest: undefined }, - }, - }); - assert.match(problems[0], PRODUCTS_FIRST); - }); - - it("refuses a rollback whose pins are newer than the products' latest", () => { - const problems = promotionProblems({ - version: "8.0.0-rc.30", - allowOlder: true, - cli: published("8.0.0-rc.36"), - pins: { - "@prisma/orm-toolchain": { - pinned: "8.0.0-rc.27", - latest: "8.0.0-rc.26", - }, - }, - }); - assert.match(problems[0], PRODUCTS_FIRST); - }); -}); - -describe("readState", () => { - const registry = { - "prisma@8.0.0-rc.37 version": "8.0.0-rc.37", - - "@prisma/cli@8.0.0-rc.37 dependencies": { - "@prisma/orm-toolchain": "8.0.0-rc.26", - "@prisma/composer": "0.41.0", - "@prisma/cli-engine": "0.10.4", - effect: "4.1.4", - }, - }; - const latest = { - prisma: "8.0.0-rc.36", - "@prisma/cli": "8.0.0-rc.36", - "@prisma/orm-toolchain": "8.0.0-rc.26", - "@prisma/composer": "0.41.0", - }; - const reads = { - view: (spec, field) => registry[`${spec} ${field}`], - latestOf: (name) => latest[name], - }; - - it("checks only the ORM and Composer pins, not the engine or third-party packages", () => { - assert.deepEqual(Object.keys(readState("8.0.0-rc.37", false, reads).pins), [ - "@prisma/orm-toolchain", - "@prisma/composer", - ]); - }); - - it("reports a version npm does not have as unpublished", () => { - const { cli } = readState("8.0.0-rc.37", false, reads); - assert.equal(cli.prisma.published, true); - assert.equal(cli["@prisma/cli"].published, false); - }); -}); diff --git a/scripts/promote-release-utils.test.ts b/scripts/promote-release-utils.test.ts new file mode 100644 index 000000000..268abc812 --- /dev/null +++ b/scripts/promote-release-utils.test.ts @@ -0,0 +1,226 @@ +import assert from "node:assert/strict"; +import { describe, it } from "node:test"; +import { + PromotionError, + planPromotion, + promotionPlan, + type RegistryState, + registryStateFrom, + releaseRootMismatch, +} from "./promote-release-utils.ts"; + +const NOT_ON_REGISTRY = /not on the registry/; +const MOVES_BACK = /back to an older version/; +const PRODUCTS_FIRST = /Promote the ORM and Composer releases first/; +const OLDER_PIN = /older than its latest, 8\.0\.0-rc\.26/; +const COULD_NOT_READ = /Could not read prisma/; +const NAMES_CLI = /@prisma\/cli@8\.0\.0-rc\.37/; +const NAMES_TAG = /v8\.0\.0-rc\.37/; + +const release = [ + { name: "prisma", version: "8.0.0-rc.37" }, + { name: "@prisma/cli", version: "8.0.0-rc.37" }, +]; + +const onRegistry = (latest: string): Map => + new Map( + ["prisma", "@prisma/cli"].map((name) => [ + name, + { versions: ["8.0.0-rc.35", "8.0.0-rc.36", "8.0.0-rc.37"], latest }, + ]), + ); + +const promotedPins = [ + { + name: "@prisma/orm-toolchain", + pinned: "8.0.0-rc.26", + latest: "8.0.0-rc.26", + }, + { name: "@prisma/composer", pinned: "0.41.0", latest: "0.41.0" }, +]; + +function refusal(run: () => unknown): string { + let message = ""; + assert.throws(run, (error) => { + message = error instanceof PromotionError ? error.message : ""; + return error instanceof PromotionError; + }); + return message; +} + +describe("planPromotion", () => { + it("moves latest for both packages when the ORM and Composer pins are already latest", () => { + const promotion = planPromotion({ + packages: release, + registry: onRegistry("8.0.0-rc.36"), + pins: promotedPins, + allowDowngrade: false, + }); + assert.deepEqual( + promotion.moves.map(({ name, from, back }) => [name, from, back]), + [ + ["@prisma/cli", "8.0.0-rc.36", false], + ["prisma", "8.0.0-rc.36", false], + ], + ); + assert.deepEqual(promotionPlan("8.0.0-rc.37", promotion), { + version: "8.0.0-rc.37", + packages: [ + { name: "@prisma/cli", version: "8.0.0-rc.37" }, + { name: "prisma", version: "8.0.0-rc.37" }, + ], + }); + }); + + it("changes nothing on a second run", () => { + const promotion = planPromotion({ + packages: release, + registry: onRegistry("8.0.0-rc.37"), + pins: promotedPins, + allowDowngrade: false, + }); + assert.equal(promotion.moves.length, 0); + assert.equal(promotion.unchanged.length, 2); + }); + + it("moves nothing when a package is not on the registry", () => { + const registry = onRegistry("8.0.0-rc.36"); + registry.set("@prisma/cli", { + versions: ["8.0.0-rc.36"], + latest: "8.0.0-rc.36", + }); + const message = refusal(() => + planPromotion({ + packages: release, + registry, + pins: promotedPins, + allowDowngrade: false, + }), + ); + assert.match(message, NOT_ON_REGISTRY); + assert.match(message, NAMES_CLI); + }); + + it("refuses to move latest back unless allow-downgrade is on", () => { + const options = { + packages: release.map(({ name }) => ({ name, version: "8.0.0-rc.35" })), + registry: onRegistry("8.0.0-rc.36"), + pins: promotedPins, + }; + assert.match( + refusal(() => planPromotion({ ...options, allowDowngrade: false })), + MOVES_BACK, + ); + assert.equal( + planPromotion({ ...options, allowDowngrade: true }).moves.length, + 2, + ); + }); + + it("does not count a development build on latest as a move back", () => { + const promotion = planPromotion({ + packages: release, + registry: onRegistry("8.0.0-rc.38-dev.4"), + pins: promotedPins, + allowDowngrade: false, + }); + assert.equal( + promotion.moves.every(({ back }) => !back), + true, + ); + }); + + it("refuses a release pinning an ORM or Composer version newer than its latest, or with no latest", () => { + for (const latest of ["8.0.0-rc.25", undefined]) { + const message = refusal(() => + planPromotion({ + packages: release, + registry: onRegistry("8.0.0-rc.36"), + pins: [ + { name: "@prisma/orm-toolchain", pinned: "8.0.0-rc.26", latest }, + ], + allowDowngrade: false, + }), + ); + assert.match(message, PRODUCTS_FIRST); + } + }); + + it("refuses a release pinning an older version than latest, except in a rollback", () => { + const pins = [ + { + name: "@prisma/orm-toolchain", + pinned: "8.0.0-rc.25", + latest: "8.0.0-rc.26", + }, + ]; + assert.match( + refusal(() => + planPromotion({ + packages: release, + registry: onRegistry("8.0.0-rc.36"), + pins, + allowDowngrade: true, + }), + ), + OLDER_PIN, + ); + const rollback = planPromotion({ + packages: release.map(({ name }) => ({ name, version: "8.0.0-rc.35" })), + registry: onRegistry("8.0.0-rc.36"), + pins, + allowDowngrade: true, + }); + assert.equal(rollback.moves.length, 2); + }); +}); + +describe("registryStateFrom", () => { + it("reads versions and latest", () => { + assert.deepEqual( + registryStateFrom("prisma", { + status: 0, + stdout: JSON.stringify({ + versions: ["8.0.0-rc.36"], + "dist-tags": { latest: "8.0.0-rc.36", next: "8.0.0-rc.36" }, + }), + stderr: "", + }), + { versions: ["8.0.0-rc.36"], latest: "8.0.0-rc.36" }, + ); + }); + + it("reads a package the registry does not have as empty", () => { + assert.deepEqual( + registryStateFrom("prisma", { + status: 1, + stdout: "", + stderr: "npm error code E404", + }), + { versions: [], latest: undefined }, + ); + }); + + it("stops on any other registry failure", () => { + assert.match( + refusal(() => + registryStateFrom("prisma", { + status: 1, + stdout: "", + stderr: "ETIMEDOUT", + }), + ), + COULD_NOT_READ, + ); + }); +}); + +describe("releaseRootMismatch", () => { + it("accepts the release asked for and names the tag otherwise", () => { + assert.equal(releaseRootMismatch("8.0.0-rc.37", "8.0.0-rc.37"), undefined); + assert.match( + releaseRootMismatch("8.0.0-rc.36", "8.0.0-rc.37") ?? "", + NAMES_TAG, + ); + }); +}); diff --git a/scripts/promote-release-utils.ts b/scripts/promote-release-utils.ts new file mode 100644 index 000000000..ff3c17de1 --- /dev/null +++ b/scripts/promote-release-utils.ts @@ -0,0 +1,198 @@ +// Pure helpers for `scripts/promote-release.ts`, which checks a release before the promotion +// workflow moves `latest` to it. All registry and file I/O lives in that script. The same shape +// as prisma/orm's scripts/promote-release-utils.ts, plus the check that the ORM and Composer +// versions a CLI release pins are already `latest`. + +import { compareVersions } from "./update-product-versions.mjs"; + +export interface ReleasePackage { + readonly name: string; + readonly version: string; +} + +export interface RegistryState { + readonly versions: readonly string[]; + readonly latest: string | undefined; +} + +/** An ORM or Composer package the release pins, and that package's current `latest`. */ +export interface ProductPin { + readonly name: string; + readonly pinned: string; + readonly latest: string | undefined; +} + +export interface Move extends ReleasePackage { + readonly from: string | undefined; + /** The move takes `latest` to an older version than the one it is on. */ + readonly back: boolean; +} + +export interface Promotion { + /** Packages whose `latest` moves to the release's version. */ + readonly moves: readonly Move[]; + /** Packages whose `latest` is already at the release's version. */ + readonly unchanged: readonly ReleasePackage[]; +} + +/** What the promote job moves. */ +export interface PromotionPlan { + readonly version: string; + readonly packages: readonly ReleasePackage[]; +} + +export class PromotionError extends Error {} + +const EMPTY: RegistryState = { versions: [], latest: undefined }; +const NOT_FOUND = /E404|404 Not Found/; +const DEVELOPMENT_BUILD = /-dev\.\d+$/; + +/** + * A package's state from the output of `npm view versions dist-tags --json`. A package + * the registry does not have is empty; any other failure stops the promotion. + */ +export function registryStateFrom( + name: string, + result: { status: number | null; stdout: string; stderr: string }, +): RegistryState { + if (result.status !== 0) { + if (NOT_FOUND.test(`${result.stdout}${result.stderr}`)) return EMPTY; + throw new PromotionError( + `Could not read ${name} from the registry:\n${result.stderr}`, + ); + } + if (result.stdout.trim() === "") return EMPTY; + const view: { + versions?: string | string[]; + "dist-tags"?: Record; + } = JSON.parse(result.stdout); + const versions = view.versions ?? []; + return { + versions: Array.isArray(versions) ? versions : [versions], + latest: view["dist-tags"]?.latest, + }; +} + +/** Why the release data checked out cannot be the release asked for, or `undefined` when it is. */ +export function releaseRootMismatch( + rootVersion: string, + requested: string, +): string | undefined { + if (rootVersion === requested) return undefined; + return `The release data is release ${rootVersion}, not ${requested}. Check out the release's tag, v${requested}, as the release data, and run again.`; +} + +/** + * What promoting a release does to each package. Refuses, naming them: + * - when any package's version is not on the registry, so a promotion changes all packages or none; + * - when a move takes `latest` back to an older version, unless `allowDowngrade`; + * - when a pinned ORM or Composer version is newer than that package's `latest`, or has no + * `latest`: `npm install prisma` would get a CLI ahead of the products users install; + * - when a pinned version is older than that package's `latest`, except in a rollback. + * A `latest` on a development build is not a release, so moving off it is never a move back. + */ +export function planPromotion(options: { + packages: readonly ReleasePackage[]; + registry: ReadonlyMap; + pins: readonly ProductPin[]; + allowDowngrade: boolean; +}): Promotion { + const packages = [...options.packages].sort((a, b) => + a.name < b.name ? -1 : 1, + ); + const stateOf = (name: string) => options.registry.get(name) ?? EMPTY; + const missing = packages.filter( + ({ name, version }) => !stateOf(name).versions.includes(version), + ); + if (missing.length > 0) { + throw new PromotionError( + [ + "These packages are not on the registry at the release version, so latest moves for none of them:", + ...missing.map(({ name, version }) => ` ${name}@${version}`), + "If the release was published only minutes ago, the registry may still be catching up: wait a few minutes and run again.", + 'Otherwise publish the release first: rerun its "Publish to npm" run, or dispatch that workflow from main with dist-tag=next and dry-run=false.', + ].join("\n"), + ); + } + const moves: Move[] = []; + const unchanged: ReleasePackage[] = []; + for (const pkg of packages) { + const from = stateOf(pkg.name).latest; + if (from === pkg.version) { + unchanged.push(pkg); + continue; + } + const back = + from !== undefined && + !DEVELOPMENT_BUILD.test(from) && + compareVersions(pkg.version, from) < 0; + moves.push({ ...pkg, from, back }); + } + const backwards = moves.filter(({ back }) => back); + if (backwards.length > 0 && !options.allowDowngrade) { + throw new PromotionError( + [ + "Promoting this release would move latest back to an older version for these packages:", + ...backwards.map( + ({ name, version, from }) => ` ${name}: ${from} -> ${version}`, + ), + "To roll latest back on purpose, run the promotion again with allow-downgrade on.", + ].join("\n"), + ); + } + const pinProblems = productPinProblems( + options.pins, + options.allowDowngrade && backwards.length > 0, + ); + if (pinProblems.length > 0) { + throw new PromotionError(pinProblems.join("\n")); + } + return { moves, unchanged }; +} + +function productPinProblems( + pins: readonly ProductPin[], + rollback: boolean, +): string[] { + const problems: string[] = []; + for (const { name, pinned, latest } of pins) { + if (latest === undefined || compareVersions(pinned, latest) > 0) { + problems.push( + `The release pins ${name}@${pinned}, but its latest is ${latest ?? "unset"}. Promote the ORM and Composer releases first.`, + ); + } else if (!rollback && compareVersions(pinned, latest) < 0) { + problems.push( + `The release pins ${name}@${pinned}, older than its latest, ${latest}. Promote a CLI release that pins ${latest}.`, + ); + } + } + return problems; +} + +export function formatPromotion(promotion: Promotion): string { + return [ + ...promotion.moves.map( + ({ name, version, from, back }) => + `${name}: latest moves ${back ? "back " : ""}${from ?? "(none)"} -> ${version}`, + ), + ...promotion.unchanged.map( + ({ name, version }) => `${name}: latest is already ${version}`, + ), + `${promotion.moves.length} to move, ${promotion.unchanged.length} already there.`, + ].join("\n"); +} + +export function promotionPlan( + version: string, + promotion: Promotion, +): PromotionPlan { + return { + version, + packages: [...promotion.moves, ...promotion.unchanged] + .map(({ name, version: packageVersion }) => ({ + name, + version: packageVersion, + })) + .sort((a, b) => (a.name < b.name ? -1 : 1)), + }; +} diff --git a/scripts/promote-release.ts b/scripts/promote-release.ts new file mode 100644 index 000000000..decf94ea2 --- /dev/null +++ b/scripts/promote-release.ts @@ -0,0 +1,148 @@ +#!/usr/bin/env node + +// Checks a published release before the promotion workflow moves `latest` to it, and writes what +// to move (docs/oss/versioning.md). It moves no tag and needs no token. Usage: +// node scripts/promote-release.ts [--release-root ] [--allow-downgrade] +// [--plan-out ] +// `--release-root` is a checkout of the release's tag, `v`, read as data only: its +// root, `packages/cli` and `packages/prisma` manifests. It defaults to this repository. + +import { spawnSync } from "node:child_process"; +import { readFileSync, writeFileSync } from "node:fs"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; +import { + formatPromotion, + type ProductPin, + type Promotion, + PromotionError, + planPromotion, + promotionPlan, + registryStateFrom, + releaseRootMismatch, +} from "./promote-release-utils.ts"; + +const USAGE = + "Usage: node scripts/promote-release.ts [--release-root ] [--allow-downgrade] [--plan-out ]"; + +const PROMOTED_MANIFESTS = [ + "packages/cli/package.json", + "packages/prisma/package.json", +]; +const PRODUCT_PIN = /^@prisma\/(orm|composer)/; +const LATEST_LINE = /^latest: (\S+)$/m; + +function readJson(path: string) { + return JSON.parse(readFileSync(path, "utf-8")); +} + +function readRegistry(name: string) { + return registryStateFrom( + name, + spawnSync("npm", ["view", name, "versions", "dist-tags", "--json"], { + encoding: "utf-8", + }), + ); +} + +/** `npm dist-tag ls` is not cached the way `npm view` is, so a product promoted minutes ago is seen. */ +function readLatest(name: string): string | undefined { + const result = spawnSync("npm", ["dist-tag", "ls", name], { + encoding: "utf-8", + }); + if (result.status !== 0) { + return registryStateFrom(name, result).latest; + } + return LATEST_LINE.exec(result.stdout)?.[1]; +} + +interface Options { + readonly version: string; + readonly releaseRoot: string; + readonly allowDowngrade: boolean; + readonly planOut: string | undefined; +} + +function parseArgs(args: readonly string[]): Options | undefined { + let version: string | undefined; + let releaseRoot = dirname(dirname(fileURLToPath(import.meta.url))); + let allowDowngrade = false; + let planOut: string | undefined; + for (let index = 0; index < args.length; index++) { + const arg = args[index] ?? ""; + const value = args[index + 1]; + if (arg === "--allow-downgrade") { + allowDowngrade = true; + } else if (arg === "--release-root" && value !== undefined) { + releaseRoot = resolve(value); + index++; + } else if (arg === "--plan-out" && value !== undefined) { + planOut = resolve(value); + index++; + } else if (!arg.startsWith("--") && version === undefined) { + version = arg; + } else { + return undefined; + } + } + return version === undefined + ? undefined + : { version, releaseRoot, allowDowngrade, planOut }; +} + +function main(args: readonly string[]): number { + const options = parseArgs(args); + if (options === undefined) { + console.error(USAGE); + return 2; + } + const rootVersion: string = readJson( + join(options.releaseRoot, "package.json"), + ).version; + const mismatch = releaseRootMismatch(rootVersion, options.version); + if (mismatch !== undefined) { + console.error(mismatch); + return 1; + } + + const manifests = PROMOTED_MANIFESTS.map((path) => + readJson(join(options.releaseRoot, path)), + ); + const packages = manifests.map(({ name, version }) => ({ name, version })); + const pinned: Record = manifests[0].dependencies ?? {}; + + let promotion: Promotion; + try { + const registry = new Map( + packages.map(({ name }) => [name, readRegistry(name)]), + ); + const pins: ProductPin[] = Object.entries(pinned) + .filter(([name]) => PRODUCT_PIN.test(name)) + .map(([name, version]) => ({ + name, + pinned: version, + latest: readLatest(name), + })); + promotion = planPromotion({ + packages, + registry, + pins, + allowDowngrade: options.allowDowngrade, + }); + } catch (error) { + if (!(error instanceof PromotionError)) throw error; + console.error(error.message); + return 1; + } + console.log(`Promoting release ${options.version} to latest:`); + console.log(formatPromotion(promotion)); + if (options.planOut !== undefined) { + writeFileSync( + options.planOut, + `${JSON.stringify(promotionPlan(options.version, promotion))}\n`, + ); + } + return 0; +} + +process.exitCode = main(process.argv.slice(2)); diff --git a/scripts/promote-workflow.test.mjs b/scripts/promote-workflow.test.mjs new file mode 100644 index 000000000..2e8cba583 --- /dev/null +++ b/scripts/promote-workflow.test.mjs @@ -0,0 +1,169 @@ +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { + chmodSync, + mkdtempSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { describe, it } from "node:test"; +import { parse } from "yaml"; + +const workflow = parse( + readFileSync( + new URL("../.github/workflows/promote.yml", import.meta.url), + "utf8", + ), +); +const moveStep = workflow.jobs.promote.steps.find((step) => step.id === "move"); + +// Runs the move step against a stand-in registry client that logs its calls. `latest` gives a +// package's current latest; `missing` lists name@version the registry lacks; `failing` lists +// name@version whose tag move fails. +function runMove(plan, { latest = {}, missing = [], failing = [] } = {}) { + const dir = mkdtempSync(join(tmpdir(), "promote-move-")); + try { + const calls = join(dir, "calls"); + const list = (values) => values.map((value) => `"${value}"`).join(" "); + writeFileSync( + join(dir, "npm"), + [ + "#!/bin/bash", + `echo "$*" >> "${calls}"`, + 'if [ "$1" = view ] && [ "$3" = version ]; then', + ` for m in ${list(missing)}; do [ "$m" = "$2" ] && exit 0; done`, + ' echo "${2##*@}"; exit 0', + "fi", + 'if [ "$1" = view ]; then', + ...Object.entries(latest).map( + ([name, version]) => + ` [ "$2" = "${name}" ] && echo "${version}" && exit 0`, + ), + " echo 0.0.0; exit 0", + "fi", + `for f in ${list(failing)}; do [ "$f" = "$3" ] && exit 1; done`, + "exit 0", + "", + ].join("\n"), + ); + chmodSync(join(dir, "npm"), 0o755); + const output = join(dir, "output"); + writeFileSync(output, ""); + const result = spawnSync("bash", ["-e", "-c", moveStep.run], { + encoding: "utf8", + env: { + PATH: `${dir}:${process.env.PATH}`, + PLAN: JSON.stringify(plan), + NODE_AUTH_TOKEN: "the-token", + RUNNER_TEMP: dir, + GITHUB_OUTPUT: output, + }, + }); + const read = (file) => { + try { + return readFileSync(file, "utf8"); + } catch { + return ""; + } + }; + return { + status: result.status, + log: `${result.stdout}${result.stderr}`, + moves: read(calls) + .split("\n") + .filter((line) => line.startsWith("dist-tag")), + output: read(output).trim(), + config: read(join(dir, "promote.npmrc")), + }; + } finally { + rmSync(dir, { recursive: true, force: true }); + } +} + +const ON_MAIN = /refs\/heads\/main/; +const NOT_DRY_RUN = /!inputs\.dry-run/; +const NOT_ON_REGISTRY = /prisma@8\.1\.0 is not on the registry/; +const RERUN_FINISHES = + /Moved in this run: @prisma\/cli\. Run the workflow again to move the rest/; + +const plan = { + version: "8.1.0", + packages: ["@prisma/cli", "prisma"].map((name) => ({ + name, + version: "8.1.0", + })), +}; + +describe("promote.yml", () => { + it("keeps the token away from repository code and repository write access", () => { + const { check, promote } = workflow.jobs; + assert.equal(promote.environment, "npm-promote"); + assert.deepEqual(promote.permissions, {}); + assert.ok(promote.steps.every((step) => step.uses === undefined)); + for (const job of [check, workflow.jobs["mark-latest"]]) { + assert.equal(JSON.stringify(job).includes("NPM_PROMOTE_TOKEN"), false); + } + assert.match(promote.if, ON_MAIN); + assert.match(promote.if, NOT_DRY_RUN); + }); +}); + +describe("the move step", () => { + it("moves latest for each package not already there, and refers to the token without writing it", () => { + const result = runMove(plan, { latest: { "@prisma/cli": "8.1.0" } }); + assert.equal(result.status, 0, result.log); + assert.deepEqual( + { + moves: result.moves, + output: result.output, + tokenInConfig: result.config.includes("the-token"), + reference: result.config.includes("${NODE_AUTH_TOKEN}"), + }, + { + moves: ["dist-tag add prisma@8.1.0 latest"], + output: "version=8.1.0", + tokenInConfig: false, + reference: true, + }, + ); + }); + + for (const [what, packages] of [ + [ + "a name that is not one of ours", + [{ name: "left-pad", version: "8.1.0" }], + ], + [ + "a version that is not a version", + [{ name: "prisma", version: "8.1.0 --tag x" }], + ], + ["no package", []], + ]) { + it(`refuses a plan with ${what}, before any registry call`, () => { + const result = runMove({ version: "8.1.0", packages }); + assert.notEqual(result.status, 0); + assert.deepEqual(result.moves, []); + }); + } + + it("moves nothing when a package is missing from the registry", () => { + const result = runMove(plan, { missing: ["prisma@8.1.0"] }); + assert.notEqual(result.status, 0); + assert.deepEqual(result.moves, []); + assert.match(result.log, NOT_ON_REGISTRY); + }); + + it("says which packages moved, and that a rerun finishes, when a move fails part-way", () => { + const result = runMove(plan, { failing: ["prisma@8.1.0"] }); + assert.notEqual(result.status, 0); + assert.match(result.log, RERUN_FINISHES); + assert.deepEqual(result.moves, [ + "dist-tag add @prisma/cli@8.1.0 latest", + "dist-tag add prisma@8.1.0 latest", + "dist-tag add prisma@8.1.0 latest", + ]); + }); +}); From 4babe2c3ce69525cf1dc95a9d80ac6e39eb1bf7c Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:44:30 +1100 Subject: [PATCH 10/16] test(promote): avoid template-like strings that the linter flags Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- scripts/promote-workflow.test.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/promote-workflow.test.mjs b/scripts/promote-workflow.test.mjs index 2e8cba583..315827885 100644 --- a/scripts/promote-workflow.test.mjs +++ b/scripts/promote-workflow.test.mjs @@ -35,7 +35,7 @@ function runMove(plan, { latest = {}, missing = [], failing = [] } = {}) { `echo "$*" >> "${calls}"`, 'if [ "$1" = view ] && [ "$3" = version ]; then', ` for m in ${list(missing)}; do [ "$m" = "$2" ] && exit 0; done`, - ' echo "${2##*@}"; exit 0', + ' echo "$' + '{2##*@}"; exit 0', "fi", 'if [ "$1" = view ]; then', ...Object.entries(latest).map( @@ -83,6 +83,8 @@ function runMove(plan, { latest = {}, missing = [], failing = [] } = {}) { } } +// The npm config line refers to the token through the shell's variable syntax. +const TOKEN_REFERENCE = "$" + "{NODE_AUTH_TOKEN}"; const ON_MAIN = /refs\/heads\/main/; const NOT_DRY_RUN = /!inputs\.dry-run/; const NOT_ON_REGISTRY = /prisma@8\.1\.0 is not on the registry/; @@ -120,7 +122,7 @@ describe("the move step", () => { moves: result.moves, output: result.output, tokenInConfig: result.config.includes("the-token"), - reference: result.config.includes("${NODE_AUTH_TOKEN}"), + reference: result.config.includes(TOKEN_REFERENCE), }, { moves: ["dist-tag add prisma@8.1.0 latest"], From 5723e718c4c6cc297ebe931f9f66d5907d6b2bb9 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:45:01 +1100 Subject: [PATCH 11/16] fix(promote): a repeat run of a finished rollback passes; doc says the newer tag wins A rollback with allow-downgrade passed its first run, but a second run, with nothing left to move, refused the same older ORM or Composer pins. Older pins are now allowed whenever allow-downgrade is on and nothing moves forward. The release-automation doc now says the version-follow script takes the newer of next and latest, not next first. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- docs/oss/release-automation.md | 2 +- scripts/promote-release-utils.test.ts | 18 ++++++++++++++++++ scripts/promote-release-utils.ts | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/oss/release-automation.md b/docs/oss/release-automation.md index 1549e5590..8c99d860a 100644 --- a/docs/oss/release-automation.md +++ b/docs/oss/release-automation.md @@ -17,7 +17,7 @@ A **release** of the CLI depends only on **released** versions of the products. ## What happens when a product publishes 1. The product repository's publish workflow finishes and sends a `repository_dispatch` event of type `product-published` to `prisma/prisma-cli`. -2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. The ORM and Composer publish each release under `next` and move `latest` later, once the releases are checked together, as this repository does (see [versioning.md](versioning.md)). So the script reads `next` first and falls back to `latest` for a product that does not publish `next`. Reading `next` lets a product release reach the CLI as soon as it publishes, and keeps the script from moving pins back to an older `latest` while a release waits to be promoted. `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each package that reads a tag of its own (`@prisma/composer-cli`, `@prisma/composer` and `@prisma/orm-toolchain`; the rest copy one of these) carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". +2. [`update-product-versions.yml`](../../.github/workflows/update-product-versions.yml) runs [`scripts/update-product-versions.mjs`](../../scripts/update-product-versions.mjs), which asks the registry for each watched package's version at its **release** dist-tag and rewrites `packages/cli/package.json` and `packages/prisma/package.json` where they differ. The ORM and Composer publish each release under `next` and move `latest` later, once the releases are checked together, as this repository does (see [versioning.md](versioning.md)). So the script reads both `next` and `latest` and takes the newer version; the order of the candidate tags only decides a tie. A product that does not publish `next` yet is read from `latest`. Reading `next` lets a product release reach the CLI as soon as it publishes, and keeps the script from moving pins back to an older `latest` while a release waits to be promoted. `@prisma/orm-framework` reads no tag of its own: it takes the version found for `@prisma/orm-toolchain`, because the two must agree (from the ORM release after 8.0.0-rc.25 the toolchain names it as an exact peer) and a run during the ORM's publish must not pin the two apart. Each package that reads a tag of its own (`@prisma/composer-cli`, `@prisma/composer` and `@prisma/orm-toolchain`; the rest copy one of these) carries a list of candidate tags rather than one name, most-preferred first, so a product moving where it publishes does not silently freeze the CLI on an old version — and a package that publishes none of its candidates fails the run instead of looking like "nothing to update". 3. If any pin changed, or `main` holds pins the last release (its `v` tag) did not ship, the workflow bumps the CLI to its next version with `pnpm bump-version` (which also refreshes `pnpm-lock.yaml`), opens a pull request titled `Release : follow the products' released versions: ...`, and arms auto-merge. Every earlier open pull request from this workflow, and every open `Bump to version` release pull request, is closed first: each bumps the same version, so only one can merge. 4. The pull request runs the full quality and conformance checks. When they pass and CodeRabbit approves it (the `main` ruleset requires one approving review), it merges, and that push to `main` changes the root version, so [`publish.yml`](../../.github/workflows/publish.yml) publishes the release under `next` with the committed product versions, plus the usual `dev` build. `latest` moves when a maintainer promotes the release with [`promote.yml`](../../.github/workflows/promote.yml). diff --git a/scripts/promote-release-utils.test.ts b/scripts/promote-release-utils.test.ts index 268abc812..06c90f28f 100644 --- a/scripts/promote-release-utils.test.ts +++ b/scripts/promote-release-utils.test.ts @@ -175,6 +175,24 @@ describe("planPromotion", () => { }); }); +describe("a finished rollback", () => { + it("passes a repeat run, so the second run is harmless as promised", () => { + const promotion = planPromotion({ + packages: release.map(({ name }) => ({ name, version: "8.0.0-rc.35" })), + registry: onRegistry("8.0.0-rc.35"), + pins: [ + { + name: "@prisma/orm-toolchain", + pinned: "8.0.0-rc.25", + latest: "8.0.0-rc.26", + }, + ], + allowDowngrade: true, + }); + assert.equal(promotion.moves.length, 0); + }); +}); + describe("registryStateFrom", () => { it("reads versions and latest", () => { assert.deepEqual( diff --git a/scripts/promote-release-utils.ts b/scripts/promote-release-utils.ts index ff3c17de1..f1cbbb09c 100644 --- a/scripts/promote-release-utils.ts +++ b/scripts/promote-release-utils.ts @@ -142,7 +142,8 @@ export function planPromotion(options: { } const pinProblems = productPinProblems( options.pins, - options.allowDowngrade && backwards.length > 0, + // A rollback, or a repeat run of one that already finished: nothing moves forward. + options.allowDowngrade && moves.every(({ back }) => back), ); if (pinProblems.length > 0) { throw new PromotionError(pinProblems.join("\n")); From 509aa0818a1791d1d8fa9533b64ef589b3ca22c4 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:46:51 +1100 Subject: [PATCH 12/16] fix(promote): refuse range pins, read pins from both packages, check the release Review fixes: - A pin that is not an exact version (such as ^0.40.0) is refused; it compared as equal to any latest before. - ORM and Composer pins are read from both prisma and @prisma/cli, and a difference between them is refused; the selection is now tested. - check refuses a stable version whose GitHub Release is missing or a draft, so marking it Latest cannot fail after npm has changed. - The workflow test also refuses @prisma/cli-engine and "prismax" in a plan. - versioning.md names the ORM PR it follows, says the tag must exist, and says which steps read the token. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 13 ++++++ docs/oss/versioning.md | 6 +-- scripts/promote-release-utils.test.ts | 58 +++++++++++++++++++++++++++ scripts/promote-release-utils.ts | 40 +++++++++++++++++- scripts/promote-release.ts | 11 +++-- scripts/promote-workflow.test.mjs | 8 ++++ 6 files changed, 126 insertions(+), 10 deletions(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 657528035..5baa4a055 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -92,6 +92,19 @@ jobs: exit 1 fi + # Checked before npm changes, so marking a stable release Latest cannot fail + # after `latest` has moved. A tag can exist with no release. + - name: Check a stable release's GitHub Release exists + if: ${{ !contains(inputs.version, '-') }} + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ inputs.version }} + run: | + if ! gh release view "v$VERSION" --repo "$GITHUB_REPOSITORY" --json isDraft --jq '.isDraft == false' | grep -qx true; then + echo "::error::GitHub Release v$VERSION is missing or still a draft. Publish it first; nothing was changed." + exit 1 + fi + - name: Set up Node.js uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 6f83f6cdf..a66b0c4a5 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -91,9 +91,9 @@ If the publish needs to be re-run (transient registry failure, etc.), a maintain ## Procedure: promote a release to `latest` -[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand with the version to promote. It has the same shape as the ORM's and Composer's promotion workflows, in three jobs: +[`promote.yml`](../../.github/workflows/promote.yml) is dispatched by hand with the version to promote. It has the same shape as the ORM's (prisma/orm#31329), in three jobs: -1. `check` holds no token and only reads. It checks out the release's git tag `v` as data, confirms that the tag's commit is on `main`, and runs this workflow's own [`scripts/promote-release.ts`](../../scripts/promote-release.ts) on it. Nothing changes unless every check passes: +1. `check` holds no token and only reads. It checks out the release's git tag `v`, which the publish workflow creates with the release, as data, confirms that the tag's commit is on `main` and, for a stable version, that its GitHub Release is published, and runs this workflow's own [`scripts/promote-release.ts`](../../scripts/promote-release.ts) on it. Nothing changes unless every check passes: - `prisma` and `@prisma/cli` are on npm at that version. - The move does not take `latest` back to an older version. To roll back, run with `allow-downgrade` on. A rollback leaves `next` on the withdrawn release, and the version-follow script follows `next`, so ship a fixed release soon after; for an ORM or Composer rollback, the CLI cannot be promoted until that product's fix release is followed. - Every ORM and Composer version that `@prisma/cli` pins at that version is exactly `latest`. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. A CLI that pins older products than `latest` is refused too, except in a rollback. @@ -114,7 +114,7 @@ For each promotion: 4. Dispatch `promote.yml` again with `dry-run` off. 5. Delete the secret from the environment and revoke the token on npm. -The token is not a dispatch input, because dispatch inputs on a public repository are not treated as secrets. The workflow reads it only in the step that moves the tags. +The token is not a dispatch input, because dispatch inputs on a public repository are not treated as secrets. Only the `promote` job reads it: one step checks it is there and masks it in the log, and the next moves the tags. ## Procedure: validate publish changes diff --git a/scripts/promote-release-utils.test.ts b/scripts/promote-release-utils.test.ts index 06c90f28f..2a7b10697 100644 --- a/scripts/promote-release-utils.test.ts +++ b/scripts/promote-release-utils.test.ts @@ -3,6 +3,7 @@ import { describe, it } from "node:test"; import { PromotionError, planPromotion, + productPinsOf, promotionPlan, type RegistryState, registryStateFrom, @@ -14,6 +15,9 @@ const MOVES_BACK = /back to an older version/; const PRODUCTS_FIRST = /Promote the ORM and Composer releases first/; const OLDER_PIN = /older than its latest, 8\.0\.0-rc\.26/; const COULD_NOT_READ = /Could not read prisma/; +const NOT_EXACT = /not an exact version/; +const PINS_DIFFER = + /pin different versions of:\n {2}@prisma\/composer: 0\.41\.0 and 0\.40\.0/; const NAMES_CLI = /@prisma\/cli@8\.0\.0-rc\.37/; const NAMES_TAG = /v8\.0\.0-rc\.37/; @@ -175,6 +179,60 @@ describe("planPromotion", () => { }); }); +describe("product pins", () => { + it("refuses a pin that is not an exact version", () => { + assert.match( + refusal(() => + planPromotion({ + packages: release, + registry: onRegistry("8.0.0-rc.36"), + pins: [ + { name: "@prisma/composer", pinned: "^0.40.0", latest: "0.41.0" }, + ], + allowDowngrade: false, + }), + ), + NOT_EXACT, + ); + }); + + it("reads only ORM and Composer pins, from both prisma and @prisma/cli", () => { + const pins = productPinsOf([ + { + name: "@prisma/cli", + dependencies: { + "@prisma/orm-toolchain": "8.0.0-rc.26", + "@prisma/cli-engine": "0.10.4", + effect: "4.1.4", + }, + }, + { name: "prisma", dependencies: { "@prisma/composer": "0.41.0" } }, + ]); + assert.deepEqual( + [...pins], + [ + ["@prisma/orm-toolchain", "8.0.0-rc.26"], + ["@prisma/composer", "0.41.0"], + ], + ); + }); + + it("refuses when prisma and @prisma/cli pin different versions", () => { + assert.match( + refusal(() => + productPinsOf([ + { + name: "@prisma/cli", + dependencies: { "@prisma/composer": "0.41.0" }, + }, + { name: "prisma", dependencies: { "@prisma/composer": "0.40.0" } }, + ]), + ), + PINS_DIFFER, + ); + }); +}); + describe("a finished rollback", () => { it("passes a repeat run, so the second run is harmless as promised", () => { const promotion = planPromotion({ diff --git a/scripts/promote-release-utils.ts b/scripts/promote-release-utils.ts index f1cbbb09c..fb415179c 100644 --- a/scripts/promote-release-utils.ts +++ b/scripts/promote-release-utils.ts @@ -46,6 +46,8 @@ export class PromotionError extends Error {} const EMPTY: RegistryState = { versions: [], latest: undefined }; const NOT_FOUND = /E404|404 Not Found/; const DEVELOPMENT_BUILD = /-dev\.\d+$/; +const EXACT_VERSION = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/; +const PRODUCT_PIN = /^@prisma\/(orm|composer)/; /** * A package's state from the output of `npm view versions dist-tags --json`. A package @@ -157,7 +159,11 @@ function productPinProblems( ): string[] { const problems: string[] = []; for (const { name, pinned, latest } of pins) { - if (latest === undefined || compareVersions(pinned, latest) > 0) { + if (!EXACT_VERSION.test(pinned)) { + problems.push( + `The release pins ${name} as "${pinned}", which is not an exact version, so it cannot be compared with latest.`, + ); + } else if (latest === undefined || compareVersions(pinned, latest) > 0) { problems.push( `The release pins ${name}@${pinned}, but its latest is ${latest ?? "unset"}. Promote the ORM and Composer releases first.`, ); @@ -170,6 +176,38 @@ function productPinProblems( return problems; } +/** + * The ORM and Composer versions the release pins, from the dependencies of its `prisma` and + * `@prisma/cli` manifests. Both packages ship the same CLI, so they must pin the same versions. + */ +export function productPinsOf( + manifests: readonly { + readonly name: string; + readonly dependencies?: Readonly>; + }[], +): Map { + const pins = new Map(); + const differ: string[] = []; + for (const manifest of manifests) { + for (const [name, version] of Object.entries(manifest.dependencies ?? {})) { + if (!PRODUCT_PIN.test(name)) continue; + const seen = pins.get(name); + if (seen !== undefined && seen !== version) { + differ.push(` ${name}: ${seen} and ${version}`); + } + pins.set(name, version); + } + } + if (differ.length > 0) { + throw new PromotionError( + ["prisma and @prisma/cli pin different versions of:", ...differ].join( + "\n", + ), + ); + } + return pins; +} + export function formatPromotion(promotion: Promotion): string { return [ ...promotion.moves.map( diff --git a/scripts/promote-release.ts b/scripts/promote-release.ts index decf94ea2..2384f1ff6 100644 --- a/scripts/promote-release.ts +++ b/scripts/promote-release.ts @@ -17,6 +17,7 @@ import { type Promotion, PromotionError, planPromotion, + productPinsOf, promotionPlan, registryStateFrom, releaseRootMismatch, @@ -29,7 +30,6 @@ const PROMOTED_MANIFESTS = [ "packages/cli/package.json", "packages/prisma/package.json", ]; -const PRODUCT_PIN = /^@prisma\/(orm|composer)/; const LATEST_LINE = /^latest: (\S+)$/m; function readJson(path: string) { @@ -109,20 +109,19 @@ function main(args: readonly string[]): number { readJson(join(options.releaseRoot, path)), ); const packages = manifests.map(({ name, version }) => ({ name, version })); - const pinned: Record = manifests[0].dependencies ?? {}; let promotion: Promotion; try { const registry = new Map( packages.map(({ name }) => [name, readRegistry(name)]), ); - const pins: ProductPin[] = Object.entries(pinned) - .filter(([name]) => PRODUCT_PIN.test(name)) - .map(([name, version]) => ({ + const pins: ProductPin[] = [...productPinsOf(manifests)].map( + ([name, version]) => ({ name, pinned: version, latest: readLatest(name), - })); + }), + ); promotion = planPromotion({ packages, registry, diff --git a/scripts/promote-workflow.test.mjs b/scripts/promote-workflow.test.mjs index 315827885..110f8024d 100644 --- a/scripts/promote-workflow.test.mjs +++ b/scripts/promote-workflow.test.mjs @@ -138,6 +138,14 @@ describe("the move step", () => { "a name that is not one of ours", [{ name: "left-pad", version: "8.1.0" }], ], + [ + "a package of ours that is not promoted", + [{ name: "@prisma/cli-engine", version: "8.1.0" }], + ], + [ + "a name that only starts like ours", + [{ name: "prismax", version: "8.1.0" }], + ], [ "a version that is not a version", [{ name: "prisma", version: "8.1.0 --tag x" }], From 6c22bda46c9a7583609c7fac4a1659392af2805c Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:48:13 +1100 Subject: [PATCH 13/16] fix(promote): a dry run cannot replace a waiting real promotion A concurrency group keeps one pending run, and a newer one replaces it, so a dry run queued behind a running promotion would drop a real one waiting there. Each dry run now gets its own group, as Composer's promote.yml does. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 5 ++++- scripts/promote-workflow.test.mjs | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 5baa4a055..8cf92a8cd 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -34,8 +34,11 @@ on: default: false type: boolean +# A group keeps only one pending run, and a newer one replaces it. So a dry run, +# from any branch, gets a group of its own, and cannot replace a real +# promotion waiting behind a running one. concurrency: - group: npm-promote + group: ${{ inputs.dry-run && format('npm-promote-dry-run-{0}', github.run_id) || 'npm-promote' }} cancel-in-progress: false permissions: {} diff --git a/scripts/promote-workflow.test.mjs b/scripts/promote-workflow.test.mjs index 110f8024d..b92f07ed1 100644 --- a/scripts/promote-workflow.test.mjs +++ b/scripts/promote-workflow.test.mjs @@ -85,6 +85,8 @@ function runMove(plan, { latest = {}, missing = [], failing = [] } = {}) { // The npm config line refers to the token through the shell's variable syntax. const TOKEN_REFERENCE = "$" + "{NODE_AUTH_TOKEN}"; +const DRY_RUN_GROUP = + /inputs\.dry-run && format\('npm-promote-dry-run-\{0\}', github\.run_id\) \|\| 'npm-promote'/; const ON_MAIN = /refs\/heads\/main/; const NOT_DRY_RUN = /!inputs\.dry-run/; const NOT_ON_REGISTRY = /prisma@8\.1\.0 is not on the registry/; @@ -113,6 +115,13 @@ describe("promote.yml", () => { }); }); +describe("concurrency", () => { + it("gives a dry run its own group, so it cannot replace a waiting real promotion", () => { + assert.match(workflow.concurrency.group, DRY_RUN_GROUP); + assert.equal(workflow.concurrency["cancel-in-progress"], false); + }); +}); + describe("the move step", () => { it("moves latest for each package not already there, and refers to the token without writing it", () => { const result = runMove(plan, { latest: { "@prisma/cli": "8.1.0" } }); From 44b384977a3607421ff03b1c88f7a99e27feb0c2 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:48:22 +1100 Subject: [PATCH 14/16] docs(versioning): the promotion check reads pins from both CLI packages Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- docs/oss/versioning.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index a66b0c4a5..5b35faca9 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -96,7 +96,7 @@ If the publish needs to be re-run (transient registry failure, etc.), a maintain 1. `check` holds no token and only reads. It checks out the release's git tag `v`, which the publish workflow creates with the release, as data, confirms that the tag's commit is on `main` and, for a stable version, that its GitHub Release is published, and runs this workflow's own [`scripts/promote-release.ts`](../../scripts/promote-release.ts) on it. Nothing changes unless every check passes: - `prisma` and `@prisma/cli` are on npm at that version. - The move does not take `latest` back to an older version. To roll back, run with `allow-downgrade` on. A rollback leaves `next` on the withdrawn release, and the version-follow script follows `next`, so ship a fixed release soon after; for an ORM or Composer rollback, the CLI cannot be promoted until that product's fix release is followed. - - Every ORM and Composer version that `@prisma/cli` pins at that version is exactly `latest`. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. A CLI that pins older products than `latest` is refused too, except in a rollback. + - Every ORM and Composer version that `prisma` and `@prisma/cli` pin at that version is exactly `latest`, and the two pin the same versions. A CLI promoted ahead of its products would give `npm install prisma` users a CLI whose ORM and Composer are not `latest` yet, so promote the ORM and Composer releases first. A CLI that pins older products than `latest` is refused too, except in a rollback. 2. `promote` runs only from `main` and only when `dry-run` is off. It is the only job in the `npm-promote` environment and the only one that reads the token; it checks out no code and has no repository permissions. It checks the plan `check` produced, moves `latest` for each package not already there, and says which moved if one fails, so a second run finishes the rest. 3. `mark-latest` marks the GitHub Release as Latest when it is a stable release. The publish workflow creates every GitHub Release without that mark, so GitHub's latest release matches npm's `latest` (GitHub never lets a pre-release be Latest). From a1984f96a698fb3b2c0a13572961422d9aea8a9f Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:48:59 +1100 Subject: [PATCH 15/16] fix(promote): only a real run from main joins the promotion's concurrency group Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 8cf92a8cd..84bef0072 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -34,11 +34,12 @@ on: default: false type: boolean -# A group keeps only one pending run, and a newer one replaces it. So a dry run, -# from any branch, gets a group of its own, and cannot replace a real -# promotion waiting behind a running one. +# A group keeps only one pending run, and a newer one replaces it. So any run +# that is not a real promotion from main (a dry run, or a run from another +# branch, which fails its input check) gets a group of its own, and cannot +# replace a real promotion waiting behind a running one. concurrency: - group: ${{ inputs.dry-run && format('npm-promote-dry-run-{0}', github.run_id) || 'npm-promote' }} + group: ${{ (inputs.dry-run || github.ref != 'refs/heads/main') && format('npm-promote-dry-run-{0}', github.run_id) || 'npm-promote' }} cancel-in-progress: false permissions: {} From 792591dd9b08f596bb55312ef613a04f177df8a8 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:49:19 +1100 Subject: [PATCH 16/16] test(promote): match the concurrency group for runs off main Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- scripts/promote-workflow.test.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/promote-workflow.test.mjs b/scripts/promote-workflow.test.mjs index b92f07ed1..2e455471e 100644 --- a/scripts/promote-workflow.test.mjs +++ b/scripts/promote-workflow.test.mjs @@ -86,7 +86,7 @@ function runMove(plan, { latest = {}, missing = [], failing = [] } = {}) { // The npm config line refers to the token through the shell's variable syntax. const TOKEN_REFERENCE = "$" + "{NODE_AUTH_TOKEN}"; const DRY_RUN_GROUP = - /inputs\.dry-run && format\('npm-promote-dry-run-\{0\}', github\.run_id\) \|\| 'npm-promote'/; + /^\$\{\{ \(inputs\.dry-run \|\| github\.ref != 'refs\/heads\/main'\) && format\('npm-promote-dry-run-\{0\}', github\.run_id\) \|\| 'npm-promote' \}\}$/; const ON_MAIN = /refs\/heads\/main/; const NOT_DRY_RUN = /!inputs\.dry-run/; const NOT_ON_REGISTRY = /prisma@8\.1\.0 is not on the registry/; @@ -116,7 +116,7 @@ describe("promote.yml", () => { }); describe("concurrency", () => { - it("gives a dry run its own group, so it cannot replace a waiting real promotion", () => { + it("gives every run but a real one from main its own group, so it cannot replace a waiting real promotion", () => { assert.match(workflow.concurrency.group, DRY_RUN_GROUP); assert.equal(workflow.concurrency["cancel-in-progress"], false); });