From d6e7394a31ebb33ec238f526097496fc2c151bd7 Mon Sep 17 00:00:00 2001 From: PIERLUIGI VITI Date: Thu, 15 Oct 2026 16:47:09 +0200 Subject: [PATCH] fix(release): tag with a git identity, release:prepare waits for pending releases - publish.yml sets the git identity of github-actions[bot] before ship: the release tags are annotated, and the runner has no identity (the 7.1.0 run failed on `git tag`; the earlier tags were made by hand) - the release PR script is now `pnpm release:prepare`: it prepares a release, publish.yml publishes it on merge - release:prepare stops while a merged release is not on npm yet: its tags don't exist yet, so it proposed the same changes again (cli 7.2.0, #297) Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish.yml | 8 +++++++- commitlint.config.mjs | 2 +- package.json | 2 +- packages/release/README.md | 4 ++-- packages/release/src/cli.ts | 4 ++-- packages/release/src/commands/publish.ts | 2 +- packages/release/src/commands/ship.ts | 4 ++-- packages/release/src/commands/version.ts | 11 ++++++++++- 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e4c1336f..5b45465d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,7 +1,7 @@ name: Publish # Releases the package versions not on npm yet, on every push to main: merging -# an approved release pull request (`pnpm release:publish`) publishes it, with +# an approved release pull request (`pnpm release:prepare`) publishes it, with # no other manual step. # # `cl-release ship --plan` finds the versions not on npm and the commit that @@ -145,6 +145,12 @@ jobs: node "$CL_RELEASE" manifest "$dir" done + # The release tags are annotated: git needs an identity to create them + - name: Git identity of the release tags + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Tag, publish to npm and release id: ship run: node "$CL_RELEASE" ship diff --git a/commitlint.config.mjs b/commitlint.config.mjs index b192ac23..10f3f1e9 100644 --- a/commitlint.config.mjs +++ b/commitlint.config.mjs @@ -7,7 +7,7 @@ */ export default { extends: ['@commitlint/config-conventional'], - // The release commits are written by `pnpm release:publish` and list + // The release commits are written by `pnpm release:prepare` and list // every released tag in the header, well past the length limit ignores: [(message) => message.startsWith('chore(release): ')], // Merge commits ("Merge branch 'main' into …") are allowed in a pull diff --git a/package.json b/package.json index dc52b88b..b34c7af9 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "lint": "biome check --enforce-assist=true", "check": "biome check --enforce-assist=true --write", "release:config": "cl-release labels", - "release:publish": "cl-release version", + "release:prepare": "cl-release version", "generate": "pnpm -r --if-present generate", "generate-local": "pnpm -r --if-present generate-local", "check:packages": "node scripts/check-packages.mjs", diff --git a/packages/release/README.md b/packages/release/README.md index 523c8d39..080992e4 100644 --- a/packages/release/README.md +++ b/packages/release/README.md @@ -4,7 +4,7 @@ Private workspace package, not published. The release tooling of the monorepo, r ## Releasing -1. `pnpm release:publish` bumps the changed packages and opens the `chore(release)` pull request, with the release notes of each package in its description. +1. `pnpm release:prepare` bumps the changed packages and opens the `chore(release)` pull request, with the release notes of each package in its description. 2. A reviewer approves it, and it is merged. 3. publish.yml, on the push to main, publishes the versions not on npm (`cl-release ship`): it builds and tests them from the commit that set them, then, dependencies first, tags each version, publishes it to npm (OIDC, provenance) and publishes its GitHub release. Each package published to npm gets its own Slack message, with the link to its release notes. @@ -13,7 +13,7 @@ A release that stopped halfway resumes by running publish.yml by hand: what is o ## Commands ```sh -cl-release version [--interactive | --yes] [--base ] [--no-pr] [--dry-run] # pnpm release:publish +cl-release version [--interactive | --yes] [--base ] [--no-pr] [--dry-run] # pnpm release:prepare cl-release ship [--plan] [--dry-run] # publish.yml cl-release tag [--base ] [--no-push] [--dry-run] # manual recovery cl-release try [...] [--out ] # pnpm release:try diff --git a/packages/release/src/cli.ts b/packages/release/src/cli.ts index d1fec50b..e0fc0d4d 100644 --- a/packages/release/src/cli.ts +++ b/packages/release/src/cli.ts @@ -1,14 +1,14 @@ /** * cl-release: the release tooling of the monorepo. * - * The root scripts run it (`pnpm release:publish`, …), and the workflows call + * The root scripts run it (`pnpm release:prepare`, …), and the workflows call * its commands directly (`pnpm exec cl-release resolve `, …). It works * from anywhere in the repository: it runs at the workspace root. */ import { execFileSync } from 'node:child_process' const COMMANDS = { - version: ['Bump the changed packages and open the release pull request (pnpm release:publish)', () => import('./commands/version.ts')], + version: ['Bump the changed packages and open the release pull request (pnpm release:prepare)', () => import('./commands/version.ts')], ship: ['Tag, publish to npm and release the versions not on npm (publish.yml)', () => import('./commands/ship.ts')], tag: ['Tag the versions not released yet and push the tags (manual recovery: ship tags them)', () => import('./commands/tag.ts')], try: ['Install the working tree in a sandbox, packed as for npm', () => import('./commands/try.ts')], diff --git a/packages/release/src/commands/publish.ts b/packages/release/src/commands/publish.ts index 76095158..5d36424e 100644 --- a/packages/release/src/commands/publish.ts +++ b/packages/release/src/commands/publish.ts @@ -39,7 +39,7 @@ export const dependenciesToPublish = ( const depTag = tagOf(dep) if (!tags.has(depTag)) throw new Error( - `${[...chain, p.name].join(' → ')} needs ${dep.name}@${dep.version}, which is not on npm and has no ${depTag} release tag. Release it with \`pnpm release:publish\`.`, + `${[...chain, p.name].join(' → ')} needs ${dep.name}@${dep.version}, which is not on npm and has no ${depTag} release tag. Release it with \`pnpm release:prepare\`.`, ) visit(dep, [...chain, p.name]) toPublish.push(dep) diff --git a/packages/release/src/commands/ship.ts b/packages/release/src/commands/ship.ts index 0a88b29e..0dec96ff 100644 --- a/packages/release/src/commands/ship.ts +++ b/packages/release/src/commands/ship.ts @@ -1,6 +1,6 @@ /** * Releases the package versions not on npm yet: run by publish.yml on every - * push to main, so merging an approved release PR (`pnpm release:publish`) + * push to main, so merging an approved release PR (`pnpm release:prepare`) * publishes it, with no other manual step. * * --plan finds them: the public packages whose package.json version isn't on @@ -119,7 +119,7 @@ export const run = async (args: string[]): Promise => { for (const name of workspaceDeps(pkg)) { const dep = all.get(name) if (dep && !names.has(name) && !onNpm(dep.name, dep.version)) - fail(`${pkg.name} needs ${dep.name}@${dep.version}, which is neither on npm nor in this release. Release it with \`pnpm release:publish\`.`) + fail(`${pkg.name} needs ${dep.name}@${dep.version}, which is neither on npm nor in this release. Release it with \`pnpm release:prepare\`.`) } } diff --git a/packages/release/src/commands/version.ts b/packages/release/src/commands/version.ts index 23828390..29a6b894 100644 --- a/packages/release/src/commands/version.ts +++ b/packages/release/src/commands/version.ts @@ -28,7 +28,7 @@ import { createInterface } from 'node:readline/promises' import { Bumper } from 'conventional-recommended-bump' import semver from 'semver' import { parse } from '../args.ts' -import { fail, git, lastTag, type Package, previousRelease, publicPackages, readJson, requireUpToDate, sortByDependencies, tagOf, workspaceDeps, writeJson } from '../workspace.ts' +import { fail, git, lastTag, onNpm, type Package, previousRelease, publicPackages, readJson, requireUpToDate, sortByDependencies, tagOf, workspaceDeps, writeJson } from '../workspace.ts' import { buildNotes } from './notes.ts' const USAGE = `Usage: cl-release version [--interactive | --yes] [--base ] [--no-pr] [--dry-run] @@ -138,6 +138,15 @@ export const run = async (args: string[]): Promise => { requireUpToDate(base) + // A merged release not on npm yet (publish.yml still running, or failed): + // its tags don't exist yet, so its changes would be released a second time + const pending = publicPackages().filter((p) => !semver.prerelease(p.version) && !onNpm(p.name, p.version)) + if (pending.length > 0) + fail( + `Not released yet: ${pending.map((p) => `${p.name}@${p.version}`).join(', ')}. ` + + 'Wait for publish.yml to publish them (Actions → Publish; run it again if it failed), then prepare the next release.', + ) + const candidates: Candidate[] = [] for (const pkg of publicPackages()) { const since = await lastTag(pkg)