Skip to content

Release: recompute the npm changelog backport instead of replaying it - #81566

Draft
sirreal wants to merge 2 commits into
trunkfrom
fix/npm-release-changelog-backport
Draft

sirreal wants to merge 2 commits into
trunkfrom
fix/npm-release-changelog-backport

Conversation

@sirreal

@sirreal sirreal commented Aug 13, 2026

Copy link
Copy Markdown
Member

What?

Closes #81506

Makes the npm release's changelog backport deterministic. The release tooling no longer replays the "Update changelog files" commit onto trunk with a bare git cherry-pick and pushes whatever comes out; it recomputes each changelog from what actually shipped, and it verifies the result before pushing anything.

Why?

A three-way merge of a markdown list knows line positions, not semantics. When trunk gains a changelog entry during the ~10-minute npm publication window, the cherry-pick files that entry under the version heading that was published minutes earlier — an entry attributed to a release that does not contain it. Worse, the merge only conflicts when the package's ## Unreleased section was empty at release time, which is precisely the case where the package shipped nothing. So the alarm fires only for packages that were fine, and packages that shipped changes are corrupted silently, every time. That is not bad luck; it is the design, and I would gently suggest it is the wrong design.

Both release cycles since July needed hand repair (#81303, #81304, #81480, #81485, #81502), and the August 12 manual recovery reproduced the same corruption it was fixing. Careful people cannot catch this, because nothing checks for it. This PR makes the tooling produce the right result, and refuse loudly when it cannot.

How?

Three changes, matching the issue's suggested fixes 1–3:

  1. Recompute instead of replay. The changelog commit is still applied with git cherry-pick --no-commit for the package.json changes the publish commit depends on, but every package changelog it touched is then rewritten by recomputeBackportedChangelog (new tools/release/lib/released-changelog.js): entries the target branch added since the release base stay under ## Unreleased with their subsection structure preserved, and everything from the new version heading down is taken verbatim from the released changelog. Conflicted files and cleanly-merged files go through the identical path, so the empty-## Unreleased conflict resolves itself. If the branch's released history does not match the release base (for example, an intermediate release that was never backported), the backport refuses with an explicit error rather than guessing. rerere is disabled for the picks so a resolution recorded on someone's machine cannot leak into a release.

  2. Verify before pushing. verifyBackportedChangelogs asserts that the released portion of every package changelog in the release tree is byte-identical on the branch tip. Anything else means an entry moved into or out of a published version section, and the push does not happen. Per the issue's warning about checks that quietly inspect nothing, finding zero changelogs to verify is itself a hard failure. The check runs inside the tool, so it covers the direct push that never becomes a PR.

  3. Independent branch backports. finalizePreparedNpmRelease now attempts trunk and the plugin release branch independently and reports every failure, instead of letting the first branch's conflict cancel the second branch's perfectly applicable backport. A failed backport restores the clone to origin/<branch> so its debris cannot poison the next target.

The issue's fix 4 (a finalize recovery subcommand) is deliberately not included; it is a feature rather than a defect fix, and the recompute/verify functions are exported so it can be built on top of this.

#81561 corrects the historical misattributions in the changelog data and is stacked on this branch.

Testing Instructions

  1. npm run test:unit -- tools/release — covers the recompute, the verification, and the backport orchestration, including the two shapes from the August 12 incident: the entry git merges cleanly into the wrong section, and the empty-## Unreleased conflict.
  2. For an end-to-end check against real git, the scenario from the issue reproduces in a scratch repository:
End-to-end reproduction
mkdir -p /tmp/backport-e2e && cd /tmp/backport-e2e
git init -q --bare origin.git && git clone -q origin.git work && cd work
git switch -qc main && mkdir -p packages/data
printf '# Changelog\n\n## Unreleased\n\n### Bug Fixes\n\n-   Shipped fix. ([#1](x))\n\n## 1.0.0 (2026-01-01)\n' > packages/data/CHANGELOG.md
printf '{\n\t"version": "1.0.0"\n}\n' > packages/data/package.json
git add -A && git commit -qm base && git push -q origin main

# The release: version heading + prerelease bump, then the publish commit.
git switch -qc wp-latest
perl -0pi -e 's/## Unreleased/## Unreleased\n\n## 1.1.0 (2026-08-12)/' packages/data/CHANGELOG.md
perl -0pi -e 's/1\.0\.0/1.1.0-prerelease/' packages/data/package.json
git commit -qam 'Update changelog files'
perl -0pi -e 's/-prerelease//' packages/data/package.json
git commit -qam 'Publish'

# Trunk moves during publication: this is the entry git silently misfiles.
git switch -q main
perl -0pi -e 's/-   Shipped fix\. \(\[#1\]\(x\)\)/-   Shipped fix. ([#1](x))\n-   Landed during publish. ([#9](x))/' packages/data/CHANGELOG.md
git commit -qam 'trunk moved' && git push -q origin main

Then, from a Gutenberg checkout on this branch, drive the backport with the two commit hashes from git log wp-latest in the scratch repo:

// node e2e.js <changelog-sha> <publish-sha>
const { backportCommitsToBranch } = require( './tools/release/commands/packages.js' );
backportCommitsToBranch(
	'main',
	{ changelogCommit: process.argv[ 2 ], publishCommit: process.argv[ 3 ] },
	{ gitWorkingDirectoryPath: '/tmp/backport-e2e/work', interactive: false }
);

git show origin/main:packages/data/CHANGELOG.md in the scratch repo should show "Landed during publish" under ## Unreleased and only "Shipped fix" under ## 1.1.0 (2026-08-12) — with the old code, both end up under 1.1.0. Rewording an entry in a released section of main before rerunning makes the backport refuse and push nothing.

Use of AI Tools

Implemented with Claude Code (Fable 5), directed and reviewed by @sirreal.

🤖 Generated with Claude Code

The npm release backport cherry-picked the 'Update changelog files' commit
onto trunk. When trunk gained changelog entries during npm publication,
git's textual merge silently filed them under the just-published version
heading, and only conflicted for packages whose '## Unreleased' section
was empty (packages that shipped nothing in the release).

- Recompute every release-touched changelog structurally instead of
  trusting the merge: entries the target branch added since the release
  base stay under '## Unreleased'; everything from the new version
  heading down is taken verbatim from the released changelog. The
  cherry-pick still supplies the package.json changes.
- Before pushing, verify that the released portion of every package
  changelog is byte-identical to the published release, failing loudly
  (including when zero files are found to verify).
- Backport each target branch independently so a failure on one branch
  no longer cancels the other, and reset the working copy on failure so
  one branch's conflict cannot poison the next backport.

Fixes #81506
@sirreal sirreal added [Type] Build Tooling Issues or PRs related to build tooling npm Packages Related to npm packages labels Aug 13, 2026
@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.72 MB

compressed-size-action

- Skip released-changelog verification for packages that have never
  published a release instead of failing; three private packages have
  changelogs with no version heading, which made every finalization
  throw.
- Sync backport target branches to the remote tip with checkout -B and
  reset --hard inside the recovery boundary, instead of pulling: a
  diverged local branch could conflict (poisoning the next branch's
  backport) or silently merge stale local state into the push.

See #81566 (comment)
@github-actions

Copy link
Copy Markdown

Flaky tests detected in d91e227.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/31785231322
📝 Reported tests:

adds and activates a new tab when pressing Enter at the end of a tab label in /test/e2e/specs/editor/blocks/tabs.spec.js, passed after 2 failed attempts.
Error: expect(locator).toHaveCount(expected) failed

Locator:  locator('[name="editor-canvas"]').contentFrame().getByRole('tab')
Expected: 3
Received: 2
Timeout:  5000ms

Call log:
  - Expect "toHaveCount" with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().getByRole('tab')
    14 × locator resolved to 2 elements
       - unexpected value "2"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/tabs.spec.js:146:25
Error: expect(locator).toHaveCount(expected) failed

Locator:  locator('[name="editor-canvas"]').contentFrame().getByRole('tab')
Expected: 3
Received: 2
Timeout:  5000ms

Call log:
  - Expect "toHaveCount" with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().getByRole('tab')
    14 × locator resolved to 2 elements
       - unexpected value "2"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/tabs.spec.js:146:25
two users concurrently move list items (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts, passed after 1 failed attempt.
Error: expect(received).toBeGreaterThan(expected)

Expected: > 2
Received:   1

Call Log:
- Timeout 10000ms exceeded while waiting on the predicate
    at assertMovedOrder (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:646:8)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:650:10

@sirreal
sirreal marked this pull request as ready for review August 14, 2026 09:14
@sirreal
sirreal requested a review from manzoorwanijk as a code owner August 14, 2026 09:14
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sirreal <jonsurrell@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

npm Packages Related to npm packages [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Release: the npm changelog backport can silently attribute unshipped changes to a published version

1 participant