From d842e2c130da81be636ef8c8d8c1fd6cf2b86d83 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 15:50:19 +1100 Subject: [PATCH 01/11] ci(publish): a release can publish under a tag other than latest, set by the RELEASE_DIST_TAG repository variable Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/publish.yml | 6 +++- docs/oss/versioning.md | 41 +++++++++++++++++++++++-- scripts/determine-version-utils.test.ts | 38 +++++++++++++++++++++++ scripts/determine-version-utils.ts | 29 ++++++++++++++--- scripts/determine-version.ts | 14 ++++++--- 5 files changed, 117 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b467c5b8e..8b822bc13 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,10 @@ name: Publish to npm # under dist-tag `dev`. # - push to `main` with the root `version` changed → publish `` under # dist-tag `latest` and create a GitHub Release. This is how a merged -# release-bump PR auto-ships. The same run then publishes `-dev.N` +# release-bump PR auto-ships. When the repository variable +# `RELEASE_DIST_TAG` is set (e.g. `next`), the release publishes under that +# tag instead, with no GitHub Release and no prisma-cli notification; see +# docs/oss/versioning.md for the steps when `latest` later moves. The same run then publishes `-dev.N` # under `dev`, so every push to `main` — release or not — leaves the `dev` # dist-tag on a build of that commit. When releases skipped the dev # publish, `dev` sat on the previous base until the next routine push. @@ -73,6 +76,7 @@ jobs: env: GITHUB_EVENT_NAME: ${{ github.event_name }} INPUT_DIST_TAG: ${{ github.event.inputs.dist-tag }} + RELEASE_DIST_TAG: ${{ vars.RELEASE_DIST_TAG }} # `before` is the ref `main` pointed at before this push; # determine-version.ts reads root package.json there to detect release # bumps. Empty for workflow_dispatch, which the script also handles. diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 145b92e4f..2b2d81e9b 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -48,6 +48,9 @@ building on a false assumption. - **`dev`** — every push to `main` that doesn't change the root `version` produces a `-dev.N` tarball under this tag. **No stability promise** — may be yanked freely. - **`beta`** — reserved for hand-cut release candidates via `workflow_dispatch`. +- **`next`** (or another name) — a release published without moving `latest`, when the + repository variable `RELEASE_DIST_TAG` is set. See + [Release without moving `latest`](#release-without-moving-latest). ## Who can publish @@ -76,8 +79,9 @@ override the version and no separate release-manifest file. exact `X.Y.Z` pin at publish time). - [`scripts/determine-version.ts`](../../scripts/determine-version.ts) composes the version + dist-tag for a run: a push to `main` whose root `version` differs from the - previous tip is a **release bump** → publish `` under `latest` + a GitHub - Release; otherwise → `-dev.N` under `dev`. + previous tip is a **release bump** → publish `` under `latest` (or the tag + named by the `RELEASE_DIST_TAG` repository variable) + a GitHub Release when the tag + is `latest`; otherwise → `-dev.N` under `dev`. - [`scripts/check-publish-deps.mjs`](../../scripts/check-publish-deps.mjs) is a pre-publish gate: it packs every publishable tarball and fails the publish if any resolved `package.json` would carry a `workspace:` / `catalog:` specifier or a @@ -105,6 +109,39 @@ publish trigger** — there is no separate dispatch step for a normal release. Between releases, every merge to `main` publishes a `-dev.N` build under `dev` — useful for `npm install @prisma/composer@dev` reproductions. +## Release without moving `latest` + +Use this when a release must be on npm before users get it by default, for example +when Composer, Prisma ORM and the `prisma` CLI are released together and `latest` +moves for all of them at once after a final check. + +1. Set the repository variable `RELEASE_DIST_TAG` to the tag, usually `next` + (**Settings → Secrets and variables → Actions → Variables**, or + `gh variable set RELEASE_DIST_TAG --body next -R prisma/composer`). The publish + workflow reads it on every push to `main`, and fails before publishing anything if + the value is not a usable tag (lowercase letters, digits and hyphens; not `dev`). +2. Cut the release as usual (`pnpm bump-minor`, PR, merge). The workflow publishes + `` under that tag, pushes the git tag `v` and publishes the usual + `-dev.N` follow-up under `dev`. It does **not** create the GitHub Release and does + **not** notify prisma-cli, because both announce a release users get by default. +3. Delete the variable (`gh variable delete RELEASE_DIST_TAG -R prisma/composer`), so + the next release goes to `latest` again. +4. When it is time for users to get the release, a maintainer with npm publish rights + moves `latest` on every published package: + + ```bash + npm dist-tag add @prisma/composer@ latest + npm dist-tag add @prisma/composer-cli@ latest + npm dist-tag add @prisma/composer-prisma-cloud@ latest + ``` + +5. Create the GitHub Release on the existing git tag: + `gh release create v --verify-tag --title v --generate-notes -R prisma/composer`. +6. prisma-cli's `update-product-versions` workflow follows `latest`, so it picks the + release up at its next daily run. To have it open its pull request at once, run it + by hand: `gh workflow run update-product-versions.yml -R prisma/prisma-cli`. If the + CLI release already pins this version, the workflow finds nothing to change. + ## Validating publish changes Before merging anything that touches the publish pipeline, run the workflow's dry-run: diff --git a/scripts/determine-version-utils.test.ts b/scripts/determine-version-utils.test.ts index 97cab0203..62f402445 100644 --- a/scripts/determine-version-utils.test.ts +++ b/scripts/determine-version-utils.test.ts @@ -6,6 +6,7 @@ import { nextDevVersion, parseVersion, planPushPublish, + resolveReleaseDistTag, } from './determine-version-utils.ts'; describe('parseVersion', () => { @@ -102,6 +103,20 @@ describe('planPushPublish', () => { ); }); + it('publishes a release under the configured release tag', () => { + assert.deepEqual( + planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.8.0-dev.7', 'next'), + { version: '0.9.0', tag: 'next', devVersion: '0.9.0-dev.1' }, + ); + }); + + it('keeps dev builds on dev whatever the release tag', () => { + assert.deepEqual( + planPushPublish('0.9.0', { available: true, version: '0.9.0' }, '0.9.0-dev.1', 'next'), + { version: '0.9.0-dev.2', tag: 'dev' }, + ); + }); + it('falls back to a dev build when the previous version could not be read', () => { assert.deepEqual(planPushPublish('0.9.0', { available: false }, '0.8.0-dev.7'), { version: '0.9.0-dev.1', @@ -117,3 +132,26 @@ describe('planPushPublish', () => { }); }); }); + +describe('resolveReleaseDistTag', () => { + it('defaults to latest when the variable is unset or blank', () => { + assert.equal(resolveReleaseDistTag(undefined), 'latest'); + assert.equal(resolveReleaseDistTag(''), 'latest'); + assert.equal(resolveReleaseDistTag(' '), 'latest'); + }); + + it('accepts a named tag', () => { + assert.equal(resolveReleaseDistTag('next'), 'next'); + assert.equal(resolveReleaseDistTag(' next '), 'next'); + }); + + it('refuses dev, which the dev follow-up moves straight after', () => { + assert.throws(() => resolveReleaseDistTag('dev'), /not a usable release dist-tag/); + }); + + it('refuses tags npm would read as a version or range', () => { + assert.throws(() => resolveReleaseDistTag('1.2.3'), /not a usable release dist-tag/); + assert.throws(() => resolveReleaseDistTag('v1'), /not a usable release dist-tag/); + assert.throws(() => resolveReleaseDistTag('Next'), /not a usable release dist-tag/); + }); +}); diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index 5080beef4..c34bf8700 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -67,15 +67,35 @@ export type PreviousVersionLookup = export interface PushPublishPlan { version: string; - tag: 'latest' | 'dev'; + tag: string; devVersion?: string; } +const RELEASE_DIST_TAG_PATTERN = /^[a-z][a-z0-9-]*$/; +const VERSION_LIKE_PATTERN = /^v\d/; + +/** + * The dist-tag a release bump publishes under: `latest` unless the + * `RELEASE_DIST_TAG` repository variable names another. `dev` is refused + * because the release's dev follow-up moves `dev` straight after. + */ +export function resolveReleaseDistTag(configured: string | undefined): string { + const tag = configured?.trim() || 'latest'; + if (!RELEASE_DIST_TAG_PATTERN.test(tag) || VERSION_LIKE_PATTERN.test(tag) || tag === 'dev') { + throw new Error( + `RELEASE_DIST_TAG "${tag}" is not a usable release dist-tag. ` + + 'Use lowercase letters, digits and hyphens, starting with a letter other than a "v" and digit (e.g. "next"), and not "dev"; ' + + 'or delete the repository variable to release under "latest".', + ); + } + return tag; +} + /** * The publish plan for a push to `main`. A changed root version means - * the push is a release bump: publish `` under `latest`, plus a + * the push is a release bump: publish `` under `releaseTag`, plus a * `-dev.N` follow-up so the `dev` dist-tag never falls behind - * `latest`. An unchanged (or unreadable — a transient git error must + * the release. An unchanged (or unreadable — a transient git error must * never silently promote to `latest`) previous version means the usual * dev-only publish. */ @@ -83,10 +103,11 @@ export function planPushPublish( base: string, previous: PreviousVersionLookup, latestDevTag: string | undefined, + releaseTag = 'latest', ): PushPublishPlan { const isReleaseBump = previous.available && previous.version !== base; if (isReleaseBump) { - return { version: base, tag: 'latest', devVersion: nextDevVersion(base, latestDevTag) }; + return { version: base, tag: releaseTag, devVersion: nextDevVersion(base, latestDevTag) }; } return { version: nextDevVersion(base, latestDevTag), tag: 'dev' }; } diff --git a/scripts/determine-version.ts b/scripts/determine-version.ts index ee88e5225..08e5c3a0b 100644 --- a/scripts/determine-version.ts +++ b/scripts/determine-version.ts @@ -9,7 +9,8 @@ * appropriate to the GitHub event: * * - `push` → if the root `version` changed in this push, - * `` (no suffix), dist-tag `latest`. This + * `` (no suffix), dist-tag `latest`, or the + * `RELEASE_DIST_TAG` repository variable when set. This * is how a merged `chore(release): ...` PR * ships a stable release automatically. The * plan then also carries `devVersion` @@ -33,7 +34,11 @@ import { appendFileSync, readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'pathe'; import type { PreviousVersionLookup } from './determine-version-utils.ts'; -import { assertCanonicalBase, planPushPublish } from './determine-version-utils.ts'; +import { + assertCanonicalBase, + planPushPublish, + resolveReleaseDistTag, +} from './determine-version-utils.ts'; const PACKAGE_NAME = process.argv[2] ?? '@prisma/composer'; @@ -128,9 +133,10 @@ switch (eventName) { break; case 'push': { + const releaseTag = resolveReleaseDistTag(process.env.RELEASE_DIST_TAG); const previous = readPreviousRootVersion(); - result = planPushPublish(baseVersion, previous, getLatestDevVersion()); - if (result.tag === 'latest') { + result = planPushPublish(baseVersion, previous, getLatestDevVersion(), releaseTag); + if (result.devVersion) { console.log( `Previous root version: ${previous.available ? (previous.version ?? '(unset)') : '(unreadable)'} → release bump detected.`, ); From 3a6102017e930be8c33fc463bb21b826ba54ed19 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 15:55:07 +1100 Subject: [PATCH 02/11] ci(publish): a release under another tag still gets its GitHub Release, CLI notification and dev build; review fixes Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/publish.yml | 33 +++++++------- docs/oss/versioning.md | 60 +++++++++++++++---------- scripts/determine-version-utils.test.ts | 24 +++++----- scripts/determine-version-utils.ts | 20 ++++++--- scripts/determine-version.ts | 15 ++++++- 5 files changed, 95 insertions(+), 57 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8b822bc13..b09b88b1f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,9 +11,9 @@ name: Publish to npm # - push to `main` with the root `version` changed → publish `` under # dist-tag `latest` and create a GitHub Release. This is how a merged # release-bump PR auto-ships. When the repository variable -# `RELEASE_DIST_TAG` is set (e.g. `next`), the release publishes under that -# tag instead, with no GitHub Release and no prisma-cli notification; see -# docs/oss/versioning.md for the steps when `latest` later moves. The same run then publishes `-dev.N` +# `RELEASE_DIST_TAG` is set (e.g. `rc`), the release publishes under that +# tag instead and `latest` stays put; everything else about the release is +# the same (docs/oss/versioning.md). The same run then publishes `-dev.N` # under `dev`, so every push to `main` — release or not — leaves the `dev` # dist-tag on a build of that commit. When releases skipped the dev # publish, `dev` sat on the previous base until the next routine push. @@ -139,10 +139,11 @@ jobs: NPM_CONFIG_PROVENANCE: "true" run: node scripts/publish-packages.mjs --tag "${{ steps.version.outputs.tag }}" - # Lightweight git tag for non-stable publishes (dev / beta). Stable publishes - # get a tag via `gh release create` below. Idempotent: skip if v$VERSION exists. - - name: Create lightweight git tag for non-stable publishes - if: ${{ steps.version.outputs.tag != 'latest' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} + # Lightweight git tag for publishes that are not releases (a manual run + # under a tag such as `beta`). Releases get their tag from + # `gh release create` below. Idempotent: skip if v$VERSION exists. + - name: Create lightweight git tag for publishes that are not releases + if: ${{ steps.version.outputs.release != 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ steps.version.outputs.version }} @@ -156,11 +157,12 @@ jobs: -f "sha=$GITHUB_SHA" fi - # Emit a GitHub Release for stable publishes only (dist-tag `latest`). - # Notes are auto-generated from the commits/PRs since the previous tag. + # Emit a GitHub Release for releases: a release-bump push, under whatever + # dist-tag it published, or a manual run under `latest`. Notes are + # auto-generated from the commits/PRs since the previous tag. # Idempotent on rerun: edit an existing Release rather than re-create it. - - name: Create GitHub Release for stable publishes - if: ${{ steps.version.outputs.tag == 'latest' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} + - name: Create GitHub Release + if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ steps.version.outputs.version }} @@ -178,11 +180,12 @@ jobs: # Tell prisma-cli a release shipped so its update-product-versions # workflow can open the repin PR now instead of at its daily run - # (prisma-cli docs/oss/release-automation.md). Stable publishes only: - # the receiver re-reads the registry at the release dist-tag, so a dev - # publish would be a no-op there. Never fails the publish. + # (prisma-cli docs/oss/release-automation.md). Releases only: the + # receiver re-reads the registry at `latest`, so a dev publish would be + # a no-op there, and so is a release under another tag until `latest` + # moves. Never fails the publish. - name: Notify prisma-cli - if: ${{ steps.version.outputs.tag == 'latest' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} + if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} continue-on-error: true env: GH_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }} diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 2b2d81e9b..22c0458dd 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -27,9 +27,9 @@ Every workspace package — publishable, private, and the workspace root — car same `version`. One read of root `package.json` answers "what version is this code?" for the entire repository. -- The two published packages (`@prisma/composer` and `@prisma/composer-prisma-cloud` - — the only publishable packages, both under `packages/9-public/`, ADR-0027) - publish at the same version, and each pins its workspace siblings to that +- The published packages (`@prisma/composer`, `@prisma/composer-cli` and + `@prisma/composer-prisma-cloud` — the only publishable packages, all under + `packages/9-public/`, ADR-0027) publish at the same version, and each pins its workspace siblings to that **exact** version. - Private packages (the `@internal/*` workspace packages, build config, examples, tests) are never published but still version in lockstep, so a contributor @@ -44,11 +44,11 @@ building on a false assumption. - **`latest`** — the most recent stable release; the default for `npm install @prisma/composer`. New `latest` releases happen automatically when a release PR merges - (see procedure below). + (see procedure below), unless the repository variable `RELEASE_DIST_TAG` is set. - **`dev`** — every push to `main` that doesn't change the root `version` produces a `-dev.N` tarball under this tag. **No stability promise** — may be yanked freely. - **`beta`** — reserved for hand-cut release candidates via `workflow_dispatch`. -- **`next`** (or another name) — a release published without moving `latest`, when the +- **`rc`** (or another name) — a release published without moving `latest`, when the repository variable `RELEASE_DIST_TAG` is set. See [Release without moving `latest`](#release-without-moving-latest). @@ -80,8 +80,7 @@ override the version and no separate release-manifest file. - [`scripts/determine-version.ts`](../../scripts/determine-version.ts) composes the version + dist-tag for a run: a push to `main` whose root `version` differs from the previous tip is a **release bump** → publish `` under `latest` (or the tag - named by the `RELEASE_DIST_TAG` repository variable) + a GitHub Release when the tag - is `latest`; otherwise → `-dev.N` under `dev`. + named by the `RELEASE_DIST_TAG` repository variable) + a GitHub Release; otherwise → `-dev.N` under `dev`. - [`scripts/check-publish-deps.mjs`](../../scripts/check-publish-deps.mjs) is a pre-publish gate: it packs every publishable tarball and fails the publish if any resolved `package.json` would carry a `workspace:` / `catalog:` specifier or a @@ -97,12 +96,16 @@ publish trigger** — there is no separate dispatch step for a normal release. ## Procedure: cut the next minor -1. From a clean `main`, run **`pnpm bump-minor`** in a fresh branch. It reads the root +1. Check that the repository variable `RELEASE_DIST_TAG` is not set + (`gh variable list -R prisma/composer`), unless you mean to + [release without moving `latest`](#release-without-moving-latest). Every publish + run also shows a warning while it is set. +2. From a clean `main`, run **`pnpm bump-minor`** in a fresh branch. It reads the root version at `HEAD`, computes the next minor (`0.1.0` → `0.2.0`), stamps every workspace `package.json`, and regenerates `pnpm-lock.yaml` (CI installs with `--frozen-lockfile`, so a bump committed without the lockfile fails every job). -2. Open a PR titled `chore(release): v`. CI runs normally. -3. **Merge it.** The push to `main` changes the root version, so the `Publish to npm` +3. Open a PR titled `chore(release): v`. CI runs normally. +4. **Merge it.** The push to `main` changes the root version, so the `Publish to npm` workflow recognises a release bump, publishes every package at `` under `latest`, and cuts a GitHub Release with auto-generated notes. @@ -115,19 +118,29 @@ Use this when a release must be on npm before users get it by default, for examp when Composer, Prisma ORM and the `prisma` CLI are released together and `latest` moves for all of them at once after a final check. -1. Set the repository variable `RELEASE_DIST_TAG` to the tag, usually `next` +1. Set the repository variable `RELEASE_DIST_TAG` to the tag, usually `rc` (**Settings → Secrets and variables → Actions → Variables**, or - `gh variable set RELEASE_DIST_TAG --body next -R prisma/composer`). The publish - workflow reads it on every push to `main`, and fails before publishing anything if - the value is not a usable tag (lowercase letters, digits and hyphens; not `dev`). + `gh variable set RELEASE_DIST_TAG --body rc -R prisma/composer`). The publish + workflow reads it when each run starts. While it is set, every run shows a warning, + and a value that is not a usable tag fails the run before anything is built or + published. A usable tag is lowercase letters, digits and hyphens, starts with a + letter, is not `dev`, and is not something npm reads as a version range (such as + `v1` or `x`). 2. Cut the release as usual (`pnpm bump-minor`, PR, merge). The workflow publishes - `` under that tag, pushes the git tag `v` and publishes the usual - `-dev.N` follow-up under `dev`. It does **not** create the GitHub Release and does - **not** notify prisma-cli, because both announce a release users get by default. -3. Delete the variable (`gh variable delete RELEASE_DIST_TAG -R prisma/composer`), so + `` under that tag instead of `latest`. Everything else is the same as for a + normal release: the GitHub Release, the prisma-cli notification and the `-dev.N` + follow-up under `dev`. prisma-cli reads Composer's `latest`, so the notification + changes nothing there until `latest` moves. +3. Wait until the publish run has succeeded and npm shows the version under the tag + (`npm view @prisma/composer dist-tags`). If the run fails, re-run it with the + variable still set. The workflow reads the variable when the run starts, not when + the release merged, so a run that starts after the variable is gone publishes to + `latest`. +4. Delete the variable (`gh variable delete RELEASE_DIST_TAG -R prisma/composer`), so the next release goes to `latest` again. -4. When it is time for users to get the release, a maintainer with npm publish rights - moves `latest` on every published package: +5. When it is time for users to get the release, a maintainer with npm publish rights + moves `latest` on every package the workflow publishes (every workspace package that + is not private; today these three): ```bash npm dist-tag add @prisma/composer@ latest @@ -135,8 +148,7 @@ moves for all of them at once after a final check. npm dist-tag add @prisma/composer-prisma-cloud@ latest ``` -5. Create the GitHub Release on the existing git tag: - `gh release create v --verify-tag --title v --generate-notes -R prisma/composer`. + The `rc` tag can stay where it is; the next release under it moves it. 6. prisma-cli's `update-product-versions` workflow follows `latest`, so it picks the release up at its next daily run. To have it open its pull request at once, run it by hand: `gh workflow run update-product-versions.yml -R prisma/prisma-cli`. If the @@ -156,13 +168,13 @@ cannot publish the initial version of a package via OIDC** — the package must exist before you can enable a trusted publisher (unlike PyPI). So the first release is a one-time manual bootstrap; every release after that goes through the workflow: -_Completed 2026-07-12 for both packages; kept as the procedure for any future +_Completed 2026-07-12 for the packages published then; kept as the procedure for any future package (e.g. a new `@prisma/composer-`)._ 1. **Create the package once, with a token.** On a machine logged in to npm as a user with publish rights to the `@prisma` scope: `pnpm install && pnpm build`, then `node scripts/publish-packages.mjs --tag latest`. This publishes the - publishable packages (the two in `packages/9-public/`) at the current root + publishable packages (those in `packages/9-public/`) at the current root version with correct exact-pinned deps. 2. **Configure a trusted publisher on each published package** at `npmjs.com/package//access` → *Trusted Publisher* → GitHub Actions: diff --git a/scripts/determine-version-utils.test.ts b/scripts/determine-version-utils.test.ts index 62f402445..170dbf789 100644 --- a/scripts/determine-version-utils.test.ts +++ b/scripts/determine-version-utils.test.ts @@ -85,35 +85,35 @@ describe('planPushPublish', () => { it('publishes a dev build when the root version is unchanged', () => { assert.deepEqual( planPushPublish('0.8.0', { available: true, version: '0.8.0' }, '0.8.0-dev.4'), - { version: '0.8.0-dev.5', tag: 'dev' }, + { version: '0.8.0-dev.5', tag: 'dev', release: false }, ); }); it('publishes a release plus a dev follow-up when the root version changed', () => { assert.deepEqual( planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.8.0-dev.7'), - { version: '0.9.0', tag: 'latest', devVersion: '0.9.0-dev.1' }, + { version: '0.9.0', tag: 'latest', release: true, devVersion: '0.9.0-dev.1' }, ); }); it('continues the dev counter on a release rerun whose dev build already landed', () => { assert.deepEqual( planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.9.0-dev.1'), - { version: '0.9.0', tag: 'latest', devVersion: '0.9.0-dev.2' }, + { version: '0.9.0', tag: 'latest', release: true, devVersion: '0.9.0-dev.2' }, ); }); it('publishes a release under the configured release tag', () => { assert.deepEqual( - planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.8.0-dev.7', 'next'), - { version: '0.9.0', tag: 'next', devVersion: '0.9.0-dev.1' }, + planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.8.0-dev.7', 'rc'), + { version: '0.9.0', tag: 'rc', release: true, devVersion: '0.9.0-dev.1' }, ); }); it('keeps dev builds on dev whatever the release tag', () => { assert.deepEqual( - planPushPublish('0.9.0', { available: true, version: '0.9.0' }, '0.9.0-dev.1', 'next'), - { version: '0.9.0-dev.2', tag: 'dev' }, + planPushPublish('0.9.0', { available: true, version: '0.9.0' }, '0.9.0-dev.1', 'rc'), + { version: '0.9.0-dev.2', tag: 'dev', release: false }, ); }); @@ -121,6 +121,7 @@ describe('planPushPublish', () => { assert.deepEqual(planPushPublish('0.9.0', { available: false }, '0.8.0-dev.7'), { version: '0.9.0-dev.1', tag: 'dev', + release: false, }); }); @@ -128,6 +129,7 @@ describe('planPushPublish', () => { assert.deepEqual(planPushPublish('0.9.0', { available: true, version: undefined }, undefined), { version: '0.9.0', tag: 'latest', + release: true, devVersion: '0.9.0-dev.1', }); }); @@ -141,17 +143,19 @@ describe('resolveReleaseDistTag', () => { }); it('accepts a named tag', () => { - assert.equal(resolveReleaseDistTag('next'), 'next'); - assert.equal(resolveReleaseDistTag(' next '), 'next'); + assert.equal(resolveReleaseDistTag('rc'), 'rc'); + assert.equal(resolveReleaseDistTag(' rc '), 'rc'); }); it('refuses dev, which the dev follow-up moves straight after', () => { assert.throws(() => resolveReleaseDistTag('dev'), /not a usable release dist-tag/); }); - it('refuses tags npm would read as a version or range', () => { + it('refuses tags npm would read as a version or range, and uppercase', () => { assert.throws(() => resolveReleaseDistTag('1.2.3'), /not a usable release dist-tag/); assert.throws(() => resolveReleaseDistTag('v1'), /not a usable release dist-tag/); + assert.throws(() => resolveReleaseDistTag('x'), /not a usable release dist-tag/); + assert.throws(() => resolveReleaseDistTag('vx'), /not a usable release dist-tag/); assert.throws(() => resolveReleaseDistTag('Next'), /not a usable release dist-tag/); }); }); diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index c34bf8700..e7c6ee1de 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -68,11 +68,13 @@ export type PreviousVersionLookup = export interface PushPublishPlan { version: string; tag: string; + release: boolean; devVersion?: string; } const RELEASE_DIST_TAG_PATTERN = /^[a-z][a-z0-9-]*$/; -const VERSION_LIKE_PATTERN = /^v\d/; +// npm refuses a dist-tag that parses as a semver range: `v1`, `x`, `vx`. +const SEMVER_RANGE_LIKE_PATTERN = /^v?(\d|x$)/; /** * The dist-tag a release bump publishes under: `latest` unless the @@ -81,11 +83,12 @@ const VERSION_LIKE_PATTERN = /^v\d/; */ export function resolveReleaseDistTag(configured: string | undefined): string { const tag = configured?.trim() || 'latest'; - if (!RELEASE_DIST_TAG_PATTERN.test(tag) || VERSION_LIKE_PATTERN.test(tag) || tag === 'dev') { + if (!RELEASE_DIST_TAG_PATTERN.test(tag) || SEMVER_RANGE_LIKE_PATTERN.test(tag) || tag === 'dev') { throw new Error( `RELEASE_DIST_TAG "${tag}" is not a usable release dist-tag. ` + - 'Use lowercase letters, digits and hyphens, starting with a letter other than a "v" and digit (e.g. "next"), and not "dev"; ' + - 'or delete the repository variable to release under "latest".', + 'A usable tag is lowercase letters, digits and hyphens, starts with a letter, ' + + 'is not "dev", and is not something npm reads as a version range (such as "v1" or "x"). ' + + 'Set it to a tag such as "rc", or delete the repository variable to release under "latest".', ); } return tag; @@ -107,7 +110,12 @@ export function planPushPublish( ): PushPublishPlan { const isReleaseBump = previous.available && previous.version !== base; if (isReleaseBump) { - return { version: base, tag: releaseTag, devVersion: nextDevVersion(base, latestDevTag) }; + return { + version: base, + tag: releaseTag, + release: true, + devVersion: nextDevVersion(base, latestDevTag), + }; } - return { version: nextDevVersion(base, latestDevTag), tag: 'dev' }; + return { version: nextDevVersion(base, latestDevTag), tag: 'dev', release: false }; } diff --git a/scripts/determine-version.ts b/scripts/determine-version.ts index 08e5c3a0b..641a24871 100644 --- a/scripts/determine-version.ts +++ b/scripts/determine-version.ts @@ -45,6 +45,7 @@ const PACKAGE_NAME = process.argv[2] ?? '@prisma/composer'; interface VersionResult { version: string; tag: string; + release: boolean; devVersion?: string; } @@ -108,6 +109,7 @@ function writeGitHubOutput(result: VersionResult): void { if (outputFile) { appendFileSync(outputFile, `version< Date: Wed, 2 Dec 2026 15:58:02 +1100 Subject: [PATCH 03/11] ci(publish)!: a release always publishes under rc and never moves latest; latest moves when a maintainer promotes the release Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/publish.yml | 47 ++++------------ docs/oss/versioning.md | 73 ++++++++----------------- scripts/determine-version-utils.test.ts | 48 ++++++---------- scripts/determine-version-utils.ts | 31 +++++------ scripts/determine-version.ts | 45 +++++++-------- 5 files changed, 85 insertions(+), 159 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b09b88b1f..c97c737b4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,16 +9,16 @@ name: Publish to npm # - push to `main` with the root `version` unchanged → publish `-dev.N` # under dist-tag `dev`. # - push to `main` with the root `version` changed → publish `` under -# dist-tag `latest` and create a GitHub Release. This is how a merged -# release-bump PR auto-ships. When the repository variable -# `RELEASE_DIST_TAG` is set (e.g. `rc`), the release publishes under that -# tag instead and `latest` stays put; everything else about the release is -# the same (docs/oss/versioning.md). The same run then publishes `-dev.N` +# dist-tag `rc` and create a GitHub Release. This is how a merged +# release-bump PR publishes a release. It never moves `latest`: a +# maintainer promotes the release to `latest` later +# (docs/oss/versioning.md). The same run then publishes `-dev.N` # under `dev`, so every push to `main` — release or not — leaves the `dev` # dist-tag on a build of that commit. When releases skipped the dev # publish, `dev` sat on the previous base until the next routine push. # - workflow_dispatch → publish `` under the chosen dist-tag (default -# `latest`); also the dry-run path. +# `rc`; `latest` is refused); also the dry-run path. A run under `rc` is a +# release and creates the GitHub Release. on: push: @@ -27,9 +27,9 @@ on: workflow_dispatch: inputs: dist-tag: - description: "npm dist-tag (e.g., latest, dev, beta)" + description: "npm dist-tag (rc for a release, or e.g. beta; latest is refused)" required: true - default: "latest" + default: "rc" type: string dry-run: description: "Dry-run only (build + pack + gate, no npm publish, no GitHub Release)." @@ -59,7 +59,7 @@ jobs: uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: # determine-version.ts compares the root `package.json` version at - # `github.event.before` to HEAD to decide dev vs latest; a multi-commit + # `github.event.before` to HEAD to decide dev vs release; a multi-commit # push can place `before` arbitrarily far back, so fetch full history. fetch-depth: 0 @@ -76,7 +76,6 @@ jobs: env: GITHUB_EVENT_NAME: ${{ github.event_name }} INPUT_DIST_TAG: ${{ github.event.inputs.dist-tag }} - RELEASE_DIST_TAG: ${{ vars.RELEASE_DIST_TAG }} # `before` is the ref `main` pointed at before this push; # determine-version.ts reads root package.json there to detect release # bumps. Empty for workflow_dispatch, which the script also handles. @@ -157,9 +156,9 @@ jobs: -f "sha=$GITHUB_SHA" fi - # Emit a GitHub Release for releases: a release-bump push, under whatever - # dist-tag it published, or a manual run under `latest`. Notes are - # auto-generated from the commits/PRs since the previous tag. + # Emit a GitHub Release for releases: a release-bump push, or a manual + # run under `rc`. Notes are auto-generated from the commits/PRs since + # the previous tag. # Idempotent on rerun: edit an existing Release rather than re-create it. - name: Create GitHub Release if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} @@ -178,28 +177,6 @@ jobs: --generate-notes fi - # Tell prisma-cli a release shipped so its update-product-versions - # workflow can open the repin PR now instead of at its daily run - # (prisma-cli docs/oss/release-automation.md). Releases only: the - # receiver re-reads the registry at `latest`, so a dev publish would be - # a no-op there, and so is a release under another tag until `latest` - # moves. Never fails the publish. - - name: Notify prisma-cli - if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} - continue-on-error: true - env: - GH_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }} - VERSION: ${{ steps.version.outputs.version }} - run: | - if [ -z "$GH_TOKEN" ]; then - echo "DEPLOY_GITHUB_TOKEN is not configured; skipping (the daily run in prisma-cli covers this)." - exit 0 - fi - gh api repos/prisma/prisma-cli/dispatches \ - -f event_type=product-published \ - -f 'client_payload[package]=@prisma/composer-cli' \ - -f "client_payload[version]=$VERSION" - # --- Dev follow-up, release pushes only (devVersion is empty otherwise). # The release steps above already ran the full check battery against this # commit; only the version stamp changes here, so the follow-up re-runs diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 22c0458dd..f21ca4da5 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -43,14 +43,15 @@ building on a false assumption. ## Dist-tag convention - **`latest`** — the most recent stable release; the default for `npm install - @prisma/composer`. New `latest` releases happen automatically when a release PR merges - (see procedure below), unless the repository variable `RELEASE_DIST_TAG` is set. + @prisma/composer`. A release reaches `latest` only when a maintainer promotes it + (see [Promote a release to `latest`](#promote-a-release-to-latest)). Merging a release + PR never moves it. +- **`rc`** — every release, as soon as its release PR merges. A release waits here + until it is promoted, for example while Composer, Prisma ORM and the `prisma` CLI + are checked together on their published versions. - **`dev`** — every push to `main` that doesn't change the root `version` produces a `-dev.N` tarball under this tag. **No stability promise** — may be yanked freely. - **`beta`** — reserved for hand-cut release candidates via `workflow_dispatch`. -- **`rc`** (or another name) — a release published without moving `latest`, when the - repository variable `RELEASE_DIST_TAG` is set. See - [Release without moving `latest`](#release-without-moving-latest). ## Who can publish @@ -79,8 +80,8 @@ override the version and no separate release-manifest file. exact `X.Y.Z` pin at publish time). - [`scripts/determine-version.ts`](../../scripts/determine-version.ts) composes the version + dist-tag for a run: a push to `main` whose root `version` differs from the - previous tip is a **release bump** → publish `` under `latest` (or the tag - named by the `RELEASE_DIST_TAG` repository variable) + a GitHub Release; otherwise → `-dev.N` under `dev`. + previous tip is a **release bump** → publish `` under `rc` + a GitHub Release; + otherwise → `-dev.N` under `dev`. - [`scripts/check-publish-deps.mjs`](../../scripts/check-publish-deps.mjs) is a pre-publish gate: it packs every publishable tarball and fails the publish if any resolved `package.json` would carry a `workspace:` / `catalog:` specifier or a @@ -96,51 +97,26 @@ publish trigger** — there is no separate dispatch step for a normal release. ## Procedure: cut the next minor -1. Check that the repository variable `RELEASE_DIST_TAG` is not set - (`gh variable list -R prisma/composer`), unless you mean to - [release without moving `latest`](#release-without-moving-latest). Every publish - run also shows a warning while it is set. -2. From a clean `main`, run **`pnpm bump-minor`** in a fresh branch. It reads the root +1. From a clean `main`, run **`pnpm bump-minor`** in a fresh branch. It reads the root version at `HEAD`, computes the next minor (`0.1.0` → `0.2.0`), stamps every workspace `package.json`, and regenerates `pnpm-lock.yaml` (CI installs with `--frozen-lockfile`, so a bump committed without the lockfile fails every job). -3. Open a PR titled `chore(release): v`. CI runs normally. -4. **Merge it.** The push to `main` changes the root version, so the `Publish to npm` +2. Open a PR titled `chore(release): v`. CI runs normally. +3. **Merge it.** The push to `main` changes the root version, so the `Publish to npm` workflow recognises a release bump, publishes every package at `` under - `latest`, and cuts a GitHub Release with auto-generated notes. + `rc`, cuts a GitHub Release with auto-generated notes, and publishes a + `-dev.1` build under `dev`. +4. **Promote it** when users should get it: see below. Between releases, every merge to `main` publishes a `-dev.N` build under `dev` — useful for `npm install @prisma/composer@dev` reproductions. -## Release without moving `latest` - -Use this when a release must be on npm before users get it by default, for example -when Composer, Prisma ORM and the `prisma` CLI are released together and `latest` -moves for all of them at once after a final check. - -1. Set the repository variable `RELEASE_DIST_TAG` to the tag, usually `rc` - (**Settings → Secrets and variables → Actions → Variables**, or - `gh variable set RELEASE_DIST_TAG --body rc -R prisma/composer`). The publish - workflow reads it when each run starts. While it is set, every run shows a warning, - and a value that is not a usable tag fails the run before anything is built or - published. A usable tag is lowercase letters, digits and hyphens, starts with a - letter, is not `dev`, and is not something npm reads as a version range (such as - `v1` or `x`). -2. Cut the release as usual (`pnpm bump-minor`, PR, merge). The workflow publishes - `` under that tag instead of `latest`. Everything else is the same as for a - normal release: the GitHub Release, the prisma-cli notification and the `-dev.N` - follow-up under `dev`. prisma-cli reads Composer's `latest`, so the notification - changes nothing there until `latest` moves. -3. Wait until the publish run has succeeded and npm shows the version under the tag - (`npm view @prisma/composer dist-tags`). If the run fails, re-run it with the - variable still set. The workflow reads the variable when the run starts, not when - the release merged, so a run that starts after the variable is gone publishes to - `latest`. -4. Delete the variable (`gh variable delete RELEASE_DIST_TAG -R prisma/composer`), so - the next release goes to `latest` again. -5. When it is time for users to get the release, a maintainer with npm publish rights - moves `latest` on every package the workflow publishes (every workspace package that - is not private; today these three): +## Promote a release to `latest` + +1. Check that every published package is on npm at the version, under `rc` + (`npm view @prisma/composer dist-tags`, and the same for each package below). +2. A maintainer with npm publish rights moves `latest` on every package the workflow + publishes (every workspace package that is not private; today these three): ```bash npm dist-tag add @prisma/composer@ latest @@ -148,11 +124,10 @@ moves for all of them at once after a final check. npm dist-tag add @prisma/composer-prisma-cloud@ latest ``` - The `rc` tag can stay where it is; the next release under it moves it. -6. prisma-cli's `update-product-versions` workflow follows `latest`, so it picks the - release up at its next daily run. To have it open its pull request at once, run it - by hand: `gh workflow run update-product-versions.yml -R prisma/prisma-cli`. If the - CLI release already pins this version, the workflow finds nothing to change. +3. prisma-cli's `update-product-versions` workflow follows Composer's `latest`, so it + picks the release up at its next daily run. To have it open its pull request at + once, run it by hand: `gh workflow run update-product-versions.yml -R prisma/prisma-cli`. + If the CLI already pins this version, the workflow finds nothing to change. ## Validating publish changes diff --git a/scripts/determine-version-utils.test.ts b/scripts/determine-version-utils.test.ts index 170dbf789..79de9b445 100644 --- a/scripts/determine-version-utils.test.ts +++ b/scripts/determine-version-utils.test.ts @@ -6,7 +6,7 @@ import { nextDevVersion, parseVersion, planPushPublish, - resolveReleaseDistTag, + resolveDispatchDistTag, } from './determine-version-utils.ts'; describe('parseVersion', () => { @@ -89,30 +89,23 @@ describe('planPushPublish', () => { ); }); - it('publishes a release plus a dev follow-up when the root version changed', () => { + it('publishes a release under rc plus a dev follow-up when the root version changed', () => { assert.deepEqual( planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.8.0-dev.7'), - { version: '0.9.0', tag: 'latest', release: true, devVersion: '0.9.0-dev.1' }, + { version: '0.9.0', tag: 'rc', release: true, devVersion: '0.9.0-dev.1' }, ); }); it('continues the dev counter on a release rerun whose dev build already landed', () => { assert.deepEqual( planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.9.0-dev.1'), - { version: '0.9.0', tag: 'latest', release: true, devVersion: '0.9.0-dev.2' }, - ); - }); - - it('publishes a release under the configured release tag', () => { - assert.deepEqual( - planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.8.0-dev.7', 'rc'), - { version: '0.9.0', tag: 'rc', release: true, devVersion: '0.9.0-dev.1' }, + { version: '0.9.0', tag: 'rc', release: true, devVersion: '0.9.0-dev.2' }, ); }); - it('keeps dev builds on dev whatever the release tag', () => { + it('keeps a dev build on dev after a release on the same base', () => { assert.deepEqual( - planPushPublish('0.9.0', { available: true, version: '0.9.0' }, '0.9.0-dev.1', 'rc'), + planPushPublish('0.9.0', { available: true, version: '0.9.0' }, '0.9.0-dev.1'), { version: '0.9.0-dev.2', tag: 'dev', release: false }, ); }); @@ -128,34 +121,25 @@ describe('planPushPublish', () => { it('treats a previous package.json without a version as a release bump', () => { assert.deepEqual(planPushPublish('0.9.0', { available: true, version: undefined }, undefined), { version: '0.9.0', - tag: 'latest', + tag: 'rc', release: true, devVersion: '0.9.0-dev.1', }); }); }); -describe('resolveReleaseDistTag', () => { - it('defaults to latest when the variable is unset or blank', () => { - assert.equal(resolveReleaseDistTag(undefined), 'latest'); - assert.equal(resolveReleaseDistTag(''), 'latest'); - assert.equal(resolveReleaseDistTag(' '), 'latest'); - }); - - it('accepts a named tag', () => { - assert.equal(resolveReleaseDistTag('rc'), 'rc'); - assert.equal(resolveReleaseDistTag(' rc '), 'rc'); +describe('resolveDispatchDistTag', () => { + it('defaults to rc when the input is blank', () => { + assert.equal(resolveDispatchDistTag(undefined), 'rc'); + assert.equal(resolveDispatchDistTag(''), 'rc'); + assert.equal(resolveDispatchDistTag(' '), 'rc'); }); - it('refuses dev, which the dev follow-up moves straight after', () => { - assert.throws(() => resolveReleaseDistTag('dev'), /not a usable release dist-tag/); + it('passes another tag through', () => { + assert.equal(resolveDispatchDistTag('beta'), 'beta'); }); - it('refuses tags npm would read as a version or range, and uppercase', () => { - assert.throws(() => resolveReleaseDistTag('1.2.3'), /not a usable release dist-tag/); - assert.throws(() => resolveReleaseDistTag('v1'), /not a usable release dist-tag/); - assert.throws(() => resolveReleaseDistTag('x'), /not a usable release dist-tag/); - assert.throws(() => resolveReleaseDistTag('vx'), /not a usable release dist-tag/); - assert.throws(() => resolveReleaseDistTag('Next'), /not a usable release dist-tag/); + it('refuses latest, which only promotion moves', () => { + assert.throws(() => resolveDispatchDistTag('latest'), /cannot publish under "latest"/); }); }); diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index e7c6ee1de..0bfc1023d 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -72,23 +72,21 @@ export interface PushPublishPlan { devVersion?: string; } -const RELEASE_DIST_TAG_PATTERN = /^[a-z][a-z0-9-]*$/; -// npm refuses a dist-tag that parses as a semver range: `v1`, `x`, `vx`. -const SEMVER_RANGE_LIKE_PATTERN = /^v?(\d|x$)/; +/** + * Every release publishes under this dist-tag and never moves `latest`. + * `latest` moves only when a maintainer promotes a published release. + */ +export const RELEASE_DIST_TAG = 'rc'; /** - * The dist-tag a release bump publishes under: `latest` unless the - * `RELEASE_DIST_TAG` repository variable names another. `dev` is refused - * because the release's dev follow-up moves `dev` straight after. + * The dist-tag for a manual publish run: the input, or `rc` when blank. + * `latest` is refused because a manual run is not how `latest` moves. */ -export function resolveReleaseDistTag(configured: string | undefined): string { - const tag = configured?.trim() || 'latest'; - if (!RELEASE_DIST_TAG_PATTERN.test(tag) || SEMVER_RANGE_LIKE_PATTERN.test(tag) || tag === 'dev') { +export function resolveDispatchDistTag(input: string | undefined): string { + const tag = input?.trim() || RELEASE_DIST_TAG; + if (tag === 'latest') { throw new Error( - `RELEASE_DIST_TAG "${tag}" is not a usable release dist-tag. ` + - 'A usable tag is lowercase letters, digits and hyphens, starts with a letter, ' + - 'is not "dev", and is not something npm reads as a version range (such as "v1" or "x"). ' + - 'Set it to a tag such as "rc", or delete the repository variable to release under "latest".', + 'A manual publish run cannot publish under "latest". Publish under "rc" and promote the release to "latest" (docs/oss/versioning.md).', ); } return tag; @@ -96,23 +94,22 @@ export function resolveReleaseDistTag(configured: string | undefined): string { /** * The publish plan for a push to `main`. A changed root version means - * the push is a release bump: publish `` under `releaseTag`, plus a + * the push is a release bump: publish `` under `rc`, plus a * `-dev.N` follow-up so the `dev` dist-tag never falls behind * the release. An unchanged (or unreadable — a transient git error must - * never silently promote to `latest`) previous version means the usual + * never silently publish a release) previous version means the usual * dev-only publish. */ export function planPushPublish( base: string, previous: PreviousVersionLookup, latestDevTag: string | undefined, - releaseTag = 'latest', ): PushPublishPlan { const isReleaseBump = previous.available && previous.version !== base; if (isReleaseBump) { return { version: base, - tag: releaseTag, + tag: RELEASE_DIST_TAG, release: true, devVersion: nextDevVersion(base, latestDevTag), }; diff --git a/scripts/determine-version.ts b/scripts/determine-version.ts index 641a24871..1c513d45c 100644 --- a/scripts/determine-version.ts +++ b/scripts/determine-version.ts @@ -9,24 +9,26 @@ * appropriate to the GitHub event: * * - `push` → if the root `version` changed in this push, - * `` (no suffix), dist-tag `latest`, or the - * `RELEASE_DIST_TAG` repository variable when set. This + * `` (no suffix), dist-tag `rc`. This * is how a merged `chore(release): ...` PR - * ships a stable release automatically. The - * plan then also carries `devVersion` - * (`-dev.N`) so the workflow can publish - * a dev build of the same commit — the `dev` - * dist-tag must never fall behind `latest`. + * publishes a release; `latest` moves later, + * when a maintainer promotes it. The plan then + * also carries `devVersion` (`-dev.N`) so + * the workflow can publish a dev build of the + * same commit — the `dev` dist-tag must never + * fall behind the release. * Otherwise, `-dev.N`, dist-tag `dev` * (N is the next available build number, * discovered by querying npm). * - `workflow_dispatch` → `` (no suffix), dist-tag from - * `INPUT_DIST_TAG` (defaults to `latest`). - * Useful as a manual escape hatch (re-publish - * after a transient failure, cut a beta). + * `INPUT_DIST_TAG` (defaults to `rc`; `latest` + * is refused). Useful as a manual escape hatch + * (re-publish after a transient failure, cut a + * beta). A run under `rc` counts as a release. * - * Outputs `version`, `tag`, and `devVersion` (empty unless the push is - * a release bump) to `$GITHUB_OUTPUT` for downstream workflow steps. + * Outputs `version`, `tag`, `release` (whether the run publishes a + * release) and `devVersion` (empty unless the push is a release bump) + * to `$GITHUB_OUTPUT` for downstream workflow steps. */ import { execFileSync, execSync } from 'node:child_process'; @@ -37,7 +39,8 @@ import type { PreviousVersionLookup } from './determine-version-utils.ts'; import { assertCanonicalBase, planPushPublish, - resolveReleaseDistTag, + RELEASE_DIST_TAG, + resolveDispatchDistTag, } from './determine-version-utils.ts'; const PACKAGE_NAME = process.argv[2] ?? '@prisma/composer'; @@ -127,25 +130,15 @@ let result: VersionResult; switch (eventName) { case 'workflow_dispatch': - // `??` is wrong here: an empty INPUT_DIST_TAG would slip through as - // the dist-tag and cause `pnpm publish --tag ""` to fail downstream. - // The workflow declares `dist-tag` with a `latest` default, so this - // fallback is a defensive belt-and-braces. { - const tag = inputDistTag || 'latest'; - result = { version: baseVersion, tag, release: tag === 'latest' }; + const tag = resolveDispatchDistTag(inputDistTag); + result = { version: baseVersion, tag, release: tag === RELEASE_DIST_TAG }; } break; case 'push': { - const releaseTag = resolveReleaseDistTag(process.env.RELEASE_DIST_TAG); - if (releaseTag !== 'latest') { - console.log( - `::warning title=Releases publish under "${releaseTag}"::The repository variable RELEASE_DIST_TAG is "${releaseTag}", so a release bump publishes under "${releaseTag}" and leaves "latest" where it is. Delete the variable to release under "latest" again (docs/oss/versioning.md).`, - ); - } const previous = readPreviousRootVersion(); - result = planPushPublish(baseVersion, previous, getLatestDevVersion(), releaseTag); + result = planPushPublish(baseVersion, previous, getLatestDevVersion()); if (result.release) { console.log( `Previous root version: ${previous.available ? (previous.version ?? '(unset)') : '(unreadable)'} → release bump detected.`, From bc15e4a45796692ee573109be701a9d774e564ad Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:03:11 +1100 Subject: [PATCH 04/11] ci(promote): a Promote to latest workflow moves latest to a published release; review fixes Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 65 ++++++++++ .github/workflows/publish.yml | 33 ++++- docs/oss/versioning.md | 62 ++++----- scripts/determine-version-utils.test.ts | 30 +++-- scripts/determine-version-utils.ts | 15 ++- scripts/determine-version.ts | 14 +- scripts/promote-packages-utils.test.ts | 48 +++++++ scripts/promote-packages-utils.ts | 38 ++++++ scripts/promote-packages.ts | 135 ++++++++++++++++++++ skills-contrib/publish-npm-version/SKILL.md | 11 +- 10 files changed, 380 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/promote.yml create mode 100644 scripts/promote-packages-utils.test.ts create mode 100644 scripts/promote-packages-utils.ts create mode 100644 scripts/promote-packages.ts diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml new file mode 100644 index 000000000..6d6131d8f --- /dev/null +++ b/.github/workflows/promote.yml @@ -0,0 +1,65 @@ +name: Promote to latest + +# A release publishes under the npm dist-tag `rc` and never moves `latest` +# (publish.yml). This workflow moves `latest` to a published release on every +# package, then marks its GitHub Release as GitHub's latest release. See +# docs/oss/versioning.md. +# +# npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a +# real run needs an npm token. The repository keeps none: the promoter adds +# the secret NPM_TOKEN to the `npm-promote` environment just before a run and +# deletes it straight after. A dry run needs no token. + +on: + workflow_dispatch: + inputs: + version: + description: "Release version to promote, e.g. 0.41.0" + required: true + type: string + dry-run: + description: "Dry-run only (check every package has the version; change nothing)." + required: false + default: true + type: boolean + +concurrency: + group: npm-publish + cancel-in-progress: false + +jobs: + promote: + name: Move latest to the release + runs-on: ubuntu-latest + if: ${{ github.ref == 'refs/heads/main' }} + environment: npm-promote + permissions: + contents: write # Required to mark the GitHub Release as latest + + steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + + - uses: ./.github/actions/setup + + - name: Promote packages (dry-run) + if: ${{ github.event.inputs.dry-run == 'true' }} + env: + VERSION: ${{ github.event.inputs.version }} + run: node scripts/promote-packages.ts --version "$VERSION" --dry-run + + - name: Promote packages + if: ${{ github.event.inputs.dry-run != 'true' }} + env: + VERSION: ${{ github.event.inputs.version }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: node scripts/promote-packages.ts --version "$VERSION" + + # The GitHub Release was created without GitHub's "Latest" mark + # (publish.yml); give it the mark now that npm `latest` is on it. + - name: Mark the GitHub Release as latest + if: ${{ github.event.inputs.dry-run != 'true' }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ github.event.inputs.version }} + run: gh release edit "v$VERSION" --latest diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c97c737b4..6819acb21 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,8 +17,8 @@ name: Publish to npm # dist-tag on a build of that commit. When releases skipped the dev # publish, `dev` sat on the previous base until the next routine push. # - workflow_dispatch → publish `` under the chosen dist-tag (default -# `rc`; `latest` is refused); also the dry-run path. A run under `rc` is a -# release and creates the GitHub Release. +# `rc`; `latest` and `dev` are refused); also the dry-run path. A run under +# `rc` re-publishes a release whose publish failed, and counts as a release. on: push: @@ -27,7 +27,7 @@ on: workflow_dispatch: inputs: dist-tag: - description: "npm dist-tag (rc for a release, or e.g. beta; latest is refused)" + description: "npm dist-tag: rc re-publishes a release whose publish failed (latest and dev are refused)" required: true default: "rc" type: string @@ -51,7 +51,7 @@ jobs: # dry-run path performs no registry writes and skips the GitHub Release step. 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 stable publishes + contents: write # Required to create the GitHub Release and git tags id-token: write # Required for npm OIDC Trusted Publishing steps: @@ -158,7 +158,8 @@ jobs: # Emit a GitHub Release for releases: a release-bump push, or a manual # run under `rc`. Notes are auto-generated from the commits/PRs since - # the previous tag. + # the previous tag. `--latest=false`: GitHub marks it its latest release + # when promote.yml moves npm `latest`. # Idempotent on rerun: edit an existing Release rather than re-create it. - name: Create GitHub Release if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} @@ -174,9 +175,31 @@ jobs: gh release create "v$VERSION" \ --target "$GITHUB_SHA" \ --title "v$VERSION" \ + --latest=false \ --generate-notes fi + # Tell prisma-cli a release shipped so its update-product-versions + # workflow can open the repin PR now instead of at its daily run + # (prisma-cli docs/oss/release-automation.md). Releases only: the + # receiver reads each product's `rc` tag first, so it finds this + # release; a dev publish would be a no-op there. Never fails the publish. + - name: Notify prisma-cli + if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }} + VERSION: ${{ steps.version.outputs.version }} + run: | + if [ -z "$GH_TOKEN" ]; then + echo "DEPLOY_GITHUB_TOKEN is not configured; skipping (the daily run in prisma-cli covers this)." + exit 0 + fi + gh api repos/prisma/prisma-cli/dispatches \ + -f event_type=product-published \ + -f 'client_payload[package]=@prisma/composer-cli' \ + -f "client_payload[version]=$VERSION" + # --- Dev follow-up, release pushes only (devVersion is empty otherwise). # The release steps above already ran the full check battery against this # commit; only the version stamp changes here, so the follow-up re-runs diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index f21ca4da5..f62da4a2c 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -42,16 +42,9 @@ building on a false assumption. ## Dist-tag convention -- **`latest`** — the most recent stable release; the default for `npm install - @prisma/composer`. A release reaches `latest` only when a maintainer promotes it - (see [Promote a release to `latest`](#promote-a-release-to-latest)). Merging a release - PR never moves it. -- **`rc`** — every release, as soon as its release PR merges. A release waits here - until it is promoted, for example while Composer, Prisma ORM and the `prisma` CLI - are checked together on their published versions. -- **`dev`** — every push to `main` that doesn't change the root `version` produces a - `-dev.N` tarball under this tag. **No stability promise** — may be yanked freely. -- **`beta`** — reserved for hand-cut release candidates via `workflow_dispatch`. +- **`latest`** — the most recent stable release; the default for `npm install @prisma/composer`. A release reaches `latest` only when a maintainer promotes it (see [Promote a release to `latest`](#promote-a-release-to-latest)). Merging a release PR never moves it. +- **`rc`** — every release, as soon as its release PR merges. A release waits here until it is promoted, for example while Composer, Prisma ORM and the `prisma` CLI are checked together on their published versions. +- **`dev`** — a `-dev.N` build of every push to `main`, release or not. **No stability promise** — may be yanked freely. ## Who can publish @@ -63,6 +56,7 @@ building on a false assumption. [npm provenance attestation](https://docs.npmjs.com/generating-provenance-statements) tying it to this repository and the workflow run that produced it (provenance requires the repo to be public, which it is). +- Moving `latest` needs an npm token, because trusted publishing does not cover `npm dist-tag`. The [`Promote to latest`](../../.github/workflows/promote.yml) workflow reads a short-lived, package-limited token from the `npm-promote` environment, which holds it only for the length of a promotion (see [Promote a release to `latest`](#promote-a-release-to-latest)). - The workflow only produces a real publish from `main`. Dry-runs are permitted from any branch via `workflow_dispatch` (see below); every step that mutates external state is independently guarded. @@ -80,8 +74,8 @@ override the version and no separate release-manifest file. exact `X.Y.Z` pin at publish time). - [`scripts/determine-version.ts`](../../scripts/determine-version.ts) composes the version + dist-tag for a run: a push to `main` whose root `version` differs from the - previous tip is a **release bump** → publish `` under `rc` + a GitHub Release; - otherwise → `-dev.N` under `dev`. + previous tip is a **release bump** → publish `` under `rc` + a GitHub Release + + a `-dev.N` build under `dev`; otherwise → `-dev.N` under `dev`. - [`scripts/check-publish-deps.mjs`](../../scripts/check-publish-deps.mjs) is a pre-publish gate: it packs every publishable tarball and fails the publish if any resolved `package.json` would carry a `workspace:` / `catalog:` specifier or a @@ -97,37 +91,28 @@ publish trigger** — there is no separate dispatch step for a normal release. ## Procedure: cut the next minor -1. From a clean `main`, run **`pnpm bump-minor`** in a fresh branch. It reads the root - version at `HEAD`, computes the next minor (`0.1.0` → `0.2.0`), stamps every - workspace `package.json`, and regenerates `pnpm-lock.yaml` (CI installs with - `--frozen-lockfile`, so a bump committed without the lockfile fails every job). +1. From a clean `main`, run **`pnpm bump-minor`** in a fresh branch. It reads the root version at `HEAD`, computes the next minor (`0.1.0` → `0.2.0`), stamps every workspace `package.json`, and regenerates `pnpm-lock.yaml` (CI installs with `--frozen-lockfile`, so a bump committed without the lockfile fails every job). 2. Open a PR titled `chore(release): v`. CI runs normally. -3. **Merge it.** The push to `main` changes the root version, so the `Publish to npm` - workflow recognises a release bump, publishes every package at `` under - `rc`, cuts a GitHub Release with auto-generated notes, and publishes a - `-dev.1` build under `dev`. -4. **Promote it** when users should get it: see below. +3. **Merge it.** The push to `main` changes the root version, so the `Publish to npm` workflow recognises a release bump. It publishes every package at `` under `rc`, cuts a GitHub Release with auto-generated notes, notifies prisma-cli (whose `update-product-versions` workflow reads Composer's `rc` tag first), and publishes a `-dev.1` build under `dev`. +4. **Promote it** when users should get it: see [Promote a release to `latest`](#promote-a-release-to-latest). -Between releases, every merge to `main` publishes a `-dev.N` build under `dev` — -useful for `npm install @prisma/composer@dev` reproductions. +If a release's publish fails, re-run the failed workflow run. If that is not possible, run **Actions → Publish to npm → Run workflow** from `main` with the dist-tag `rc` and dry-run unchecked: it re-publishes the release under `rc` and skips packages already on npm. Manual runs refuse `latest` and `dev`. + +Between releases, every merge to `main` publishes a `-dev.N` build under `dev` — useful for `npm install @prisma/composer@dev` reproductions. ## Promote a release to `latest` -1. Check that every published package is on npm at the version, under `rc` - (`npm view @prisma/composer dist-tags`, and the same for each package below). -2. A maintainer with npm publish rights moves `latest` on every package the workflow - publishes (every workspace package that is not private; today these three): +The [`Promote to latest`](../../.github/workflows/promote.yml) workflow moves `latest` to a published release on every package the publish workflow publishes (every workspace package that is not private). It first checks that every package has the version on npm, and changes nothing unless all do. Packages already on the version are left alone, so a second run is harmless. A real run then marks the release's GitHub Release as GitHub's latest release. + +npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a real run needs an npm token. The repository keeps none between promotions: - ```bash - npm dist-tag add @prisma/composer@ latest - npm dist-tag add @prisma/composer-cli@ latest - npm dist-tag add @prisma/composer-prisma-cloud@ latest - ``` +1. Check the release with a dry run, which needs no token: `gh workflow run promote.yml -R prisma/composer --ref main -f version=`. +2. On npmjs.com, create a **granular access token** with read and write access to the published packages only (`@prisma/composer`, `@prisma/composer-cli`, `@prisma/composer-prisma-cloud`) and the shortest expiry npm allows. +3. Add it to the `npm-promote` environment: `gh secret set NPM_TOKEN --env npm-promote -R prisma/composer`. It prompts for the value, so the token is not on your command line or in your shell history. +4. Run the promotion: `gh workflow run promote.yml -R prisma/composer --ref main -f version= -f dry-run=false`. +5. As soon as the run finishes, delete the secret (`gh secret delete NPM_TOKEN --env npm-promote -R prisma/composer`) and revoke the token on npmjs.com. -3. prisma-cli's `update-product-versions` workflow follows Composer's `latest`, so it - picks the release up at its next daily run. To have it open its pull request at - once, run it by hand: `gh workflow run update-product-versions.yml -R prisma/prisma-cli`. - If the CLI already pins this version, the workflow finds nothing to change. +The workflow moves `latest` to any published version you give it, older ones included, so check the version before a real run. ## Validating publish changes @@ -159,3 +144,8 @@ package (e.g. a new `@prisma/composer-`)._ - Environment: leave blank - Allowed action: **npm publish** 3. From then on, remove any token you used and let the workflow publish via OIDC. + +## One-time setup: the `npm-promote` environment (maintainers) + +1. Create the environment: **Settings → Environments → New environment**, named `npm-promote`. Under **Deployment branches and tags**, allow only `main`. It holds no secret between promotions. +2. Check each published package's **Settings → Publishing access** on npmjs.com. If it disallows tokens, the promotion's `npm dist-tag add` fails, and a maintainer moves `latest` by hand instead (`npm dist-tag add @ latest`, for each package). diff --git a/scripts/determine-version-utils.test.ts b/scripts/determine-version-utils.test.ts index 79de9b445..761428a46 100644 --- a/scripts/determine-version-utils.test.ts +++ b/scripts/determine-version-utils.test.ts @@ -5,8 +5,8 @@ import { computeNextMinor, nextDevVersion, parseVersion, + planDispatchPublish, planPushPublish, - resolveDispatchDistTag, } from './determine-version-utils.ts'; describe('parseVersion', () => { @@ -128,18 +128,30 @@ describe('planPushPublish', () => { }); }); -describe('resolveDispatchDistTag', () => { - it('defaults to rc when the input is blank', () => { - assert.equal(resolveDispatchDistTag(undefined), 'rc'); - assert.equal(resolveDispatchDistTag(''), 'rc'); - assert.equal(resolveDispatchDistTag(' '), 'rc'); +describe('planDispatchPublish', () => { + it('re-publishes a release under rc when the input is blank', () => { + for (const input of [undefined, '', ' ']) { + assert.deepEqual(planDispatchPublish('0.9.0', input), { + version: '0.9.0', + tag: 'rc', + release: true, + }); + } }); - it('passes another tag through', () => { - assert.equal(resolveDispatchDistTag('beta'), 'beta'); + it('publishes under another tag without counting as a release', () => { + assert.deepEqual(planDispatchPublish('0.9.0', 'beta'), { + version: '0.9.0', + tag: 'beta', + release: false, + }); }); it('refuses latest, which only promotion moves', () => { - assert.throws(() => resolveDispatchDistTag('latest'), /cannot publish under "latest"/); + assert.throws(() => planDispatchPublish('0.9.0', 'latest'), /cannot publish under "latest"/); + }); + + it('refuses dev, which holds dev builds', () => { + assert.throws(() => planDispatchPublish('0.9.0', 'dev'), /cannot publish under "dev"/); }); }); diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index 0bfc1023d..cd697691c 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -79,17 +79,20 @@ export interface PushPublishPlan { export const RELEASE_DIST_TAG = 'rc'; /** - * The dist-tag for a manual publish run: the input, or `rc` when blank. - * `latest` is refused because a manual run is not how `latest` moves. + * The publish plan for a manual run: `` under the input tag, or + * `rc` when blank. A run under `rc` re-publishes a release whose publish + * failed, so it counts as a release. `latest` is refused because promotion + * is how `latest` moves; `dev` is refused because a release version under + * `dev` would sit where dev builds belong. */ -export function resolveDispatchDistTag(input: string | undefined): string { +export function planDispatchPublish(base: string, input: string | undefined): PushPublishPlan { const tag = input?.trim() || RELEASE_DIST_TAG; - if (tag === 'latest') { + if (tag === 'latest' || tag === 'dev') { throw new Error( - 'A manual publish run cannot publish under "latest". Publish under "rc" and promote the release to "latest" (docs/oss/versioning.md).', + `A manual publish run cannot publish under "${tag}". Re-publish a release under "rc", and promote it to "latest" with the Promote to latest workflow (docs/oss/versioning.md).`, ); } - return tag; + return { version: base, tag, release: tag === RELEASE_DIST_TAG }; } /** diff --git a/scripts/determine-version.ts b/scripts/determine-version.ts index 1c513d45c..0c5f74b6b 100644 --- a/scripts/determine-version.ts +++ b/scripts/determine-version.ts @@ -22,9 +22,9 @@ * discovered by querying npm). * - `workflow_dispatch` → `` (no suffix), dist-tag from * `INPUT_DIST_TAG` (defaults to `rc`; `latest` - * is refused). Useful as a manual escape hatch - * (re-publish after a transient failure, cut a - * beta). A run under `rc` counts as a release. + * and `dev` are refused). The manual escape + * hatch: re-publish a release whose publish + * failed. A run under `rc` counts as a release. * * Outputs `version`, `tag`, `release` (whether the run publishes a * release) and `devVersion` (empty unless the push is a release bump) @@ -38,9 +38,8 @@ import { dirname, join } from 'pathe'; import type { PreviousVersionLookup } from './determine-version-utils.ts'; import { assertCanonicalBase, + planDispatchPublish, planPushPublish, - RELEASE_DIST_TAG, - resolveDispatchDistTag, } from './determine-version-utils.ts'; const PACKAGE_NAME = process.argv[2] ?? '@prisma/composer'; @@ -130,10 +129,7 @@ let result: VersionResult; switch (eventName) { case 'workflow_dispatch': - { - const tag = resolveDispatchDistTag(inputDistTag); - result = { version: baseVersion, tag, release: tag === RELEASE_DIST_TAG }; - } + result = planDispatchPublish(baseVersion, inputDistTag); break; case 'push': { diff --git a/scripts/promote-packages-utils.test.ts b/scripts/promote-packages-utils.test.ts new file mode 100644 index 000000000..ddd7f2f67 --- /dev/null +++ b/scripts/promote-packages-utils.test.ts @@ -0,0 +1,48 @@ +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; + +import { assertReleaseVersion, planPromotion } from './promote-packages-utils.ts'; + +describe('assertReleaseVersion', () => { + it('accepts a release version', () => { + assert.doesNotThrow(() => assertReleaseVersion('0.41.0')); + }); + + it('refuses dev builds, ranges and tags', () => { + for (const version of ['0.41.0-dev.1', '^0.41.0', 'rc', '', 'v0.41.0']) { + assert.throws(() => assertReleaseVersion(version), /not a release version/); + } + }); +}); + +describe('planPromotion', () => { + it('moves latest on every package that has the version', () => { + assert.deepEqual( + planPromotion('0.41.0', [ + { name: 'a', hasVersion: true, latest: '0.40.0' }, + { name: 'b', hasVersion: true, latest: '0.40.0' }, + ]), + { missing: [], toMove: ['a', 'b'], alreadyLatest: [] }, + ); + }); + + it('reports packages missing the version', () => { + assert.deepEqual( + planPromotion('0.41.0', [ + { name: 'a', hasVersion: true, latest: '0.40.0' }, + { name: 'b', hasVersion: false, latest: '0.40.0' }, + ]), + { missing: ['b'], toMove: ['a'], alreadyLatest: [] }, + ); + }); + + it('leaves packages already on the version alone, so a second run changes nothing', () => { + assert.deepEqual( + planPromotion('0.41.0', [ + { name: 'a', hasVersion: true, latest: '0.41.0' }, + { name: 'b', hasVersion: true, latest: undefined }, + ]), + { missing: [], toMove: ['b'], alreadyLatest: ['a'] }, + ); + }); +}); diff --git a/scripts/promote-packages-utils.ts b/scripts/promote-packages-utils.ts new file mode 100644 index 000000000..767cd20cd --- /dev/null +++ b/scripts/promote-packages-utils.ts @@ -0,0 +1,38 @@ +// Pure helpers for `promote-packages.ts`, exercised under `node --test` +// from `pnpm test:scripts`. All npm I/O lives in the caller. + +const RELEASE_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/; + +export function assertReleaseVersion(version: string): void { + if (!RELEASE_VERSION_PATTERN.test(version)) { + throw new Error( + `"${version}" is not a release version. Give the version a release published, such as "0.41.0".`, + ); + } +} + +export interface PackageOnNpm { + name: string; + hasVersion: boolean; + latest: string | undefined; +} + +export interface PromotionPlan { + missing: string[]; + toMove: string[]; + alreadyLatest: string[]; +} + +/** + * Which packages to move `latest` on. Any package without the version on + * npm is `missing`, and the caller then changes nothing at all. + */ +export function planPromotion(version: string, packages: readonly PackageOnNpm[]): PromotionPlan { + const plan: PromotionPlan = { missing: [], toMove: [], alreadyLatest: [] }; + for (const pkg of packages) { + if (!pkg.hasVersion) plan.missing.push(pkg.name); + else if (pkg.latest === version) plan.alreadyLatest.push(pkg.name); + else plan.toMove.push(pkg.name); + } + return plan; +} diff --git a/scripts/promote-packages.ts b/scripts/promote-packages.ts new file mode 100644 index 000000000..759672946 --- /dev/null +++ b/scripts/promote-packages.ts @@ -0,0 +1,135 @@ +#!/usr/bin/env node + +/** + * Moves the npm `latest` dist-tag to a published release on every package + * the publish workflow publishes. Run by `.github/workflows/promote.yml`. + * + * Usage: node scripts/promote-packages.ts --version [--dry-run] + * + * It first checks every package has the version on npm, and changes nothing + * unless all do. Packages already on the version are left alone, so a second + * run is harmless. A real run reads the npm token from `NPM_TOKEN`; npm gets + * it through an npmrc that names the variable, never the value. + */ + +import { execFileSync } from 'node:child_process'; +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; + +import { + assertReleaseVersion, + type PackageOnNpm, + planPromotion, +} from './promote-packages-utils.ts'; + +const args = process.argv.slice(2); +let version: string | undefined; +let dryRun = false; +for (let i = 0; i < args.length; i++) { + if (args[i] === '--version') version = args[++i]; + else if (args[i] === '--dry-run') dryRun = true; + else { + console.error(`Unknown argument: ${args[i]}`); + process.exit(2); + } +} +if (version === undefined) { + console.error('Usage: promote-packages.ts --version [--dry-run]'); + process.exit(2); +} +assertReleaseVersion(version); + +interface WorkspacePackage { + name?: string; + path?: string; + private?: boolean; +} + +function publishedPackageNames(): string[] { + const listJson = execFileSync('pnpm', ['list', '-r', '--json', '--depth', '-1'], { + encoding: 'utf-8', + maxBuffer: 64 * 1024 * 1024, + }); + const workspace: WorkspacePackage[] = JSON.parse(listJson); + return workspace.flatMap((p) => (!p.private && p.path && p.name ? [p.name] : [])); +} + +function npmView(spec: string, field: string): string { + return execFileSync('npm', ['view', spec, field], { + encoding: 'utf-8', + stdio: ['ignore', 'pipe', 'pipe'], + }).trim(); +} + +function hasVersionOnNpm(name: string, release: string): boolean { + try { + return npmView(`${name}@${release}`, 'version') === release; + } catch (error) { + if (error instanceof Error && 'stderr' in error && String(error.stderr).includes('E404')) { + return false; + } + throw error; + } +} + +const names = publishedPackageNames(); +const packages: PackageOnNpm[] = names.map((name) => ({ + name, + hasVersion: hasVersionOnNpm(name, version), + latest: npmView(name, 'dist-tags.latest') || undefined, +})); +const plan = planPromotion(version, packages); + +console.log(`Promoting ${version} to latest${dryRun ? ' (dry run)' : ''}.`); +for (const pkg of packages) console.log(` ${pkg.name}: latest is ${pkg.latest ?? '(none)'}`); + +if (plan.missing.length > 0) { + console.error( + `Not promoting: ${version} is not on npm for ${plan.missing.join(', ')}. Nothing was changed.`, + ); + process.exit(1); +} +for (const name of plan.alreadyLatest) console.log(` ${name}: already on ${version}`); +for (const name of plan.toMove) + console.log(` ${name}: ${dryRun ? 'would move' : 'will move'} latest to ${version}`); + +if (dryRun || plan.toMove.length === 0) process.exit(0); + +if (!process.env['NPM_TOKEN']) { + console.error( + 'NPM_TOKEN is not set. Add it as a secret of the npm-promote environment for this run (docs/oss/versioning.md). Nothing was changed.', + ); + process.exit(1); +} + +const configDir = mkdtempSync(join(process.env['RUNNER_TEMP'] ?? tmpdir(), 'promote-')); +const npmrc = join(configDir, '.npmrc'); +// biome-ignore lint/suspicious/noTemplateCurlyInString: npm expands ${NPM_TOKEN} itself, so the file never holds the token. +writeFileSync(npmrc, '//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n'); +try { + for (const name of plan.toMove) { + execFileSync( + 'npm', + ['dist-tag', 'add', `${name}@${version}`, 'latest', '--userconfig', npmrc], + { + stdio: 'inherit', + }, + ); + } +} finally { + rmSync(configDir, { recursive: true, force: true }); +} + +// The registry can serve the old tag for a little while after a change. +let stillBehind = names; +for (let attempt = 1; attempt <= 6; attempt++) { + stillBehind = stillBehind.filter((name) => npmView(name, 'dist-tags.latest') !== version); + if (stillBehind.length === 0) break; + if (attempt < 6) execFileSync('sleep', ['10']); +} +if (stillBehind.length > 0) { + console.error(`latest is not on ${version} for ${stillBehind.join(', ')} after promotion.`); + process.exit(1); +} +console.log(`latest is on ${version} for every package.`); diff --git a/skills-contrib/publish-npm-version/SKILL.md b/skills-contrib/publish-npm-version/SKILL.md index 17414dad8..16cf72962 100644 --- a/skills-contrib/publish-npm-version/SKILL.md +++ b/skills-contrib/publish-npm-version/SKILL.md @@ -4,9 +4,10 @@ description: >- Cuts the next minor release of Prisma Composer: bumps the root package.json version, propagates it to every workspace package in lockstep, and opens a PR titled "chore(release): v". When a maintainer - merges the PR, the `Publish to npm` workflow runs automatically and ships the - new version to npm under dist-tag `latest`, plus a matching GitHub Release - with auto-generated notes. Use when a maintainer asks to "cut the next minor", + merges the PR, the `Publish to npm` workflow runs automatically and publishes + the new version to npm under dist-tag `rc`, plus a matching GitHub Release + with auto-generated notes; users get it when a maintainer promotes it to + `latest`. Use when a maintainer asks to "cut the next minor", "bump to the next version", "open a release PR", or "prepare a publish PR". --- @@ -59,9 +60,7 @@ undisturbed. gh pr create --base main --title "chore(release): v" \ --body "Release v. Merging this triggers the Publish to npm workflow." ``` -5. **Hand off.** Tell the maintainer the PR is open and that **merging it** ships - `` to npm under `latest` (via OIDC trusted publishing) and cuts a - GitHub Release with auto-generated notes. Do not merge it yourself unless asked. +5. **Hand off.** Tell the maintainer the PR is open and that **merging it** publishes `` to npm under `rc` (via OIDC trusted publishing) and cuts a GitHub Release with auto-generated notes. Users get the release only once a maintainer promotes it to `latest` with the `Promote to latest` workflow (versioning.md § Promote a release to `latest`). Do not merge it yourself unless asked. ## What this skill does NOT do From 0345857713494f2bd96ff568b5b6340b9291d49d Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:11:15 +1100 Subject: [PATCH 05/11] ci(promote): promotion refuses until the pinned ORM is latest, checks run without the token, and review fixes Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 47 +++++++--- docs/oss/versioning.md | 31 +++---- scripts/determine-version-utils.ts | 6 +- scripts/promote-packages-utils.test.ts | 70 ++++++++++++++- scripts/promote-packages-utils.ts | 45 ++++++++++ scripts/promote-packages.ts | 120 ++++++++++++++++--------- 6 files changed, 246 insertions(+), 73 deletions(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 6d6131d8f..cb561ada1 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -8,7 +8,8 @@ name: Promote to latest # npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a # real run needs an npm token. The repository keeps none: the promoter adds # the secret NPM_TOKEN to the `npm-promote` environment just before a run and -# deletes it straight after. A dry run needs no token. +# deletes it straight after. Only the `promote` job uses that environment, +# and only on a real run; the checks need no token. on: workflow_dispatch: @@ -18,20 +19,50 @@ on: required: true type: string dry-run: - description: "Dry-run only (check every package has the version; change nothing)." + description: "Dry-run only (run the checks; change nothing)." required: false default: true type: boolean concurrency: - group: npm-publish + group: npm-promote cancel-in-progress: false +permissions: + contents: read + jobs: + check: + name: Check the release can be promoted + runs-on: ubuntu-latest + steps: + - name: Require main + if: ${{ github.ref != 'refs/heads/main' }} + run: | + echo "::error::Promote to latest runs only from main (this run is on $GITHUB_REF)." + exit 1 + + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + + - uses: ./.github/actions/setup + + - name: Check the GitHub Release exists + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ github.event.inputs.version }} + run: gh release view "v$VERSION" --json tagName > /dev/null + + - name: Check every package (dry run) + env: + VERSION: ${{ github.event.inputs.version }} + run: node scripts/promote-packages.ts --version "$VERSION" --dry-run + promote: name: Move latest to the release + needs: check + if: ${{ github.ref == 'refs/heads/main' && github.event.inputs.dry-run != 'true' }} runs-on: ubuntu-latest - if: ${{ github.ref == 'refs/heads/main' }} environment: npm-promote permissions: contents: write # Required to mark the GitHub Release as latest @@ -42,14 +73,7 @@ jobs: - uses: ./.github/actions/setup - - name: Promote packages (dry-run) - if: ${{ github.event.inputs.dry-run == 'true' }} - env: - VERSION: ${{ github.event.inputs.version }} - run: node scripts/promote-packages.ts --version "$VERSION" --dry-run - - name: Promote packages - if: ${{ github.event.inputs.dry-run != 'true' }} env: VERSION: ${{ github.event.inputs.version }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} @@ -58,7 +82,6 @@ jobs: # The GitHub Release was created without GitHub's "Latest" mark # (publish.yml); give it the mark now that npm `latest` is on it. - name: Mark the GitHub Release as latest - if: ${{ github.event.inputs.dry-run != 'true' }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ github.event.inputs.version }} diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index f62da4a2c..e648b5cd7 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -27,10 +27,7 @@ Every workspace package — publishable, private, and the workspace root — car same `version`. One read of root `package.json` answers "what version is this code?" for the entire repository. -- The published packages (`@prisma/composer`, `@prisma/composer-cli` and - `@prisma/composer-prisma-cloud` — the only publishable packages, all under - `packages/9-public/`, ADR-0027) publish at the same version, and each pins its workspace siblings to that - **exact** version. +- The published packages (`@prisma/composer`, `@prisma/composer-cli` and `@prisma/composer-prisma-cloud` — the only publishable packages, all under `packages/9-public/`, ADR-0027) publish at the same version, and each pins its workspace siblings to that **exact** version. - Private packages (the `@internal/*` workspace packages, build config, examples, tests) are never published but still version in lockstep, so a contributor cloning any commit sees one consistent answer. `pnpm publish` skips them via @@ -72,10 +69,7 @@ override the version and no separate release-manifest file. invocation walks every workspace `package.json`, writes the requested version, and rewrites internal `workspace:` deps to `workspace:` (which pnpm turns into an exact `X.Y.Z` pin at publish time). -- [`scripts/determine-version.ts`](../../scripts/determine-version.ts) composes the - version + dist-tag for a run: a push to `main` whose root `version` differs from the - previous tip is a **release bump** → publish `` under `rc` + a GitHub Release - + a `-dev.N` build under `dev`; otherwise → `-dev.N` under `dev`. +- [`scripts/determine-version.ts`](../../scripts/determine-version.ts) composes the version + dist-tag for a run: a push to `main` whose root `version` differs from the previous tip is a **release bump** → publish `` under `rc` + a GitHub Release + a `-dev.N` build under `dev`; otherwise → `-dev.N` under `dev`. - [`scripts/check-publish-deps.mjs`](../../scripts/check-publish-deps.mjs) is a pre-publish gate: it packs every publishable tarball and fails the publish if any resolved `package.json` would carry a `workspace:` / `catalog:` specifier or a @@ -102,18 +96,23 @@ Between releases, every merge to `main` publishes a `-dev.N` build under ` ## Promote a release to `latest` -The [`Promote to latest`](../../.github/workflows/promote.yml) workflow moves `latest` to a published release on every package the publish workflow publishes (every workspace package that is not private). It first checks that every package has the version on npm, and changes nothing unless all do. Packages already on the version are left alone, so a second run is harmless. A real run then marks the release's GitHub Release as GitHub's latest release. +The [`Promote to latest`](../../.github/workflows/promote.yml) workflow moves `latest` to a published release on every package the publish workflow publishes (every workspace package that is not private). Before changing anything it checks that: -npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a real run needs an npm token. The repository keeps none between promotions: +- the run is on `main`; +- the release's GitHub Release exists; +- every package has the version on npm; +- every Prisma ORM version the release pins is already the ORM's `latest`. Promote the ORM first. -1. Check the release with a dry run, which needs no token: `gh workflow run promote.yml -R prisma/composer --ref main -f version=`. -2. On npmjs.com, create a **granular access token** with read and write access to the published packages only (`@prisma/composer`, `@prisma/composer-cli`, `@prisma/composer-prisma-cloud`) and the shortest expiry npm allows. +Packages already on the version are left alone, so a second run is harmless, and a run that failed partway finishes when re-run. A real run then marks the release's GitHub Release as GitHub's latest release. + +npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a real run needs an npm token. The repository keeps none between promotions. Before the first promotion, do the [one-time setup](#one-time-setup-the-npm-promote-environment-maintainers). Then: + +1. Run the checks with a dry run, which needs no token: `gh workflow run promote.yml -R prisma/composer --ref main -f version=`. Its log lists the packages and says if `latest` would move to an older version. +2. On npmjs.com, create a **granular access token** with read and write access to the packages the dry run listed and nothing else, the shortest expiry npm allows, and **Bypass two-factor authentication** ticked (without it, `npm dist-tag add` in CI fails asking for a one-time password). 3. Add it to the `npm-promote` environment: `gh secret set NPM_TOKEN --env npm-promote -R prisma/composer`. It prompts for the value, so the token is not on your command line or in your shell history. 4. Run the promotion: `gh workflow run promote.yml -R prisma/composer --ref main -f version= -f dry-run=false`. 5. As soon as the run finishes, delete the secret (`gh secret delete NPM_TOKEN --env npm-promote -R prisma/composer`) and revoke the token on npmjs.com. -The workflow moves `latest` to any published version you give it, older ones included, so check the version before a real run. - ## Validating publish changes Before merging anything that touches the publish pipeline, run the workflow's dry-run: @@ -147,5 +146,7 @@ package (e.g. a new `@prisma/composer-`)._ ## One-time setup: the `npm-promote` environment (maintainers) -1. Create the environment: **Settings → Environments → New environment**, named `npm-promote`. Under **Deployment branches and tags**, allow only `main`. It holds no secret between promotions. +Do this before the first promotion. Only a repository admin can. + +1. Create the environment: **Settings → Environments → New environment**, named `npm-promote`. Under **Deployment branches and tags**, allow only `main`: while the token is in the environment, this is what stops a workflow on another branch from reading it. Optionally add a required reviewer, so each promotion waits for an approval. The environment holds no secret between promotions. 2. Check each published package's **Settings → Publishing access** on npmjs.com. If it disallows tokens, the promotion's `npm dist-tag add` fails, and a maintainer moves `latest` by hand instead (`npm dist-tag add @ latest`, for each package). diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index cd697691c..10a23a1bb 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -65,7 +65,7 @@ export type PreviousVersionLookup = | { available: true; version: string | undefined } | { available: false }; -export interface PushPublishPlan { +export interface PublishPlan { version: string; tag: string; release: boolean; @@ -85,7 +85,7 @@ export const RELEASE_DIST_TAG = 'rc'; * is how `latest` moves; `dev` is refused because a release version under * `dev` would sit where dev builds belong. */ -export function planDispatchPublish(base: string, input: string | undefined): PushPublishPlan { +export function planDispatchPublish(base: string, input: string | undefined): PublishPlan { const tag = input?.trim() || RELEASE_DIST_TAG; if (tag === 'latest' || tag === 'dev') { throw new Error( @@ -107,7 +107,7 @@ export function planPushPublish( base: string, previous: PreviousVersionLookup, latestDevTag: string | undefined, -): PushPublishPlan { +): PublishPlan { const isReleaseBump = previous.available && previous.version !== base; if (isReleaseBump) { return { diff --git a/scripts/promote-packages-utils.test.ts b/scripts/promote-packages-utils.test.ts index ddd7f2f67..58b050050 100644 --- a/scripts/promote-packages-utils.test.ts +++ b/scripts/promote-packages-utils.test.ts @@ -1,7 +1,13 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import { assertReleaseVersion, planPromotion } from './promote-packages-utils.ts'; +import { + assertReleaseVersion, + collectOrmPins, + isOlderRelease, + ormPinsNotLatest, + planPromotion, +} from './promote-packages-utils.ts'; describe('assertReleaseVersion', () => { it('accepts a release version', () => { @@ -46,3 +52,65 @@ describe('planPromotion', () => { ); }); }); + +describe('isOlderRelease', () => { + it('compares each part as a number', () => { + assert.equal(isOlderRelease('0.9.0', '0.10.0'), true); + assert.equal(isOlderRelease('0.10.0', '0.9.0'), false); + assert.equal(isOlderRelease('1.0.0', '0.99.99'), false); + assert.equal(isOlderRelease('0.41.0', '0.41.0'), false); + }); +}); + +describe('collectOrmPins', () => { + it('collects exact Prisma ORM pins from dependencies and peer dependencies, once each', () => { + assert.deepEqual( + collectOrmPins([ + { + dependencies: { '@prisma/orm-toolchain': '8.0.0-rc.26', effect: '4.1.4' }, + peerDependencies: { '@prisma/orm-postgres': '8.0.0-rc.26' }, + }, + { dependencies: { '@prisma/orm-toolchain': '8.0.0-rc.26' } }, + ]), + [ + { name: '@prisma/orm-toolchain', version: '8.0.0-rc.26' }, + { name: '@prisma/orm-postgres', version: '8.0.0-rc.26' }, + ], + ); + }); + + it('ignores ranges and packages outside the ORM', () => { + assert.deepEqual( + collectOrmPins([ + { + dependencies: { '@prisma/orm-toolchain': '^8.0.0', '@prisma/cli-engine': '0.10.4' }, + }, + {}, + ]), + [], + ); + }); +}); + +describe('ormPinsNotLatest', () => { + it('returns the pins whose package latest is elsewhere', () => { + const latest: Record = { + '@prisma/orm-toolchain': '8.0.0-rc.26', + '@prisma/orm-postgres': '8.0.0-rc.25', + }; + assert.deepEqual( + ormPinsNotLatest( + [ + { name: '@prisma/orm-toolchain', version: '8.0.0-rc.26' }, + { name: '@prisma/orm-postgres', version: '8.0.0-rc.26' }, + { name: '@prisma/orm-framework', version: '8.0.0-rc.26' }, + ], + (name) => latest[name], + ), + [ + { name: '@prisma/orm-postgres', version: '8.0.0-rc.26' }, + { name: '@prisma/orm-framework', version: '8.0.0-rc.26' }, + ], + ); + }); +}); diff --git a/scripts/promote-packages-utils.ts b/scripts/promote-packages-utils.ts index 767cd20cd..9f097aeb0 100644 --- a/scripts/promote-packages-utils.ts +++ b/scripts/promote-packages-utils.ts @@ -2,6 +2,8 @@ // from `pnpm test:scripts`. All npm I/O lives in the caller. const RELEASE_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/; +const EXACT_VERSION_PATTERN = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/; +const ORM_PACKAGE_PREFIX = '@prisma/orm-'; export function assertReleaseVersion(version: string): void { if (!RELEASE_VERSION_PATTERN.test(version)) { @@ -11,6 +13,16 @@ export function assertReleaseVersion(version: string): void { } } +/** Whether release `a` is older than release `b` (both `major.minor.patch`). */ +export function isOlderRelease(a: string, b: string): boolean { + const [pa, pb] = [a, b].map((v) => v.split('.').map(Number)); + for (let i = 0; i < 3; i++) { + const [x, y] = [pa?.[i] ?? 0, pb?.[i] ?? 0]; + if (x !== y) return x < y; + } + return false; +} + export interface PackageOnNpm { name: string; hasVersion: boolean; @@ -36,3 +48,36 @@ export function planPromotion(version: string, packages: readonly PackageOnNpm[] } return plan; } + +export interface PublishedManifest { + dependencies?: Record; + peerDependencies?: Record; +} + +export interface OrmPin { + name: string; + version: string; +} + +/** The exact Prisma ORM versions the published packages depend on. */ +export function collectOrmPins(manifests: readonly PublishedManifest[]): OrmPin[] { + const pins = new Map(); + for (const manifest of manifests) { + for (const deps of [manifest.dependencies, manifest.peerDependencies]) { + for (const [name, version] of Object.entries(deps ?? {})) { + if (name.startsWith(ORM_PACKAGE_PREFIX) && EXACT_VERSION_PATTERN.test(version)) { + pins.set(`${name}@${version}`, { name, version }); + } + } + } + } + return [...pins.values()]; +} + +/** The ORM pins whose package's `latest` is not on the pinned version. */ +export function ormPinsNotLatest( + pins: readonly OrmPin[], + latestOf: (name: string) => string | undefined, +): OrmPin[] { + return pins.filter((pin) => latestOf(pin.name) !== pin.version); +} diff --git a/scripts/promote-packages.ts b/scripts/promote-packages.ts index 759672946..8b4f26f6b 100644 --- a/scripts/promote-packages.ts +++ b/scripts/promote-packages.ts @@ -6,10 +6,11 @@ * * Usage: node scripts/promote-packages.ts --version [--dry-run] * - * It first checks every package has the version on npm, and changes nothing - * unless all do. Packages already on the version are left alone, so a second - * run is harmless. A real run reads the npm token from `NPM_TOKEN`; npm gets - * it through an npmrc that names the variable, never the value. + * Before changing anything it checks that every package has the version on + * npm and that every Prisma ORM version the release pins is already the + * ORM's `latest`. Packages already on the version are left alone, so a + * second run is harmless. A real run reads the npm token from `NPM_TOKEN`; + * npm gets it through an npmrc that names the variable, never the value. */ import { execFileSync } from 'node:child_process'; @@ -19,26 +20,34 @@ import { join } from 'node:path'; import { assertReleaseVersion, + collectOrmPins, + isOlderRelease, + ormPinsNotLatest, type PackageOnNpm, + type PublishedManifest, planPromotion, } from './promote-packages-utils.ts'; +function fail(message: string): never { + console.error(message); + process.exit(1); +} + const args = process.argv.slice(2); -let version: string | undefined; +let requested: string | undefined; let dryRun = false; for (let i = 0; i < args.length; i++) { - if (args[i] === '--version') version = args[++i]; + if (args[i] === '--version') requested = args[++i]; else if (args[i] === '--dry-run') dryRun = true; - else { - console.error(`Unknown argument: ${args[i]}`); - process.exit(2); - } + else fail(`Unknown argument: ${args[i]}`); } -if (version === undefined) { - console.error('Usage: promote-packages.ts --version [--dry-run]'); - process.exit(2); +if (requested === undefined) fail('Usage: promote-packages.ts --version [--dry-run]'); +const version: string = requested; +try { + assertReleaseVersion(version); +} catch (error) { + fail(error instanceof Error ? error.message : String(error)); } -assertReleaseVersion(version); interface WorkspacePackage { name?: string; @@ -55,29 +64,29 @@ function publishedPackageNames(): string[] { return workspace.flatMap((p) => (!p.private && p.path && p.name ? [p.name] : [])); } -function npmView(spec: string, field: string): string { - return execFileSync('npm', ['view', spec, field], { - encoding: 'utf-8', - stdio: ['ignore', 'pipe', 'pipe'], - }).trim(); -} - -function hasVersionOnNpm(name: string, release: string): boolean { +/** `npm view`, with `undefined` when npm has no such package or version. */ +function npmView(spec: string, ...fields: string[]): string | undefined { try { - return npmView(`${name}@${release}`, 'version') === release; + const out = execFileSync('npm', ['view', spec, ...fields], { + encoding: 'utf-8', + stdio: ['ignore', 'pipe', 'pipe'], + }).trim(); + return out === '' ? undefined : out; } catch (error) { if (error instanceof Error && 'stderr' in error && String(error.stderr).includes('E404')) { - return false; + return undefined; } throw error; } } +const latestOf = (name: string) => npmView(name, 'dist-tags.latest'); + const names = publishedPackageNames(); const packages: PackageOnNpm[] = names.map((name) => ({ name, - hasVersion: hasVersionOnNpm(name, version), - latest: npmView(name, 'dist-tags.latest') || undefined, + hasVersion: npmView(`${name}@${version}`, 'version') === version, + latest: latestOf(name), })); const plan = planPromotion(version, packages); @@ -85,37 +94,65 @@ console.log(`Promoting ${version} to latest${dryRun ? ' (dry run)' : ''}.`); for (const pkg of packages) console.log(` ${pkg.name}: latest is ${pkg.latest ?? '(none)'}`); if (plan.missing.length > 0) { - console.error( + fail( `Not promoting: ${version} is not on npm for ${plan.missing.join(', ')}. Nothing was changed.`, ); - process.exit(1); } + +// One field per call: with several fields, npm drops the field names when +// only one of them is set. +const dependencyField = (name: string, field: string): Record => + JSON.parse(npmView(`${name}@${version}`, field, '--json') ?? '{}'); +const manifests: PublishedManifest[] = names.map((name) => ({ + dependencies: dependencyField(name, 'dependencies'), + peerDependencies: dependencyField(name, 'peerDependencies'), +})); +const ormBehind = ormPinsNotLatest(collectOrmPins(manifests), latestOf); +if (ormBehind.length > 0) { + fail( + `Not promoting: ${version} pins Prisma ORM versions that are not yet the ORM's latest: ${ormBehind + .map((pin) => `${pin.name}@${pin.version}`) + .join(', ')}. Promote the ORM first. Nothing was changed.`, + ); +} + for (const name of plan.alreadyLatest) console.log(` ${name}: already on ${version}`); -for (const name of plan.toMove) - console.log(` ${name}: ${dryRun ? 'would move' : 'will move'} latest to ${version}`); +for (const pkg of packages.filter((p) => plan.toMove.includes(p.name))) { + const older = pkg.latest !== undefined && isOlderRelease(version, pkg.latest); + console.log( + ` ${pkg.name}: ${dryRun ? 'would move' : 'will move'} latest to ${version}${older ? `, which is OLDER than ${pkg.latest}` : ''}`, + ); +} if (dryRun || plan.toMove.length === 0) process.exit(0); if (!process.env['NPM_TOKEN']) { - console.error( + fail( 'NPM_TOKEN is not set. Add it as a secret of the npm-promote environment for this run (docs/oss/versioning.md). Nothing was changed.', ); - process.exit(1); } const configDir = mkdtempSync(join(process.env['RUNNER_TEMP'] ?? tmpdir(), 'promote-')); const npmrc = join(configDir, '.npmrc'); // biome-ignore lint/suspicious/noTemplateCurlyInString: npm expands ${NPM_TOKEN} itself, so the file never holds the token. writeFileSync(npmrc, '//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n'); +const moved: string[] = []; try { for (const name of plan.toMove) { - execFileSync( - 'npm', - ['dist-tag', 'add', `${name}@${version}`, 'latest', '--userconfig', npmrc], - { - stdio: 'inherit', - }, - ); + try { + execFileSync( + 'npm', + ['dist-tag', 'add', `${name}@${version}`, 'latest', '--userconfig', npmrc], + { + stdio: 'inherit', + }, + ); + } catch { + fail( + `Moving latest failed for ${name}. Moved so far: ${moved.join(', ') || 'none'}. Fix the cause and re-run the workflow; it skips packages already on ${version}.`, + ); + } + moved.push(name); } } finally { rmSync(configDir, { recursive: true, force: true }); @@ -124,12 +161,11 @@ try { // The registry can serve the old tag for a little while after a change. let stillBehind = names; for (let attempt = 1; attempt <= 6; attempt++) { - stillBehind = stillBehind.filter((name) => npmView(name, 'dist-tags.latest') !== version); + stillBehind = stillBehind.filter((name) => latestOf(name) !== version); if (stillBehind.length === 0) break; if (attempt < 6) execFileSync('sleep', ['10']); } if (stillBehind.length > 0) { - console.error(`latest is not on ${version} for ${stillBehind.join(', ')} after promotion.`); - process.exit(1); + fail(`latest is not on ${version} for ${stillBehind.join(', ')} after promotion.`); } console.log(`latest is on ${version} for every package.`); From a2d7ed2618f41593f80d71da60caaca0dbaba7ad Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:16:15 +1100 Subject: [PATCH 06/11] ci(publish)!: releases stage under next, promotion reads NPM_PROMOTE_TOKEN; review fixes Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 28 +++++++------ .github/workflows/publish.yml | 14 +++---- docs/oss/versioning.md | 22 +++++----- scripts/determine-version-utils.test.ts | 12 +++--- scripts/determine-version-utils.ts | 8 ++-- scripts/determine-version.ts | 6 +-- scripts/promote-packages-utils.test.ts | 2 +- scripts/promote-packages.ts | 45 +++++++++++++-------- skills-contrib/publish-npm-version/SKILL.md | 4 +- 9 files changed, 77 insertions(+), 64 deletions(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index cb561ada1..0043452bb 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -1,15 +1,15 @@ name: Promote to latest -# A release publishes under the npm dist-tag `rc` and never moves `latest` +# A release publishes under the npm dist-tag `next` and never moves `latest` # (publish.yml). This workflow moves `latest` to a published release on every # package, then marks its GitHub Release as GitHub's latest release. See # docs/oss/versioning.md. # # npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a # real run needs an npm token. The repository keeps none: the promoter adds -# the secret NPM_TOKEN to the `npm-promote` environment just before a run and -# deletes it straight after. Only the `promote` job uses that environment, -# and only on a real run; the checks need no token. +# the secret NPM_PROMOTE_TOKEN to the `npm-promote` environment just before +# a run and deletes it straight after. Only the `promote` job uses that +# environment, and only on a real run from `main`; the checks need no token. on: workflow_dispatch: @@ -36,10 +36,12 @@ jobs: name: Check the release can be promoted runs-on: ubuntu-latest steps: - - name: Require main - if: ${{ github.ref != 'refs/heads/main' }} + # A dry run may come from a branch, to try a change to this workflow; + # the job holds no secret. + - name: Require main for a real run + if: ${{ github.ref != 'refs/heads/main' && github.event.inputs.dry-run != 'true' }} run: | - echo "::error::Promote to latest runs only from main (this run is on $GITHUB_REF)." + echo "::error::A real promotion runs only from main (this run is on $GITHUB_REF)." exit 1 - name: Checkout @@ -47,16 +49,16 @@ jobs: - uses: ./.github/actions/setup - - name: Check the GitHub Release exists + - name: Check every package (dry run) env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ github.event.inputs.version }} - run: gh release view "v$VERSION" --json tagName > /dev/null + run: node scripts/promote-packages.ts --version "$VERSION" --dry-run - - name: Check every package (dry run) + - name: Check the GitHub Release exists env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ github.event.inputs.version }} - run: node scripts/promote-packages.ts --version "$VERSION" --dry-run + run: gh release view "v$VERSION" --json tagName > /dev/null promote: name: Move latest to the release @@ -76,7 +78,7 @@ jobs: - name: Promote packages env: VERSION: ${{ github.event.inputs.version }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_PROMOTE_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} run: node scripts/promote-packages.ts --version "$VERSION" # The GitHub Release was created without GitHub's "Latest" mark diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6819acb21..53ec810c9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,7 @@ name: Publish to npm # - push to `main` with the root `version` unchanged → publish `-dev.N` # under dist-tag `dev`. # - push to `main` with the root `version` changed → publish `` under -# dist-tag `rc` and create a GitHub Release. This is how a merged +# dist-tag `next` and create a GitHub Release. This is how a merged # release-bump PR publishes a release. It never moves `latest`: a # maintainer promotes the release to `latest` later # (docs/oss/versioning.md). The same run then publishes `-dev.N` @@ -17,8 +17,8 @@ name: Publish to npm # dist-tag on a build of that commit. When releases skipped the dev # publish, `dev` sat on the previous base until the next routine push. # - workflow_dispatch → publish `` under the chosen dist-tag (default -# `rc`; `latest` and `dev` are refused); also the dry-run path. A run under -# `rc` re-publishes a release whose publish failed, and counts as a release. +# `next`; `latest` and `dev` are refused); also the dry-run path. A run under +# `next` re-publishes a release whose publish failed, and counts as a release. on: push: @@ -27,9 +27,9 @@ on: workflow_dispatch: inputs: dist-tag: - description: "npm dist-tag: rc re-publishes a release whose publish failed (latest and dev are refused)" + description: "npm dist-tag: next re-publishes a release whose publish failed (latest and dev are refused)" required: true - default: "rc" + default: "next" type: string dry-run: description: "Dry-run only (build + pack + gate, no npm publish, no GitHub Release)." @@ -157,7 +157,7 @@ jobs: fi # Emit a GitHub Release for releases: a release-bump push, or a manual - # run under `rc`. Notes are auto-generated from the commits/PRs since + # run under `next`. Notes are auto-generated from the commits/PRs since # the previous tag. `--latest=false`: GitHub marks it its latest release # when promote.yml moves npm `latest`. # Idempotent on rerun: edit an existing Release rather than re-create it. @@ -182,7 +182,7 @@ jobs: # Tell prisma-cli a release shipped so its update-product-versions # workflow can open the repin PR now instead of at its daily run # (prisma-cli docs/oss/release-automation.md). Releases only: the - # receiver reads each product's `rc` tag first, so it finds this + # receiver reads each product's `next` tag first, so it finds this # release; a dev publish would be a no-op there. Never fails the publish. - name: Notify prisma-cli if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }} diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index e648b5cd7..5856e74a2 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -40,7 +40,7 @@ building on a false assumption. ## Dist-tag convention - **`latest`** — the most recent stable release; the default for `npm install @prisma/composer`. A release reaches `latest` only when a maintainer promotes it (see [Promote a release to `latest`](#promote-a-release-to-latest)). Merging a release PR never moves it. -- **`rc`** — every release, as soon as its release PR merges. A release waits here until it is promoted, for example while Composer, Prisma ORM and the `prisma` CLI are checked together on their published versions. +- **`next`** — every release, as soon as its release PR merges, so it always names the newest release. A release waits here until it is promoted, for example while Composer, Prisma ORM and the `prisma` CLI are checked together on their published versions. - **`dev`** — a `-dev.N` build of every push to `main`, release or not. **No stability promise** — may be yanked freely. ## Who can publish @@ -54,9 +54,7 @@ building on a false assumption. tying it to this repository and the workflow run that produced it (provenance requires the repo to be public, which it is). - Moving `latest` needs an npm token, because trusted publishing does not cover `npm dist-tag`. The [`Promote to latest`](../../.github/workflows/promote.yml) workflow reads a short-lived, package-limited token from the `npm-promote` environment, which holds it only for the length of a promotion (see [Promote a release to `latest`](#promote-a-release-to-latest)). -- The workflow only produces a real publish from `main`. Dry-runs are permitted from any - branch via `workflow_dispatch` (see below); every step that mutates external state is - independently guarded. +- The `Publish to npm` workflow only produces a real publish from `main`. Its dry-runs are permitted from any branch via `workflow_dispatch` (see below); every step that mutates external state is independently guarded. The `Promote to latest` workflow likewise moves `latest` only from `main`. ## Mechanism: how we deliver the contract @@ -69,7 +67,7 @@ override the version and no separate release-manifest file. invocation walks every workspace `package.json`, writes the requested version, and rewrites internal `workspace:` deps to `workspace:` (which pnpm turns into an exact `X.Y.Z` pin at publish time). -- [`scripts/determine-version.ts`](../../scripts/determine-version.ts) composes the version + dist-tag for a run: a push to `main` whose root `version` differs from the previous tip is a **release bump** → publish `` under `rc` + a GitHub Release + a `-dev.N` build under `dev`; otherwise → `-dev.N` under `dev`. +- [`scripts/determine-version.ts`](../../scripts/determine-version.ts) composes the version + dist-tag for a run: a push to `main` whose root `version` differs from the previous tip is a **release bump** → publish `` under `next` + a GitHub Release + a `-dev.N` build under `dev`; otherwise → `-dev.N` under `dev`. - [`scripts/check-publish-deps.mjs`](../../scripts/check-publish-deps.mjs) is a pre-publish gate: it packs every publishable tarball and fails the publish if any resolved `package.json` would carry a `workspace:` / `catalog:` specifier or a @@ -87,10 +85,10 @@ publish trigger** — there is no separate dispatch step for a normal release. 1. From a clean `main`, run **`pnpm bump-minor`** in a fresh branch. It reads the root version at `HEAD`, computes the next minor (`0.1.0` → `0.2.0`), stamps every workspace `package.json`, and regenerates `pnpm-lock.yaml` (CI installs with `--frozen-lockfile`, so a bump committed without the lockfile fails every job). 2. Open a PR titled `chore(release): v`. CI runs normally. -3. **Merge it.** The push to `main` changes the root version, so the `Publish to npm` workflow recognises a release bump. It publishes every package at `` under `rc`, cuts a GitHub Release with auto-generated notes, notifies prisma-cli (whose `update-product-versions` workflow reads Composer's `rc` tag first), and publishes a `-dev.1` build under `dev`. +3. **Merge it.** The push to `main` changes the root version, so the `Publish to npm` workflow recognises a release bump. It publishes every package at `` under `next`, cuts a GitHub Release with auto-generated notes, notifies prisma-cli (whose `update-product-versions` workflow reads Composer's `next` tag first), and publishes a `-dev.1` build under `dev`. 4. **Promote it** when users should get it: see [Promote a release to `latest`](#promote-a-release-to-latest). -If a release's publish fails, re-run the failed workflow run. If that is not possible, run **Actions → Publish to npm → Run workflow** from `main` with the dist-tag `rc` and dry-run unchecked: it re-publishes the release under `rc` and skips packages already on npm. Manual runs refuse `latest` and `dev`. +If a release's publish fails, re-run the failed workflow run. If that is not possible, run **Actions → Publish to npm → Run workflow** from `main` with the dist-tag `next` and dry-run unchecked: it re-publishes the release under `next` and skips packages already on npm. Manual runs refuse `latest` and `dev`. Between releases, every merge to `main` publishes a `-dev.N` build under `dev` — useful for `npm install @prisma/composer@dev` reproductions. @@ -98,7 +96,7 @@ Between releases, every merge to `main` publishes a `-dev.N` build under ` The [`Promote to latest`](../../.github/workflows/promote.yml) workflow moves `latest` to a published release on every package the publish workflow publishes (every workspace package that is not private). Before changing anything it checks that: -- the run is on `main`; +- a real run is on `main` (a dry run may come from a branch, to try a change to the workflow); - the release's GitHub Release exists; - every package has the version on npm; - every Prisma ORM version the release pins is already the ORM's `latest`. Promote the ORM first. @@ -107,11 +105,13 @@ Packages already on the version are left alone, so a second run is harmless, and npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a real run needs an npm token. The repository keeps none between promotions. Before the first promotion, do the [one-time setup](#one-time-setup-the-npm-promote-environment-maintainers). Then: -1. Run the checks with a dry run, which needs no token: `gh workflow run promote.yml -R prisma/composer --ref main -f version=`. Its log lists the packages and says if `latest` would move to an older version. +1. Run the checks with a dry run, which needs no token: `gh workflow run promote.yml -R prisma/composer --ref main -f version=`. Its log lists the packages and the ORM pins it compared, and says if `latest` would move to an older version. 2. On npmjs.com, create a **granular access token** with read and write access to the packages the dry run listed and nothing else, the shortest expiry npm allows, and **Bypass two-factor authentication** ticked (without it, `npm dist-tag add` in CI fails asking for a one-time password). -3. Add it to the `npm-promote` environment: `gh secret set NPM_TOKEN --env npm-promote -R prisma/composer`. It prompts for the value, so the token is not on your command line or in your shell history. +3. Add it to the `npm-promote` environment: `gh secret set NPM_PROMOTE_TOKEN --env npm-promote -R prisma/composer`. It prompts for the value, so the token is not on your command line or in your shell history. 4. Run the promotion: `gh workflow run promote.yml -R prisma/composer --ref main -f version= -f dry-run=false`. -5. As soon as the run finishes, delete the secret (`gh secret delete NPM_TOKEN --env npm-promote -R prisma/composer`) and revoke the token on npmjs.com. +5. As soon as the run finishes, delete the secret (`gh secret delete NPM_PROMOTE_TOKEN --env npm-promote -R prisma/composer`) and revoke the token on npmjs.com. + +Rolling `latest` back to an older Composer release works the same way, but the ORM check usually refuses it: an older release pins an older ORM, and the ORM's `latest` has moved on. Move the ORM's `latest` back first, or move Composer's `latest` by hand (`npm dist-tag add @ latest`, for each package). ## Validating publish changes diff --git a/scripts/determine-version-utils.test.ts b/scripts/determine-version-utils.test.ts index 761428a46..2375cfcd2 100644 --- a/scripts/determine-version-utils.test.ts +++ b/scripts/determine-version-utils.test.ts @@ -89,17 +89,17 @@ describe('planPushPublish', () => { ); }); - it('publishes a release under rc plus a dev follow-up when the root version changed', () => { + it('publishes a release under next plus a dev follow-up when the root version changed', () => { assert.deepEqual( planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.8.0-dev.7'), - { version: '0.9.0', tag: 'rc', release: true, devVersion: '0.9.0-dev.1' }, + { version: '0.9.0', tag: 'next', release: true, devVersion: '0.9.0-dev.1' }, ); }); it('continues the dev counter on a release rerun whose dev build already landed', () => { assert.deepEqual( planPushPublish('0.9.0', { available: true, version: '0.8.0' }, '0.9.0-dev.1'), - { version: '0.9.0', tag: 'rc', release: true, devVersion: '0.9.0-dev.2' }, + { version: '0.9.0', tag: 'next', release: true, devVersion: '0.9.0-dev.2' }, ); }); @@ -121,7 +121,7 @@ describe('planPushPublish', () => { it('treats a previous package.json without a version as a release bump', () => { assert.deepEqual(planPushPublish('0.9.0', { available: true, version: undefined }, undefined), { version: '0.9.0', - tag: 'rc', + tag: 'next', release: true, devVersion: '0.9.0-dev.1', }); @@ -129,11 +129,11 @@ describe('planPushPublish', () => { }); describe('planDispatchPublish', () => { - it('re-publishes a release under rc when the input is blank', () => { + it('re-publishes a release under next when the input is blank', () => { for (const input of [undefined, '', ' ']) { assert.deepEqual(planDispatchPublish('0.9.0', input), { version: '0.9.0', - tag: 'rc', + tag: 'next', release: true, }); } diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index 10a23a1bb..b24a0423f 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -76,11 +76,11 @@ export interface PublishPlan { * Every release publishes under this dist-tag and never moves `latest`. * `latest` moves only when a maintainer promotes a published release. */ -export const RELEASE_DIST_TAG = 'rc'; +export const RELEASE_DIST_TAG = 'next'; /** * The publish plan for a manual run: `` under the input tag, or - * `rc` when blank. A run under `rc` re-publishes a release whose publish + * `next` when blank. A run under `next` re-publishes a release whose publish * failed, so it counts as a release. `latest` is refused because promotion * is how `latest` moves; `dev` is refused because a release version under * `dev` would sit where dev builds belong. @@ -89,7 +89,7 @@ export function planDispatchPublish(base: string, input: string | undefined): Pu const tag = input?.trim() || RELEASE_DIST_TAG; if (tag === 'latest' || tag === 'dev') { throw new Error( - `A manual publish run cannot publish under "${tag}". Re-publish a release under "rc", and promote it to "latest" with the Promote to latest workflow (docs/oss/versioning.md).`, + `A manual publish run cannot publish under "${tag}". Re-publish a release under "next", and promote it to "latest" with the Promote to latest workflow (docs/oss/versioning.md).`, ); } return { version: base, tag, release: tag === RELEASE_DIST_TAG }; @@ -97,7 +97,7 @@ export function planDispatchPublish(base: string, input: string | undefined): Pu /** * The publish plan for a push to `main`. A changed root version means - * the push is a release bump: publish `` under `rc`, plus a + * the push is a release bump: publish `` under `next`, plus a * `-dev.N` follow-up so the `dev` dist-tag never falls behind * the release. An unchanged (or unreadable — a transient git error must * never silently publish a release) previous version means the usual diff --git a/scripts/determine-version.ts b/scripts/determine-version.ts index 0c5f74b6b..5ac1d3dfb 100644 --- a/scripts/determine-version.ts +++ b/scripts/determine-version.ts @@ -9,7 +9,7 @@ * appropriate to the GitHub event: * * - `push` → if the root `version` changed in this push, - * `` (no suffix), dist-tag `rc`. This + * `` (no suffix), dist-tag `next`. This * is how a merged `chore(release): ...` PR * publishes a release; `latest` moves later, * when a maintainer promotes it. The plan then @@ -21,10 +21,10 @@ * (N is the next available build number, * discovered by querying npm). * - `workflow_dispatch` → `` (no suffix), dist-tag from - * `INPUT_DIST_TAG` (defaults to `rc`; `latest` + * `INPUT_DIST_TAG` (defaults to `next`; `latest` * and `dev` are refused). The manual escape * hatch: re-publish a release whose publish - * failed. A run under `rc` counts as a release. + * failed. A run under `next` counts as a release. * * Outputs `version`, `tag`, `release` (whether the run publishes a * release) and `devVersion` (empty unless the push is a release bump) diff --git a/scripts/promote-packages-utils.test.ts b/scripts/promote-packages-utils.test.ts index 58b050050..de3954adc 100644 --- a/scripts/promote-packages-utils.test.ts +++ b/scripts/promote-packages-utils.test.ts @@ -15,7 +15,7 @@ describe('assertReleaseVersion', () => { }); it('refuses dev builds, ranges and tags', () => { - for (const version of ['0.41.0-dev.1', '^0.41.0', 'rc', '', 'v0.41.0']) { + for (const version of ['0.41.0-dev.1', '^0.41.0', 'next', '', 'v0.41.0']) { assert.throws(() => assertReleaseVersion(version), /not a release version/); } }); diff --git a/scripts/promote-packages.ts b/scripts/promote-packages.ts index 8b4f26f6b..b2edaeb4a 100644 --- a/scripts/promote-packages.ts +++ b/scripts/promote-packages.ts @@ -9,7 +9,7 @@ * Before changing anything it checks that every package has the version on * npm and that every Prisma ORM version the release pins is already the * ORM's `latest`. Packages already on the version are left alone, so a - * second run is harmless. A real run reads the npm token from `NPM_TOKEN`; + * second run is harmless. A real run reads the npm token from `NPM_PROMOTE_TOKEN`; * npm gets it through an npmrc that names the variable, never the value. */ @@ -107,12 +107,18 @@ const manifests: PublishedManifest[] = names.map((name) => ({ dependencies: dependencyField(name, 'dependencies'), peerDependencies: dependencyField(name, 'peerDependencies'), })); -const ormBehind = ormPinsNotLatest(collectOrmPins(manifests), latestOf); -if (ormBehind.length > 0) { +const ormPins = collectOrmPins(manifests); +for (const pin of ormPins) { + console.log(` ORM pin ${pin.name}@${pin.version}: latest is ${latestOf(pin.name) ?? '(none)'}`); +} +const ormMismatched = ormPinsNotLatest(ormPins, latestOf); +if (ormMismatched.length > 0) { + const listed = ormMismatched + .map((pin) => `${pin.name}@${pin.version} (latest is ${latestOf(pin.name) ?? 'unset'})`) + .join(', '); fail( - `Not promoting: ${version} pins Prisma ORM versions that are not yet the ORM's latest: ${ormBehind - .map((pin) => `${pin.name}@${pin.version}`) - .join(', ')}. Promote the ORM first. Nothing was changed.`, + `Not promoting: ${version} pins Prisma ORM versions that are not the ORM's latest: ${listed}. ` + + "If the ORM's latest is older, promote the ORM first. If it is newer, users would get this release with an ORM it was not released with: release Composer on that ORM, or move the ORM's latest back first. Nothing was changed.", ); } @@ -126,37 +132,40 @@ for (const pkg of packages.filter((p) => plan.toMove.includes(p.name))) { if (dryRun || plan.toMove.length === 0) process.exit(0); -if (!process.env['NPM_TOKEN']) { +if (!process.env['NPM_PROMOTE_TOKEN']) { fail( - 'NPM_TOKEN is not set. Add it as a secret of the npm-promote environment for this run (docs/oss/versioning.md). Nothing was changed.', + 'NPM_PROMOTE_TOKEN is not set. Add it as a secret of the npm-promote environment for this run (docs/oss/versioning.md). Nothing was changed.', ); } const configDir = mkdtempSync(join(process.env['RUNNER_TEMP'] ?? tmpdir(), 'promote-')); const npmrc = join(configDir, '.npmrc'); -// biome-ignore lint/suspicious/noTemplateCurlyInString: npm expands ${NPM_TOKEN} itself, so the file never holds the token. -writeFileSync(npmrc, '//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n'); +// biome-ignore lint/suspicious/noTemplateCurlyInString: npm expands ${NPM_PROMOTE_TOKEN} itself, so the file never holds the token. +writeFileSync(npmrc, '//registry.npmjs.org/:_authToken=${NPM_PROMOTE_TOKEN}\n'); const moved: string[] = []; +let failedOn: string | undefined; try { for (const name of plan.toMove) { try { execFileSync( 'npm', ['dist-tag', 'add', `${name}@${version}`, 'latest', '--userconfig', npmrc], - { - stdio: 'inherit', - }, + { stdio: 'inherit' }, ); } catch { - fail( - `Moving latest failed for ${name}. Moved so far: ${moved.join(', ') || 'none'}. Fix the cause and re-run the workflow; it skips packages already on ${version}.`, - ); + failedOn = name; + break; } moved.push(name); } } finally { rmSync(configDir, { recursive: true, force: true }); } +if (failedOn !== undefined) { + fail( + `Moving latest failed for ${failedOn}. Moved so far: ${moved.join(', ') || 'none'}. Fix the cause and re-run the workflow; it skips packages already on ${version}.`, + ); +} // The registry can serve the old tag for a little while after a change. let stillBehind = names; @@ -166,6 +175,8 @@ for (let attempt = 1; attempt <= 6; attempt++) { if (attempt < 6) execFileSync('sleep', ['10']); } if (stillBehind.length > 0) { - fail(`latest is not on ${version} for ${stillBehind.join(', ')} after promotion.`); + fail( + `latest is not on ${version} for ${stillBehind.join(', ')} after promotion. Check npm, and re-run the workflow if it has not moved.`, + ); } console.log(`latest is on ${version} for every package.`); diff --git a/skills-contrib/publish-npm-version/SKILL.md b/skills-contrib/publish-npm-version/SKILL.md index 16cf72962..6dbc6e05c 100644 --- a/skills-contrib/publish-npm-version/SKILL.md +++ b/skills-contrib/publish-npm-version/SKILL.md @@ -5,7 +5,7 @@ description: >- package.json version, propagates it to every workspace package in lockstep, and opens a PR titled "chore(release): v". When a maintainer merges the PR, the `Publish to npm` workflow runs automatically and publishes - the new version to npm under dist-tag `rc`, plus a matching GitHub Release + the new version to npm under dist-tag `next`, plus a matching GitHub Release with auto-generated notes; users get it when a maintainer promotes it to `latest`. Use when a maintainer asks to "cut the next minor", "bump to the next version", "open a release PR", or "prepare a publish PR". @@ -60,7 +60,7 @@ undisturbed. gh pr create --base main --title "chore(release): v" \ --body "Release v. Merging this triggers the Publish to npm workflow." ``` -5. **Hand off.** Tell the maintainer the PR is open and that **merging it** publishes `` to npm under `rc` (via OIDC trusted publishing) and cuts a GitHub Release with auto-generated notes. Users get the release only once a maintainer promotes it to `latest` with the `Promote to latest` workflow (versioning.md § Promote a release to `latest`). Do not merge it yourself unless asked. +5. **Hand off.** Tell the maintainer the PR is open and that **merging it** publishes `` to npm under `next` (via OIDC trusted publishing) and cuts a GitHub Release with auto-generated notes. Users get the release only once a maintainer promotes it to `latest` with the `Promote to latest` workflow (versioning.md § Promote a release to `latest`). Do not merge it yourself unless asked. ## What this skill does NOT do From fd20a42e6e25b0742c1dc6acb8c2588d4b72fcdb Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:20:23 +1100 Subject: [PATCH 07/11] ci(promote): the Latest mark moves in its own job; branch dry runs get their own queue; review nits Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 19 ++++++++++++++----- docs/oss/versioning.md | 2 +- scripts/promote-packages-utils.ts | 2 +- scripts/promote-packages.ts | 10 +++++++--- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 0043452bb..5090a1f7e 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -24,8 +24,10 @@ on: default: true type: boolean +# A dry run from a branch gets its own group, so it cannot cancel a real +# promotion waiting in the queue. concurrency: - group: npm-promote + group: ${{ github.ref == 'refs/heads/main' && 'npm-promote' || format('npm-promote-{0}', github.ref) }} cancel-in-progress: false permissions: @@ -66,8 +68,6 @@ jobs: if: ${{ github.ref == 'refs/heads/main' && github.event.inputs.dry-run != 'true' }} runs-on: ubuntu-latest environment: npm-promote - permissions: - contents: write # Required to mark the GitHub Release as latest steps: - name: Checkout @@ -81,8 +81,17 @@ jobs: NPM_PROMOTE_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} run: node scripts/promote-packages.ts --version "$VERSION" - # The GitHub Release was created without GitHub's "Latest" mark - # (publish.yml); give it the mark now that npm `latest` is on it. + # Its own job, so the job holding the npm token has read-only access to + # the repository. The GitHub Release was created without GitHub's + # "Latest" mark (publish.yml); give it the mark now that npm `latest` is + # on it. + mark-latest: + name: Mark the GitHub Release as latest + needs: promote + runs-on: ubuntu-latest + permissions: + contents: write + steps: - name: Mark the GitHub Release as latest env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 5856e74a2..0ce91245f 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -111,7 +111,7 @@ npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a real 4. Run the promotion: `gh workflow run promote.yml -R prisma/composer --ref main -f version= -f dry-run=false`. 5. As soon as the run finishes, delete the secret (`gh secret delete NPM_PROMOTE_TOKEN --env npm-promote -R prisma/composer`) and revoke the token on npmjs.com. -Rolling `latest` back to an older Composer release works the same way, but the ORM check usually refuses it: an older release pins an older ORM, and the ORM's `latest` has moved on. Move the ORM's `latest` back first, or move Composer's `latest` by hand (`npm dist-tag add @ latest`, for each package). +Rolling `latest` back to an older Composer release works the same way, but the ORM check refuses it while the ORM's `latest` is newer than the ORM version that release pins. Move the ORM's `latest` back to that version first, then promote. Moving Composer's `latest` back by hand (`npm dist-tag add @ latest`, for each package) is a last resort: `@prisma/composer-prisma-cloud` takes the ORM as an exact peer dependency, so installing it and the ORM both at `latest` then fails, and GitHub's "Latest" mark stays on the newer release until you move it (`gh release edit v --latest`). ## Validating publish changes diff --git a/scripts/promote-packages-utils.ts b/scripts/promote-packages-utils.ts index 9f097aeb0..2c03c3c51 100644 --- a/scripts/promote-packages-utils.ts +++ b/scripts/promote-packages-utils.ts @@ -8,7 +8,7 @@ const ORM_PACKAGE_PREFIX = '@prisma/orm-'; export function assertReleaseVersion(version: string): void { if (!RELEASE_VERSION_PATTERN.test(version)) { throw new Error( - `"${version}" is not a release version. Give the version a release published, such as "0.41.0".`, + `"${version}" is not a release version. Give the version of a published release, such as "0.41.0".`, ); } } diff --git a/scripts/promote-packages.ts b/scripts/promote-packages.ts index b2edaeb4a..237f1eb99 100644 --- a/scripts/promote-packages.ts +++ b/scripts/promote-packages.ts @@ -108,13 +108,17 @@ const manifests: PublishedManifest[] = names.map((name) => ({ peerDependencies: dependencyField(name, 'peerDependencies'), })); const ormPins = collectOrmPins(manifests); +const ormLatest = new Map(ormPins.map((pin) => [pin.name, latestOf(pin.name)])); +const ormLatestOf = (name: string) => ormLatest.get(name); for (const pin of ormPins) { - console.log(` ORM pin ${pin.name}@${pin.version}: latest is ${latestOf(pin.name) ?? '(none)'}`); + console.log( + ` ORM pin ${pin.name}@${pin.version}: latest is ${ormLatestOf(pin.name) ?? '(none)'}`, + ); } -const ormMismatched = ormPinsNotLatest(ormPins, latestOf); +const ormMismatched = ormPinsNotLatest(ormPins, ormLatestOf); if (ormMismatched.length > 0) { const listed = ormMismatched - .map((pin) => `${pin.name}@${pin.version} (latest is ${latestOf(pin.name) ?? 'unset'})`) + .map((pin) => `${pin.name}@${pin.version} (latest is ${ormLatestOf(pin.name) ?? 'unset'})`) .join(', '); fail( `Not promoting: ${version} pins Prisma ORM versions that are not the ORM's latest: ${listed}. ` + From 12732ab4bea52f8298cc3472c8ff42d1886f3451 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:22:17 +1100 Subject: [PATCH 08/11] ci(promote): the Latest-mark job names its repository for gh Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 1 + docs/oss/versioning.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 5090a1f7e..056729ff8 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -95,5 +95,6 @@ jobs: - name: Mark the GitHub Release as latest env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} VERSION: ${{ github.event.inputs.version }} run: gh release edit "v$VERSION" --latest diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 0ce91245f..0f4dd3bdd 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -99,7 +99,7 @@ The [`Promote to latest`](../../.github/workflows/promote.yml) workflow moves `l - a real run is on `main` (a dry run may come from a branch, to try a change to the workflow); - the release's GitHub Release exists; - every package has the version on npm; -- every Prisma ORM version the release pins is already the ORM's `latest`. Promote the ORM first. +- every Prisma ORM version the release pins is already the ORM's `latest`. If it is not, move the ORM's `latest` to the pinned version first. Packages already on the version are left alone, so a second run is harmless, and a run that failed partway finishes when re-run. A real run then marks the release's GitHub Release as GitHub's latest release. From 3c850c2afa6615fd0122d660fbae413c1d6f5cc9 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:27:46 +1100 Subject: [PATCH 09/11] docs(versioning): the trusted-publisher setup names the composer repository 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 0f4dd3bdd..3a73e2394 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -138,7 +138,7 @@ package (e.g. a new `@prisma/composer-`)._ 2. **Configure a trusted publisher on each published package** at `npmjs.com/package//access` → *Trusted Publisher* → GitHub Actions: - Organization or user: `prisma` - - Repository: `compose` + - Repository: `composer` - Workflow filename: `publish.yml` - Environment: leave blank - Allowed action: **npm publish** From c429b44bcc9a55601721d507252b98682dc66d76 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:42:05 +1100 Subject: [PATCH 10/11] ci(promote): follow the ORM's promotion pattern: plan from the release tag as data, a token job that runs no repository code, allow-downgrade Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/promote.yml | 195 +++++++++++++----- docs/oss/versioning.md | 24 ++- scripts/determine-version-utils.ts | 2 +- scripts/promote-packages.ts | 186 ----------------- ....test.ts => promote-release-utils.test.ts} | 46 +++-- ...ages-utils.ts => promote-release-utils.ts} | 43 ++-- scripts/promote-release.ts | 170 +++++++++++++++ skills-contrib/publish-npm-version/SKILL.md | 2 +- 8 files changed, 392 insertions(+), 276 deletions(-) delete mode 100644 scripts/promote-packages.ts rename scripts/{promote-packages-utils.test.ts => promote-release-utils.test.ts} (72%) rename scripts/{promote-packages-utils.ts => promote-release-utils.ts} (61%) create mode 100644 scripts/promote-release.ts diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 056729ff8..d61418052 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -1,28 +1,36 @@ -name: Promote to latest +name: Promote a release to latest -# A release publishes under the npm dist-tag `next` and never moves `latest` -# (publish.yml). This workflow moves `latest` to a published release on every -# package, then marks its GitHub Release as GitHub's latest release. 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` to a published +# release, by hand, once the Prisma ORM, Composer and prisma CLI versions that +# work together are all released and checked. See docs/oss/versioning.md. # -# npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a -# real run needs an npm token. The repository keeps none: the promoter adds -# the secret NPM_PROMOTE_TOKEN to the `npm-promote` environment just before -# a run and deletes it straight after. Only the `promote` job uses that -# environment, and only on a real run from `main`; the checks need no token. +# 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. Holds no npm token. on: workflow_dispatch: inputs: version: - description: "Release version to promote, e.g. 0.41.0" + description: "Release version to promote, such as 0.41.0" required: true type: string dry-run: - description: "Dry-run only (run the checks; change nothing)." + description: "Dry run: check the release and print the moves, without changing any tag" required: false default: true type: boolean + allow-downgrade: + description: "Allow moving latest back to an older release (a rollback)" + required: false + default: false + type: boolean # A dry run from a branch gets its own group, so it cannot cancel a real # promotion waiting in the queue. @@ -30,71 +38,160 @@ concurrency: group: ${{ github.ref == 'refs/heads/main' && 'npm-promote' || format('npm-promote-{0}', github.ref) }} cancel-in-progress: false -permissions: - contents: read +permissions: {} jobs: check: - name: Check the release can be promoted + name: Check the release runs-on: ubuntu-latest + permissions: + contents: read + outputs: + plan: ${{ steps.plan.outputs.plan }} + steps: - # A dry run may come from a branch, to try a change to this workflow; - # the job holds no secret. - - name: Require main for a real run - if: ${{ github.ref != 'refs/heads/main' && github.event.inputs.dry-run != 'true' }} + - name: Check the inputs + env: + VERSION: ${{ inputs.version }} + DRY_RUN: ${{ inputs.dry-run }} run: | - echo "::error::A real promotion runs only from main (this run is on $GITHUB_REF)." - exit 1 + if ! printf '%s' "$VERSION" | grep -Eq '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'; then + echo "::error::\"$VERSION\" is not a release version, such as 0.41.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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + fetch-depth: 0 + persist-credentials: false - - uses: ./.github/actions/setup + # Data only: nothing in this folder is run. + - name: Checkout the release's tag as data + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + ref: v${{ inputs.version }} + path: release-data + persist-credentials: false - - name: Check every package (dry run) + - name: Check the release's tag is on main env: - VERSION: ${{ github.event.inputs.version }} - run: node scripts/promote-packages.ts --version "$VERSION" --dry-run + VERSION: ${{ inputs.version }} + run: | + 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 - name: Check the GitHub Release exists env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VERSION: ${{ github.event.inputs.version }} - run: gh release view "v$VERSION" --json tagName > /dev/null + GH_TOKEN: ${{ github.token }} + VERSION: ${{ inputs.version }} + run: gh release view "v$VERSION" --repo "$GITHUB_REPOSITORY" --json tagName > /dev/null + + - uses: ./.github/actions/setup + + - name: Plan the promotion + id: plan + env: + VERSION: ${{ inputs.version }} + ALLOW_DOWNGRADE: ${{ inputs.allow-downgrade }} + run: | + 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 to the release needs: check - if: ${{ github.ref == 'refs/heads/main' && github.event.inputs.dry-run != 'true' }} + if: ${{ github.ref == 'refs/heads/main' && !inputs.dry-run }} runs-on: ubuntu-latest environment: npm-promote + permissions: {} + outputs: + version: ${{ steps.move.outputs.version }} steps: - - name: Checkout - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - - - uses: ./.github/actions/setup + - name: Check the npm token + env: + NPM_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} + run: | + 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 + echo "::add-mask::$NPM_TOKEN" - - name: Promote packages + # 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: ${{ github.event.inputs.version }} - NPM_PROMOTE_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} - run: node scripts/promote-packages.ts --version "$VERSION" - - # Its own job, so the job holding the npm token has read-only access to - # the repository. The GitHub Release was created without GitHub's - # "Latest" mark (publish.yml); give it the mark now that npm `latest` is - # on it. + NODE_AUTH_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} + PLAN: ${{ needs.check.outputs.plan }} + run: | + set -euo pipefail + version_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$' + name_re='^@prisma/composer(-[a-z0-9-]+)?$' + 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 release 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" = "$release" ] || { echo "::error::The plan gives $name \"$version\", not the release's $release."; 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 + done 3<<<"$entries" + echo "version=$release" >> "$GITHUB_OUTPUT" + mark-latest: - name: Mark the GitHub Release as latest + name: Mark the GitHub Release as Latest needs: promote runs-on: ubuntu-latest permissions: contents: write steps: - - name: Mark the GitHub Release as latest + # publish.yml creates the GitHub Release without the Latest mark. + - name: Mark the GitHub Release as Latest env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GH_REPO: ${{ github.repository }} - VERSION: ${{ github.event.inputs.version }} - run: gh release edit "v$VERSION" --latest + GH_TOKEN: ${{ github.token }} + VERSION: ${{ needs.promote.outputs.version }} + run: gh release edit "v$VERSION" --repo "$GITHUB_REPOSITORY" --latest diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index 3a73e2394..a8eb94bdf 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -53,8 +53,8 @@ building on a false assumption. [npm provenance attestation](https://docs.npmjs.com/generating-provenance-statements) tying it to this repository and the workflow run that produced it (provenance requires the repo to be public, which it is). -- Moving `latest` needs an npm token, because trusted publishing does not cover `npm dist-tag`. The [`Promote to latest`](../../.github/workflows/promote.yml) workflow reads a short-lived, package-limited token from the `npm-promote` environment, which holds it only for the length of a promotion (see [Promote a release to `latest`](#promote-a-release-to-latest)). -- The `Publish to npm` workflow only produces a real publish from `main`. Its dry-runs are permitted from any branch via `workflow_dispatch` (see below); every step that mutates external state is independently guarded. The `Promote to latest` workflow likewise moves `latest` only from `main`. +- Moving `latest` needs an npm token, because trusted publishing does not cover `npm dist-tag`. The [`Promote a release to latest`](../../.github/workflows/promote.yml) workflow reads a short-lived, package-limited token from the `npm-promote` environment, which holds it only for the length of a promotion (see [Promote a release to `latest`](#promote-a-release-to-latest)). +- The `Publish to npm` workflow only produces a real publish from `main`. Its dry-runs are permitted from any branch via `workflow_dispatch` (see below); every step that mutates external state is independently guarded. The `Promote a release to latest` workflow likewise moves `latest` only from `main`. ## Mechanism: how we deliver the contract @@ -94,24 +94,26 @@ Between releases, every merge to `main` publishes a `-dev.N` build under ` ## Promote a release to `latest` -The [`Promote to latest`](../../.github/workflows/promote.yml) workflow moves `latest` to a published release on every package the publish workflow publishes (every workspace package that is not private). Before changing anything it checks that: +The [`Promote a release to latest`](../../.github/workflows/promote.yml) workflow moves `latest` to a published release on every package the release published (the packages in `packages/9-public/` at the release's tag). It runs in three jobs, so that the npm token meets no code from the repository and no repository write access: -- a real run is on `main` (a dry run may come from a branch, to try a change to the workflow); -- the release's GitHub Release exists; -- every package has the version on npm; -- every Prisma ORM version the release pins is already the ORM's `latest`. If it is not, move the ORM's `latest` to the pinned version first. - -Packages already on the version are left alone, so a second run is harmless, and a run that failed partway finishes when re-run. A real run then marks the release's GitHub Release as GitHub's latest release. +- **check** holds no token and can only read. It runs [`scripts/promote-release.ts`](../../scripts/promote-release.ts) from the workflow's own ref against the release's tag, `v`, which it checks out as data only. A dry run ends here, and may come from a branch, to try a change to the workflow. It refuses unless: + - a real run is on `main`; + - the tag's commit is on `main`, and the release's GitHub Release exists; + - every package has the version on npm; + - every Prisma ORM version the release pins is already the ORM's `latest`. If it is not, move the ORM's `latest` to the pinned version first; + - no package's `latest` would move back to an older release, unless the run sets `allow-downgrade`. +- **promote** runs only on a real run from `main`. It holds the token, has no repository permissions and checks out nothing: it moves `latest` for each package in the plan the check job wrote, after checking each name and version in it. Packages already on the version are left alone, so a second run is harmless, and a run that failed partway finishes when re-run. +- **mark-latest** gives the release's GitHub Release GitHub's "Latest" mark. It holds no npm token. npm trusted publishing covers `npm publish` only, not `npm dist-tag`, so a real run needs an npm token. The repository keeps none between promotions. Before the first promotion, do the [one-time setup](#one-time-setup-the-npm-promote-environment-maintainers). Then: -1. Run the checks with a dry run, which needs no token: `gh workflow run promote.yml -R prisma/composer --ref main -f version=`. Its log lists the packages and the ORM pins it compared, and says if `latest` would move to an older version. +1. Run the checks with a dry run, which needs no token: `gh workflow run promote.yml -R prisma/composer --ref main -f version=`. Its log lists the packages and the ORM pins it compared. 2. On npmjs.com, create a **granular access token** with read and write access to the packages the dry run listed and nothing else, the shortest expiry npm allows, and **Bypass two-factor authentication** ticked (without it, `npm dist-tag add` in CI fails asking for a one-time password). 3. Add it to the `npm-promote` environment: `gh secret set NPM_PROMOTE_TOKEN --env npm-promote -R prisma/composer`. It prompts for the value, so the token is not on your command line or in your shell history. 4. Run the promotion: `gh workflow run promote.yml -R prisma/composer --ref main -f version= -f dry-run=false`. 5. As soon as the run finishes, delete the secret (`gh secret delete NPM_PROMOTE_TOKEN --env npm-promote -R prisma/composer`) and revoke the token on npmjs.com. -Rolling `latest` back to an older Composer release works the same way, but the ORM check refuses it while the ORM's `latest` is newer than the ORM version that release pins. Move the ORM's `latest` back to that version first, then promote. Moving Composer's `latest` back by hand (`npm dist-tag add @ latest`, for each package) is a last resort: `@prisma/composer-prisma-cloud` takes the ORM as an exact peer dependency, so installing it and the ORM both at `latest` then fails, and GitHub's "Latest" mark stays on the newer release until you move it (`gh release edit v --latest`). +Rolling `latest` back to an older Composer release works the same way, with `-f allow-downgrade=true`. The ORM check still refuses it while the ORM's `latest` is newer than the ORM version that release pins: move the ORM's `latest` back to that version first, then promote. Moving Composer's `latest` back by hand (`npm dist-tag add @ latest`, for each package) is a last resort: `@prisma/composer-prisma-cloud` takes the ORM as an exact peer dependency, so installing it and the ORM both at `latest` then fails, and GitHub's "Latest" mark stays on the newer release until you move it (`gh release edit v --latest`). ## Validating publish changes diff --git a/scripts/determine-version-utils.ts b/scripts/determine-version-utils.ts index b24a0423f..e14416343 100644 --- a/scripts/determine-version-utils.ts +++ b/scripts/determine-version-utils.ts @@ -89,7 +89,7 @@ export function planDispatchPublish(base: string, input: string | undefined): Pu const tag = input?.trim() || RELEASE_DIST_TAG; if (tag === 'latest' || tag === 'dev') { throw new Error( - `A manual publish run cannot publish under "${tag}". Re-publish a release under "next", and promote it to "latest" with the Promote to latest workflow (docs/oss/versioning.md).`, + `A manual publish run cannot publish under "${tag}". Re-publish a release under "next", and promote it to "latest" with the Promote a release to latest workflow (docs/oss/versioning.md).`, ); } return { version: base, tag, release: tag === RELEASE_DIST_TAG }; diff --git a/scripts/promote-packages.ts b/scripts/promote-packages.ts deleted file mode 100644 index 237f1eb99..000000000 --- a/scripts/promote-packages.ts +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env node - -/** - * Moves the npm `latest` dist-tag to a published release on every package - * the publish workflow publishes. Run by `.github/workflows/promote.yml`. - * - * Usage: node scripts/promote-packages.ts --version [--dry-run] - * - * Before changing anything it checks that every package has the version on - * npm and that every Prisma ORM version the release pins is already the - * ORM's `latest`. Packages already on the version are left alone, so a - * second run is harmless. A real run reads the npm token from `NPM_PROMOTE_TOKEN`; - * npm gets it through an npmrc that names the variable, never the value. - */ - -import { execFileSync } from 'node:child_process'; -import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; -import { tmpdir } from 'node:os'; -import { join } from 'node:path'; - -import { - assertReleaseVersion, - collectOrmPins, - isOlderRelease, - ormPinsNotLatest, - type PackageOnNpm, - type PublishedManifest, - planPromotion, -} from './promote-packages-utils.ts'; - -function fail(message: string): never { - console.error(message); - process.exit(1); -} - -const args = process.argv.slice(2); -let requested: string | undefined; -let dryRun = false; -for (let i = 0; i < args.length; i++) { - if (args[i] === '--version') requested = args[++i]; - else if (args[i] === '--dry-run') dryRun = true; - else fail(`Unknown argument: ${args[i]}`); -} -if (requested === undefined) fail('Usage: promote-packages.ts --version [--dry-run]'); -const version: string = requested; -try { - assertReleaseVersion(version); -} catch (error) { - fail(error instanceof Error ? error.message : String(error)); -} - -interface WorkspacePackage { - name?: string; - path?: string; - private?: boolean; -} - -function publishedPackageNames(): string[] { - const listJson = execFileSync('pnpm', ['list', '-r', '--json', '--depth', '-1'], { - encoding: 'utf-8', - maxBuffer: 64 * 1024 * 1024, - }); - const workspace: WorkspacePackage[] = JSON.parse(listJson); - return workspace.flatMap((p) => (!p.private && p.path && p.name ? [p.name] : [])); -} - -/** `npm view`, with `undefined` when npm has no such package or version. */ -function npmView(spec: string, ...fields: string[]): string | undefined { - try { - const out = execFileSync('npm', ['view', spec, ...fields], { - encoding: 'utf-8', - stdio: ['ignore', 'pipe', 'pipe'], - }).trim(); - return out === '' ? undefined : out; - } catch (error) { - if (error instanceof Error && 'stderr' in error && String(error.stderr).includes('E404')) { - return undefined; - } - throw error; - } -} - -const latestOf = (name: string) => npmView(name, 'dist-tags.latest'); - -const names = publishedPackageNames(); -const packages: PackageOnNpm[] = names.map((name) => ({ - name, - hasVersion: npmView(`${name}@${version}`, 'version') === version, - latest: latestOf(name), -})); -const plan = planPromotion(version, packages); - -console.log(`Promoting ${version} to latest${dryRun ? ' (dry run)' : ''}.`); -for (const pkg of packages) console.log(` ${pkg.name}: latest is ${pkg.latest ?? '(none)'}`); - -if (plan.missing.length > 0) { - fail( - `Not promoting: ${version} is not on npm for ${plan.missing.join(', ')}. Nothing was changed.`, - ); -} - -// One field per call: with several fields, npm drops the field names when -// only one of them is set. -const dependencyField = (name: string, field: string): Record => - JSON.parse(npmView(`${name}@${version}`, field, '--json') ?? '{}'); -const manifests: PublishedManifest[] = names.map((name) => ({ - dependencies: dependencyField(name, 'dependencies'), - peerDependencies: dependencyField(name, 'peerDependencies'), -})); -const ormPins = collectOrmPins(manifests); -const ormLatest = new Map(ormPins.map((pin) => [pin.name, latestOf(pin.name)])); -const ormLatestOf = (name: string) => ormLatest.get(name); -for (const pin of ormPins) { - console.log( - ` ORM pin ${pin.name}@${pin.version}: latest is ${ormLatestOf(pin.name) ?? '(none)'}`, - ); -} -const ormMismatched = ormPinsNotLatest(ormPins, ormLatestOf); -if (ormMismatched.length > 0) { - const listed = ormMismatched - .map((pin) => `${pin.name}@${pin.version} (latest is ${ormLatestOf(pin.name) ?? 'unset'})`) - .join(', '); - fail( - `Not promoting: ${version} pins Prisma ORM versions that are not the ORM's latest: ${listed}. ` + - "If the ORM's latest is older, promote the ORM first. If it is newer, users would get this release with an ORM it was not released with: release Composer on that ORM, or move the ORM's latest back first. Nothing was changed.", - ); -} - -for (const name of plan.alreadyLatest) console.log(` ${name}: already on ${version}`); -for (const pkg of packages.filter((p) => plan.toMove.includes(p.name))) { - const older = pkg.latest !== undefined && isOlderRelease(version, pkg.latest); - console.log( - ` ${pkg.name}: ${dryRun ? 'would move' : 'will move'} latest to ${version}${older ? `, which is OLDER than ${pkg.latest}` : ''}`, - ); -} - -if (dryRun || plan.toMove.length === 0) process.exit(0); - -if (!process.env['NPM_PROMOTE_TOKEN']) { - fail( - 'NPM_PROMOTE_TOKEN is not set. Add it as a secret of the npm-promote environment for this run (docs/oss/versioning.md). Nothing was changed.', - ); -} - -const configDir = mkdtempSync(join(process.env['RUNNER_TEMP'] ?? tmpdir(), 'promote-')); -const npmrc = join(configDir, '.npmrc'); -// biome-ignore lint/suspicious/noTemplateCurlyInString: npm expands ${NPM_PROMOTE_TOKEN} itself, so the file never holds the token. -writeFileSync(npmrc, '//registry.npmjs.org/:_authToken=${NPM_PROMOTE_TOKEN}\n'); -const moved: string[] = []; -let failedOn: string | undefined; -try { - for (const name of plan.toMove) { - try { - execFileSync( - 'npm', - ['dist-tag', 'add', `${name}@${version}`, 'latest', '--userconfig', npmrc], - { stdio: 'inherit' }, - ); - } catch { - failedOn = name; - break; - } - moved.push(name); - } -} finally { - rmSync(configDir, { recursive: true, force: true }); -} -if (failedOn !== undefined) { - fail( - `Moving latest failed for ${failedOn}. Moved so far: ${moved.join(', ') || 'none'}. Fix the cause and re-run the workflow; it skips packages already on ${version}.`, - ); -} - -// The registry can serve the old tag for a little while after a change. -let stillBehind = names; -for (let attempt = 1; attempt <= 6; attempt++) { - stillBehind = stillBehind.filter((name) => latestOf(name) !== version); - if (stillBehind.length === 0) break; - if (attempt < 6) execFileSync('sleep', ['10']); -} -if (stillBehind.length > 0) { - fail( - `latest is not on ${version} for ${stillBehind.join(', ')} after promotion. Check npm, and re-run the workflow if it has not moved.`, - ); -} -console.log(`latest is on ${version} for every package.`); diff --git a/scripts/promote-packages-utils.test.ts b/scripts/promote-release-utils.test.ts similarity index 72% rename from scripts/promote-packages-utils.test.ts rename to scripts/promote-release-utils.test.ts index de3954adc..34f422da4 100644 --- a/scripts/promote-packages-utils.test.ts +++ b/scripts/promote-release-utils.test.ts @@ -7,7 +7,8 @@ import { isOlderRelease, ormPinsNotLatest, planPromotion, -} from './promote-packages-utils.ts'; + promotionPlan, +} from './promote-release-utils.ts'; describe('assertReleaseVersion', () => { it('accepts a release version', () => { @@ -26,33 +27,52 @@ describe('planPromotion', () => { assert.deepEqual( planPromotion('0.41.0', [ { name: 'a', hasVersion: true, latest: '0.40.0' }, - { name: 'b', hasVersion: true, latest: '0.40.0' }, + { name: 'b', hasVersion: true, latest: undefined }, ]), - { missing: [], toMove: ['a', 'b'], alreadyLatest: [] }, + { + missing: [], + moves: [ + { name: 'a', from: '0.40.0', back: false }, + { name: 'b', from: undefined, back: false }, + ], + unchanged: [], + }, ); }); it('reports packages missing the version', () => { assert.deepEqual( - planPromotion('0.41.0', [ - { name: 'a', hasVersion: true, latest: '0.40.0' }, - { name: 'b', hasVersion: false, latest: '0.40.0' }, - ]), - { missing: ['b'], toMove: ['a'], alreadyLatest: [] }, + planPromotion('0.41.0', [{ name: 'b', hasVersion: false, latest: '0.40.0' }]).missing, + ['b'], ); }); it('leaves packages already on the version alone, so a second run changes nothing', () => { + const promotion = planPromotion('0.41.0', [{ name: 'a', hasVersion: true, latest: '0.41.0' }]); + assert.deepEqual(promotion.unchanged, ['a']); + assert.deepEqual(promotion.moves, []); + }); + + it('marks a move back to an older release', () => { assert.deepEqual( - planPromotion('0.41.0', [ - { name: 'a', hasVersion: true, latest: '0.41.0' }, - { name: 'b', hasVersion: true, latest: undefined }, - ]), - { missing: [], toMove: ['b'], alreadyLatest: ['a'] }, + planPromotion('0.39.0', [{ name: 'a', hasVersion: true, latest: '0.40.0' }]).moves, + [{ name: 'a', from: '0.40.0', back: true }], ); }); }); +describe('promotionPlan', () => { + it('lists every package at the release version', () => { + assert.deepEqual(promotionPlan('0.41.0', ['@prisma/composer', '@prisma/composer-cli']), { + version: '0.41.0', + packages: [ + { name: '@prisma/composer', version: '0.41.0' }, + { name: '@prisma/composer-cli', version: '0.41.0' }, + ], + }); + }); +}); + describe('isOlderRelease', () => { it('compares each part as a number', () => { assert.equal(isOlderRelease('0.9.0', '0.10.0'), true); diff --git a/scripts/promote-packages-utils.ts b/scripts/promote-release-utils.ts similarity index 61% rename from scripts/promote-packages-utils.ts rename to scripts/promote-release-utils.ts index 2c03c3c51..50e2eff19 100644 --- a/scripts/promote-packages-utils.ts +++ b/scripts/promote-release-utils.ts @@ -1,5 +1,5 @@ -// Pure helpers for `promote-packages.ts`, exercised under `node --test` -// from `pnpm test:scripts`. All npm I/O lives in the caller. +// Pure helpers for `promote-release.ts`, exercised under `node --test` +// from `pnpm test:scripts`. All npm and file I/O lives in the caller. const RELEASE_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/; const EXACT_VERSION_PATTERN = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/; @@ -29,24 +29,37 @@ export interface PackageOnNpm { latest: string | undefined; } -export interface PromotionPlan { +export interface Promotion { + /** Packages without the version on npm; the caller then changes nothing. */ missing: string[]; - toMove: string[]; - alreadyLatest: string[]; + /** Packages whose `latest` moves to the version, with where it moves from. */ + moves: { name: string; from: string | undefined; back: boolean }[]; + /** Packages whose `latest` is already on the version. */ + unchanged: string[]; } -/** - * Which packages to move `latest` on. Any package without the version on - * npm is `missing`, and the caller then changes nothing at all. - */ -export function planPromotion(version: string, packages: readonly PackageOnNpm[]): PromotionPlan { - const plan: PromotionPlan = { missing: [], toMove: [], alreadyLatest: [] }; +/** What promoting `version` does to each package. */ +export function planPromotion(version: string, packages: readonly PackageOnNpm[]): Promotion { + const promotion: Promotion = { missing: [], moves: [], unchanged: [] }; for (const pkg of packages) { - if (!pkg.hasVersion) plan.missing.push(pkg.name); - else if (pkg.latest === version) plan.alreadyLatest.push(pkg.name); - else plan.toMove.push(pkg.name); + if (!pkg.hasVersion) promotion.missing.push(pkg.name); + else if (pkg.latest === version) promotion.unchanged.push(pkg.name); + else { + const back = pkg.latest !== undefined && isOlderRelease(version, pkg.latest); + promotion.moves.push({ name: pkg.name, from: pkg.latest, back }); + } } - return plan; + return promotion; +} + +/** What the promote job moves: every package of the release, at its version. */ +export interface PromotionPlan { + version: string; + packages: { name: string; version: string }[]; +} + +export function promotionPlan(version: string, names: readonly string[]): PromotionPlan { + return { version, packages: names.map((name) => ({ name, version })) }; } export interface PublishedManifest { diff --git a/scripts/promote-release.ts b/scripts/promote-release.ts new file mode 100644 index 000000000..f048dbcef --- /dev/null +++ b/scripts/promote-release.ts @@ -0,0 +1,170 @@ +#!/usr/bin/env node + +/** + * Checks a published release before `.github/workflows/promote.yml` moves + * `latest` to it, and writes what to move. It moves no tag and needs no + * token (docs/oss/versioning.md). + * + * 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 `package.json` and the manifests in + * `packages/9-public/`, the only place publishable packages live. It + * defaults to this repository. Stops when any package is not on npm at the + * version, when a Prisma ORM version the release pins is not the ORM's + * `latest`, and when a move would take `latest` back to an older release + * unless `--allow-downgrade` is given. + */ + +import { execFileSync } from 'node:child_process'; +import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'; +import { dirname, join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import { + assertReleaseVersion, + collectOrmPins, + ormPinsNotLatest, + type PackageOnNpm, + type PublishedManifest, + planPromotion, + promotionPlan, +} from './promote-release-utils.ts'; + +const USAGE = + 'Usage: node scripts/promote-release.ts [--release-root ] [--allow-downgrade] [--plan-out ]'; + +function fail(message: string, code = 1): never { + console.error(message); + process.exit(code); +} + +let version: string | undefined; +let releaseRoot = dirname(dirname(fileURLToPath(import.meta.url))); +let allowDowngrade = false; +let planOut: string | undefined; +const args = process.argv.slice(2); +for (let i = 0; i < args.length; i++) { + const arg = args[i] ?? ''; + const value = args[i + 1]; + if (arg === '--allow-downgrade') allowDowngrade = true; + else if (arg === '--release-root' && value !== undefined) { + releaseRoot = resolve(value); + i++; + } else if (arg === '--plan-out' && value !== undefined) { + planOut = resolve(value); + i++; + } else if (!arg.startsWith('--') && version === undefined) version = arg; + else fail(USAGE, 2); +} +if (version === undefined) fail(USAGE, 2); +const release: string = version; +try { + assertReleaseVersion(release); +} catch (error) { + fail(error instanceof Error ? error.message : String(error)); +} + +interface Manifest { + name?: string; + version?: string; + private?: boolean; +} + +const readJson = (file: string): Manifest => JSON.parse(readFileSync(file, 'utf-8')); + +const rootVersion = readJson(join(releaseRoot, 'package.json')).version; +if (rootVersion !== release) { + fail( + `The release data is release ${rootVersion}, not ${release}. Check out the release's tag, v${release}, as the release data, and run again.`, + ); +} + +const publicDir = join(releaseRoot, 'packages', '9-public'); +const names = readdirSync(publicDir) + .map((dir) => join(publicDir, dir, 'package.json')) + .filter((file) => existsSync(file)) + .map(readJson) + .flatMap((manifest) => (!manifest.private && manifest.name ? [manifest.name] : [])) + .sort(); +if (names.length === 0) fail(`No published package found in ${publicDir}.`); + +/** `npm view`, with `undefined` when npm has no such package or version. */ +function npmView(spec: string, ...fields: string[]): string | undefined { + try { + const out = execFileSync('npm', ['view', spec, ...fields], { + encoding: 'utf-8', + stdio: ['ignore', 'pipe', 'pipe'], + }).trim(); + return out === '' ? undefined : out; + } catch (error) { + if (error instanceof Error && 'stderr' in error && String(error.stderr).includes('E404')) { + return undefined; + } + throw error; + } +} + +const latestOf = (name: string) => npmView(name, 'dist-tags.latest'); + +const packages: PackageOnNpm[] = names.map((name) => ({ + name, + hasVersion: npmView(`${name}@${release}`, 'version') === release, + latest: latestOf(name), +})); +const promotion = planPromotion(release, packages); + +console.log(`Promoting release ${release} to latest:`); +for (const pkg of packages) console.log(` ${pkg.name}: latest is ${pkg.latest ?? '(none)'}`); + +if (promotion.missing.length > 0) { + fail(`Not promoting: ${release} is not on npm for ${promotion.missing.join(', ')}.`); +} + +// One field per call: with several fields, npm drops the field names when +// only one of them is set. +const dependencyField = (name: string, field: string): Record => + JSON.parse(npmView(`${name}@${release}`, field, '--json') ?? '{}'); +const manifests: PublishedManifest[] = names.map((name) => ({ + dependencies: dependencyField(name, 'dependencies'), + peerDependencies: dependencyField(name, 'peerDependencies'), +})); +const ormPins = collectOrmPins(manifests); +const ormLatest = new Map(ormPins.map((pin) => [pin.name, latestOf(pin.name)])); +const ormLatestOf = (name: string) => ormLatest.get(name); +for (const pin of ormPins) { + console.log( + ` ORM pin ${pin.name}@${pin.version}: latest is ${ormLatestOf(pin.name) ?? '(none)'}`, + ); +} +const ormMismatched = ormPinsNotLatest(ormPins, ormLatestOf); +if (ormMismatched.length > 0) { + const listed = ormMismatched + .map((pin) => `${pin.name}@${pin.version} (latest is ${ormLatestOf(pin.name) ?? 'unset'})`) + .join(', '); + fail( + `Not promoting: ${release} pins Prisma ORM versions that are not the ORM's latest: ${listed}. ` + + "If the ORM's latest is older, promote the ORM first. If it is newer, users would get this release with an ORM it was not released with: release Composer on that ORM, or move the ORM's latest back first.", + ); +} + +const backwards = promotion.moves.filter((move) => move.back); +if (backwards.length > 0 && !allowDowngrade) { + fail( + `Not promoting: this moves latest back to an older release for ${backwards + .map((move) => `${move.name} (latest is ${move.from})`) + .join(', ')}. Run again with allow-downgrade to roll back on purpose.`, + ); +} + +for (const name of promotion.unchanged) console.log(` ${name}: already on ${release}`); +for (const move of promotion.moves) { + console.log( + ` ${move.name}: moves latest to ${release}${move.back ? ' (back to an older release)' : ''}`, + ); +} + +if (planOut !== undefined) { + writeFileSync(planOut, `${JSON.stringify(promotionPlan(release, names))}\n`); +} diff --git a/skills-contrib/publish-npm-version/SKILL.md b/skills-contrib/publish-npm-version/SKILL.md index 6dbc6e05c..359d788eb 100644 --- a/skills-contrib/publish-npm-version/SKILL.md +++ b/skills-contrib/publish-npm-version/SKILL.md @@ -60,7 +60,7 @@ undisturbed. gh pr create --base main --title "chore(release): v" \ --body "Release v. Merging this triggers the Publish to npm workflow." ``` -5. **Hand off.** Tell the maintainer the PR is open and that **merging it** publishes `` to npm under `next` (via OIDC trusted publishing) and cuts a GitHub Release with auto-generated notes. Users get the release only once a maintainer promotes it to `latest` with the `Promote to latest` workflow (versioning.md § Promote a release to `latest`). Do not merge it yourself unless asked. +5. **Hand off.** Tell the maintainer the PR is open and that **merging it** publishes `` to npm under `next` (via OIDC trusted publishing) and cuts a GitHub Release with auto-generated notes. Users get the release only once a maintainer promotes it to `latest` with the `Promote a release to latest` workflow (versioning.md § Promote a release to `latest`). Do not merge it yourself unless asked. ## What this skill does NOT do From 3f57579b6750e64a92cc77e0006be7ecb9861df2 Mon Sep 17 00:00:00 2001 From: willbot Date: Wed, 2 Dec 2026 16:47:14 +1100 Subject: [PATCH 11/11] ci(promote): the check job sets up node only, the token job checks the plan's version, and the tag is read by its full ref Signed-off-by: willbot Signed-off-by: Will Madden --- .drive/deferred.md | 1 + .github/workflows/promote.yml | 14 ++++++++++---- docs/oss/versioning.md | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.drive/deferred.md b/.drive/deferred.md index 8f9374a0b..33e0300ff 100644 --- a/.drive/deferred.md +++ b/.drive/deferred.md @@ -333,6 +333,7 @@ Each needs a change to the Prisma Cloud Management API. ## Later Composer work +- **The publishable-location lint does not check every workspace member.** `scripts/lint-publishable-location.mjs` lists manifests by path globs that leave out `website/`, which is in the pnpm workspace. The promotion workflow takes its package list from `packages/9-public/` at the release's tag, and the publish workflow publishes every non-private workspace member. If `website/` ever became publishable, publish would ship it, promotion would leave it out, and the lint would not notice. Nothing is wrong today: `website/` is private. Fix by having the lint list members the way `publish-packages.mjs` does (`pnpm list -r`). - **Destroying production deletes the operator's platform variables.** Destroying an app's production environment deletes its Prisma Cloud project, and with it every variable the operator set. The platform never returns a value, so an operator who kept no copy must make a new secret. Options: keep the project when it holds rows that are not Composer's, or warn before deleting. Needs its own decision about destroy. - **An author-declared per-reader variable**, one that maps to the service scope the platform is expected to add, so that two readers of one name are guaranteed different values. Not built: where a value lives is the operator's choice on the platform, and nobody has a case that needs the author to force it. Wait for a real case. - **A warning when the app names a variable another module expects under a different name.** Not needed: the deploy report lists every name with its readers, so a module wired to the wrong name shows up there. diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index d61418052..c8c536b47 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -7,7 +7,7 @@ name: Promote a release to latest # # 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 +# - check: no npm 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 @@ -74,7 +74,7 @@ jobs: - name: Checkout the release's tag as data uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: - ref: v${{ inputs.version }} + ref: refs/tags/v${{ inputs.version }} path: release-data persist-credentials: false @@ -82,7 +82,7 @@ jobs: env: VERSION: ${{ inputs.version }} run: | - tagged="$(git rev-parse "v$VERSION^{commit}")" + tagged="$(git rev-parse "refs/tags/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 @@ -98,7 +98,11 @@ jobs: VERSION: ${{ inputs.version }} run: gh release view "v$VERSION" --repo "$GITHUB_REPOSITORY" --json tagName > /dev/null - - uses: ./.github/actions/setup + # Node only: nothing else may run before the plan is written. + - name: Setup mise + uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1 + with: + cache: false - name: Plan the promotion id: plan @@ -142,6 +146,7 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }} PLAN: ${{ needs.check.outputs.plan }} + VERSION: ${{ inputs.version }} run: | set -euo pipefail version_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$' @@ -149,6 +154,7 @@ jobs: 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 release version."; exit 1; } + [ "$release" = "$VERSION" ] || { echo "::error::The plan is for $release, not the requested $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; } diff --git a/docs/oss/versioning.md b/docs/oss/versioning.md index a8eb94bdf..f6ee8730b 100644 --- a/docs/oss/versioning.md +++ b/docs/oss/versioning.md @@ -96,7 +96,7 @@ Between releases, every merge to `main` publishes a `-dev.N` build under ` The [`Promote a release to latest`](../../.github/workflows/promote.yml) workflow moves `latest` to a published release on every package the release published (the packages in `packages/9-public/` at the release's tag). It runs in three jobs, so that the npm token meets no code from the repository and no repository write access: -- **check** holds no token and can only read. It runs [`scripts/promote-release.ts`](../../scripts/promote-release.ts) from the workflow's own ref against the release's tag, `v`, which it checks out as data only. A dry run ends here, and may come from a branch, to try a change to the workflow. It refuses unless: +- **check** holds no npm token and can only read. It runs [`scripts/promote-release.ts`](../../scripts/promote-release.ts) from the workflow's own ref against the release's tag, `v`, which it checks out as data only. A dry run ends here, and may come from a branch, to try a change to the workflow. It refuses unless: - a real run is on `main`; - the tag's commit is on `main`, and the release's GitHub Release exists; - every package has the version on npm;