diff --git a/.github/scripts/release-section.mts b/.github/scripts/release-section.mts index ca243614..ef8d1559 100644 --- a/.github/scripts/release-section.mts +++ b/.github/scripts/release-section.mts @@ -449,6 +449,52 @@ export function getNewReleaseEntriesSection({ ].join('\n'); } +/** + * Removes the entries whose owning PRs are all among the given PRs, leaving + * the other entries and the categories that still have one untouched. An entry + * that also owns another PR stays, so that PR is never dropped with it. + * + * @param options - Options. + * @param options.section - A release section. + * @param options.prNumbers - The PRs whose entries are removed. + * @returns The section without those entries; the same text when none match. + */ +export function removeReleaseEntries({ + section, + prNumbers, +}: { + section: string; + prNumbers: ReadonlySet; +}): string { + let removedAny = false; + const categories = parseReleaseSectionCategories(section) + .map(({ heading, entries }) => ({ + heading, + entries: entries.filter(({ lines }) => { + const owners = getOwningPrNumbers(lines[0] ?? ''); + const isRemoved = + owners.length > 0 && owners.every((owner) => prNumbers.has(owner)); + removedAny ||= isRemoved; + return !isRemoved; + }), + })) + .filter(({ entries }) => entries.length > 0); + + if (!removedAny) { + return section; + } + + return [ + splitLines(section)[0] ?? '', + ...categories.flatMap(({ heading, entries }) => [ + '', + heading, + '', + ...entries.flatMap(({ lines }) => lines), + ]), + ].join('\n'); +} + const CATEGORY_BY_LEADING_VERB = new Map([ ['Added', '### Added'], ['Changed', '### Changed'], diff --git a/.github/scripts/tests/release-section.test.mts b/.github/scripts/tests/release-section.test.mts index 184a72e0..e49bcd90 100644 --- a/.github/scripts/tests/release-section.test.mts +++ b/.github/scripts/tests/release-section.test.mts @@ -7,6 +7,7 @@ import { mergeCurrentReleaseSection, mergeNewReleaseEntries, normalizeRepositoryPrLinks, + removeReleaseEntries, replaceReleaseSection, restoreGeneratedCategories, } from '../release-section.mts'; @@ -616,3 +617,57 @@ test('ends the oldest release section before the link references', () => { .replace('Fixed an issue (#101)', 'Added a feature (#102)'), ); }); + +test('removes the entries owning the given PRs and drops emptied categories', () => { + const section = [ + '## [2.0.0]', + '', + '### Added', + '', + '- Added a thing (#1)', + '', + '### Fixed', + '', + '- Fixed one (#2)', + ' more detail', + '- Fixed two (#3)', + ].join('\n'); + + assert.equal( + removeReleaseEntries({ section, prNumbers: new Set(['1', '2']) }), + ['## [2.0.0]', '', '### Fixed', '', '- Fixed two (#3)'].join('\n'), + ); + assert.equal( + removeReleaseEntries({ section, prNumbers: new Set(['1', '2', '3']) }), + '## [2.0.0]', + ); +}); + +test('keeps an entry that owns a PR outside the given PRs', () => { + const section = [ + '## [2.0.0]', + '', + '### Fixed', + '', + '- Fixed from (#1) (#2)', + '- Fixed together (#3, #4)', + ].join('\n'); + + assert.equal( + removeReleaseEntries({ section, prNumbers: new Set(['1', '3']) }), + section, + ); + assert.equal( + removeReleaseEntries({ section, prNumbers: new Set(['3', '4']) }), + ['## [2.0.0]', '', '### Fixed', '', '- Fixed from (#1) (#2)'].join('\n'), + ); +}); + +test('leaves the section untouched when no entry matches', () => { + const section = '## [2.0.0]\n\n### Added\n\n- Added a thing (#1)'; + + assert.equal( + removeReleaseEntries({ section, prNumbers: new Set(['9']) }), + section, + ); +}); diff --git a/.github/scripts/tests/update-release-changelog-reachability.test.mts b/.github/scripts/tests/update-release-changelog-reachability.test.mts new file mode 100644 index 00000000..70dba5ba --- /dev/null +++ b/.github/scripts/tests/update-release-changelog-reachability.test.mts @@ -0,0 +1,59 @@ +import assert from 'node:assert/strict'; +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { afterEach, beforeEach, describe, it, mock } from 'node:test'; + +import { git } from './git-test-environment.mts'; +import { isCommitReachableFrom } from '../update-release-changelog.mts'; + +describe('isCommitReachableFrom', () => { + let directory: string; + let shared: string; + let onlyOnMain: string; + + beforeEach(() => { + directory = mkdtempSync(join(tmpdir(), 'reachability-')); + git(directory, 'init', '-q', '-b', 'main'); + const commit = (file: string): string => { + writeFileSync(join(directory, file), file); + git(directory, 'add', file); + git(directory, 'commit', '-q', '-m', file); + return git(directory, 'rev-parse', 'HEAD'); + }; + shared = commit('shared.txt'); + git(directory, 'branch', 'release'); + onlyOnMain = commit('main-only.txt'); + }); + + afterEach(() => { + mock.restoreAll(); + rmSync(directory, { recursive: true, force: true }); + }); + + it('is true for a commit on the ref and false for one that is not', () => { + assert.equal(isCommitReachableFrom(shared, 'release', directory), true); + assert.equal( + isCommitReachableFrom(onlyOnMain, 'release', directory), + false, + ); + }); + + it('warns and returns false when Git cannot resolve the commit', () => { + const warn = mock.method(console, 'warn', () => undefined); + + assert.equal( + isCommitReachableFrom('f'.repeat(40), 'release', directory), + false, + ); + assert.equal(warn.mock.callCount(), 1); + }); + + it('does not warn for an ordinary non-ancestor', () => { + const warn = mock.method(console, 'warn', () => undefined); + + isCommitReachableFrom(onlyOnMain, 'release', directory); + + assert.equal(warn.mock.callCount(), 0); + }); +}); diff --git a/.github/scripts/tests/update-release-changelog.test.mts b/.github/scripts/tests/update-release-changelog.test.mts index b6929e3d..1e9ac9cf 100644 --- a/.github/scripts/tests/update-release-changelog.test.mts +++ b/.github/scripts/tests/update-release-changelog.test.mts @@ -6,6 +6,8 @@ import test from 'node:test'; import { assertReleaseSectionHasEntries, + excludePrsCherryPickedOntoBaseline, + findPrsMissingFromChangelog, findReleaseVersionsContainingPrs, getAutoChangelogCli, getAcceptedPrCommits, @@ -13,7 +15,11 @@ import { getChangelogPushArguments, getDeletedPrNumbers, getChangelogPrPresentation, + getCherryPickAliasesByPr, + getCherryPickedPrsByCommit, getHistoricalSkippedPrNumbers, + getPrsCherryPickedOntoBaseline, + getUnlistedCherryPicksWarning, isReleaseSectionEmpty, hasOnlyUpdaterCommits, isUntouchedUnproofreadChangelogPr, @@ -585,3 +591,176 @@ test('rejects generated sections with missing or duplicate PR references', () => ), ); }); + +test('collects the canonical PR of each accepted cherry-pick commit', () => { + assert.deepEqual( + [ + ...getCherryPickedPrsByCommit(`[auto-changelog] commit=${COMMIT_A} accepted source-pr=1 canonical-pr=1 cherry-pick=false +[auto-changelog] commit=${COMMIT_B} accepted source-pr=7 canonical-pr=1 cherry-pick=true +[auto-changelog] commit=${COMMIT_C} accepted source-pr=none canonical-pr=none cherry-pick=true`), + ], + [[COMMIT_B, '1']], + ); +}); + +test('finds the PRs cherry-picked onto the baseline branch', () => { + const cherryPickedPrsByCommit = new Map([ + [COMMIT_A, '1'], + [COMMIT_B, '2'], + ]); + + assert.deepEqual( + getPrsCherryPickedOntoBaseline({ + cherryPickedPrsByCommit, + baselineRef: 'origin/release/1.0.0', + isAncestor: (commit, ref) => + commit === COMMIT_A && ref === 'origin/release/1.0.0', + }), + new Set(['1']), + ); + assert.deepEqual( + getPrsCherryPickedOntoBaseline({ + cherryPickedPrsByCommit, + baselineRef: 'origin/stable', + isAncestor: () => false, + }), + new Set(), + ); +}); + +test('maps each canonical PR to its cherry-pick PR numbers', () => { + assert.deepEqual( + [ + ...getCherryPickAliasesByPr(`[auto-changelog] commit=${COMMIT_A} accepted source-pr=1 canonical-pr=1 cherry-pick=false +[auto-changelog] commit=${COMMIT_B} accepted source-pr=7 canonical-pr=1 cherry-pick=true +[auto-changelog] commit=${COMMIT_C} accepted source-pr=8 canonical-pr=1 cherry-pick=true`), + ], + [['1', ['7', '8']]], + ); +}); + +test('reports PRs that no other section lists under any of their numbers', () => { + const changelog = [ + '## [2.0.0]', + '', + '### Fixed', + '', + '- Fixed one (#1)', + '', + '## [1.0.0]', + '', + '### Fixed', + '', + '- Fixed two (#2)', + '- Fixed three by its cherry-pick (#31)', + '', + ].join('\n'); + + assert.deepEqual( + findPrsMissingFromChangelog({ + changelog, + prNumbers: ['1', '2', '3', '4'], + aliasesByPr: new Map([['3', ['31']]]), + version: '2.0.0', + repositoryUrl: 'https://github.com/MetaMask/example', + }), + ['1', '4'], + ); +}); + +test('words the warning for PRs the earlier changelog lacks', () => { + assert.equal( + getUnlistedCherryPicksWarning('13.56.0', { + baselineVersion: '13.55.0', + prNumbers: ['47395', '47400'], + }), + '> #47395, #47400 were left out of 13.56.0 because their cherry-picks are already on the 13.55.0 branch, but the 13.55.0 changelog does not list them. Add an entry to the right release if one is needed.', + ); + assert.equal( + getUnlistedCherryPicksWarning('13.56.0', { + baselineVersion: '13.55.0', + prNumbers: ['47395'], + }), + '> #47395 was left out of 13.56.0 because its cherry-pick is already on the 13.55.0 branch, but the 13.55.0 changelog does not list it. Add an entry to the right release if one is needed.', + ); +}); + +const EXCLUSION_SECTION = [ + '## [2.0.0]', + '', + '### Fixed', + '', + '- Fixed one (#1)', + '- Fixed two (#2)', + '- Fixed three (#3, #7)', + '- Fixed the regression from (#4) (#5)', + '', +].join('\n'); + +test('excludes the entries of PRs already on the baseline branch', () => { + const result = excludePrsCherryPickedOntoBaseline({ + section: EXCLUSION_SECTION, + shippedEarlier: new Set(['1', '3']), + aliasesByPr: new Map([['3', ['7']]]), + reviewedPrNumbers: new Set(), + }); + + assert.deepEqual(result.excludedPrNumbers, ['1', '3']); + assert.equal( + result.section, + [ + '## [2.0.0]', + '', + '### Fixed', + '', + '- Fixed two (#2)', + '- Fixed the regression from (#4) (#5)', + ].join('\n'), + ); +}); + +test('keeps an entry that also owns a PR that is not excluded', () => { + const result = excludePrsCherryPickedOntoBaseline({ + section: EXCLUSION_SECTION, + shippedEarlier: new Set(['4']), + aliasesByPr: new Map(), + reviewedPrNumbers: new Set(), + }); + + assert.equal(result.section, EXCLUSION_SECTION); + assert.deepEqual(result.excludedPrNumbers, []); +}); + +test('does not report PRs a reviewer already approved in the section', () => { + const result = excludePrsCherryPickedOntoBaseline({ + section: EXCLUSION_SECTION, + shippedEarlier: new Set(['1', '2']), + aliasesByPr: new Map(), + reviewedPrNumbers: new Set(['1']), + }); + + assert.deepEqual(result.excludedPrNumbers, ['2']); +}); + +test('does not report excluded PRs that the section never listed', () => { + const result = excludePrsCherryPickedOntoBaseline({ + section: EXCLUSION_SECTION, + shippedEarlier: new Set(['99']), + aliasesByPr: new Map(), + reviewedPrNumbers: new Set(), + }); + + assert.equal(result.section, EXCLUSION_SECTION); + assert.deepEqual(result.excludedPrNumbers, []); +}); + +test('adds the unlisted cherry-pick warning to the PR body', () => { + const { body } = getChangelogPrPresentation({ + version: '2.0.0', + changelogBranch: 'release-changelog/2.0.0', + proofreadingStatus: 'succeeded', + unlistedCherryPicks: { baselineVersion: '1.0.0', prNumbers: ['5'] }, + }); + + assert.match(body, /#5 was left out of 2\.0\.0/u); +}); diff --git a/.github/scripts/update-release-changelog.mts b/.github/scripts/update-release-changelog.mts index f10547df..53a8dc45 100644 --- a/.github/scripts/update-release-changelog.mts +++ b/.github/scripts/update-release-changelog.mts @@ -23,6 +23,7 @@ import { mergeNewReleaseEntries, normalizeRepositoryPrLinks, parseReleaseHeadingVersion, + removeReleaseEntries, replaceReleaseSection, restoreGeneratedCategories, splitLines, @@ -49,6 +50,11 @@ type ChangelogPrPresentation = { body: string; }; +type UnlistedCherryPicks = { + baselineVersion: string; + prNumbers: readonly string[]; +}; + const SCRIPT_DIRECTORY = dirname(fileURLToPath(import.meta.url)); const CLEANER_PATH = resolve(SCRIPT_DIRECTORY, 'clean-release-changelog.mts'); const PROMPT_PATH = resolve( @@ -547,6 +553,208 @@ export function getAcceptedPrCommits( return commitsByPr; } +/** + * Extracts the canonical PR of each cherry-pick commit the generator accepted. + * + * @param diagnostics - The generator's verbose standard error. + * @returns The canonical PR number by cherry-pick commit SHA. + */ +export function getCherryPickedPrsByCommit( + diagnostics: string, +): Map { + return new Map( + [ + ...diagnostics.matchAll( + /\[auto-changelog\] commit=([0-9a-f]{40}) accepted source-pr=\S+ canonical-pr=(\d+) cherry-pick=true/gu, + ), + ].flatMap(([, commit, prNumber]) => + commit && prNumber ? [[commit, prNumber] as const] : [], + ), + ); +} + +/** + * Reports whether a commit is reachable from a ref. A Git failure counts as + * not reachable, which keeps the PR listed rather than dropping it. + * + * @param commit - The commit SHA. + * @param ref - The ref to search from. + * @param cwd - The repository directory. + * @returns True when the commit is an ancestor of the ref. + */ +export function isCommitReachableFrom( + commit: string, + ref: string, + cwd: string = process.cwd(), +): boolean { + const { status, stderr } = spawnSync( + 'git', + ['merge-base', '--is-ancestor', commit, ref], + { cwd, encoding: 'utf8', env: deterministicEnvironment }, + ); + // Status 1 is the ordinary "not an ancestor"; anything else is a failure. + if (status !== 0 && status !== 1) { + console.warn( + `Could not tell whether ${commit} is reachable from ${ref}: ${String(stderr ?? '').trim()}`, + ); + } + return status === 0; +} + +/** + * Finds the PRs already cherry-picked onto the baseline's branch. They ship in + * that earlier release, so the merged-in cherry-pick and the original PR must + * not be listed again, whether or not the earlier changelog says so yet. + * + * @param options0 - The options. + * @param options0.cherryPickedPrsByCommit - The canonical PR of each + * cherry-pick commit in the generator's range. + * @param options0.baselineRef - The baseline ref. + * @param options0.isAncestor - Reports whether a commit is reachable from the + * baseline ref; replaceable in tests. + * @returns The PR numbers. + */ +export function getPrsCherryPickedOntoBaseline({ + cherryPickedPrsByCommit, + baselineRef, + isAncestor = isCommitReachableFrom, +}: { + cherryPickedPrsByCommit: ReadonlyMap; + baselineRef: string; + isAncestor?: (commit: string, ref: string) => boolean; +}): Set { + return new Set( + [...cherryPickedPrsByCommit].flatMap(([commit, prNumber]) => + isAncestor(commit, baselineRef) ? [prNumber] : [], + ), + ); +} + +/** + * Maps each canonical PR to the cherry-pick PR numbers the generator saw for it. + * + * @param diagnostics - The generator's verbose standard error. + * @returns The cherry-pick PR numbers by canonical PR number. + */ +export function getCherryPickAliasesByPr( + diagnostics: string, +): Map { + const aliasesByPr = new Map(); + for (const [, sourcePr = '', canonicalPr = ''] of diagnostics.matchAll( + /\[auto-changelog\] commit=[0-9a-f]{40} accepted source-pr=(\d+) canonical-pr=(\d+) cherry-pick=true/gu, + )) { + aliasesByPr.set(canonicalPr, [ + ...(aliasesByPr.get(canonicalPr) ?? []), + sourcePr, + ]); + } + return aliasesByPr; +} + +/** + * Finds the PRs that no other release section lists, under their own number or + * a cherry-pick's. + * + * @param options0 - The options. + * @param options0.changelog - The full changelog text. + * @param options0.prNumbers - The PRs to check. + * @param options0.aliasesByPr - The cherry-pick PR numbers by canonical PR. + * @param options0.version - The version whose section is ignored. + * @param options0.repositoryUrl - The repository's GitHub URL. + * @returns The PR numbers that are not listed anywhere else. + */ +export function findPrsMissingFromChangelog({ + changelog, + prNumbers, + aliasesByPr, + version, + repositoryUrl, +}: { + changelog: string; + prNumbers: readonly string[]; + aliasesByPr: ReadonlyMap; + version: string; + repositoryUrl: string; +}): string[] { + return prNumbers.filter( + (prNumber) => + findReleaseVersionsContainingPrs( + changelog, + [prNumber, ...(aliasesByPr.get(prNumber) ?? [])], + version, + repositoryUrl, + ).length === 0, + ); +} + +/** + * Removes the entries of PRs already cherry-picked onto the baseline's branch. + * An entry is removed only when all its PRs are among them. + * + * @param options0 - The options. + * @param options0.section - The current release section. + * @param options0.shippedEarlier - The canonical PRs on the baseline's branch. + * @param options0.aliasesByPr - The cherry-pick PR numbers by canonical PR. + * @param options0.reviewedPrNumbers - The PRs a reviewer already approved in + * the section; the updater restores those entries, so they do not count. + * @returns The section, and the PRs this removed that nothing restores. + */ +export function excludePrsCherryPickedOntoBaseline({ + section, + shippedEarlier, + aliasesByPr, + reviewedPrNumbers, +}: { + section: string; + shippedEarlier: ReadonlySet; + aliasesByPr: ReadonlyMap; + reviewedPrNumbers: ReadonlySet; +}): { section: string; excludedPrNumbers: string[] } { + const numbersByPr = new Map( + [...shippedEarlier].map((prNumber) => [ + prNumber, + [prNumber, ...(aliasesByPr.get(prNumber) ?? [])], + ]), + ); + const updatedSection = removeReleaseEntries({ + section, + prNumbers: new Set([...numbersByPr.values()].flat()), + }); + const before = new Set(getPrNumbers(section)); + const after = new Set(getPrNumbers(updatedSection)); + const excludedPrNumbers = [...numbersByPr] + .filter( + ([, numbers]) => + numbers.some((number) => before.has(number)) && + !numbers.some( + (number) => after.has(number) || reviewedPrNumbers.has(number), + ), + ) + .map(([prNumber]) => prNumber); + return { section: updatedSection, excludedPrNumbers }; +} + +/** + * Builds the PR warning for PRs left out because an earlier release's branch + * has them, when that release's changelog does not list them. + * + * @param version - The version being released. + * @param unlistedCherryPicks - The earlier release and the PRs it lacks. + * @returns The warning as a Markdown quote. + */ +export function getUnlistedCherryPicksWarning( + version: string, + unlistedCherryPicks: UnlistedCherryPicks, +): string { + const { baselineVersion, prNumbers } = unlistedCherryPicks; + const list = prNumbers.map((prNumber) => `#${prNumber}`).join(', '); + const [was, cherryPicks, pronoun] = + prNumbers.length === 1 + ? ['was', 'its cherry-pick is', 'it'] + : ['were', 'their cherry-picks are', 'them']; + return `> ${list} ${was} left out of ${version} because ${cherryPicks} already on the ${baselineVersion} branch, but the ${baselineVersion} changelog does not list ${pronoun}. Add an entry to the right release if one is needed.`; +} + /** * Finds the other released versions whose sections mention any of the PRs. * @@ -606,7 +814,9 @@ export function isReleaseSectionEmpty( * @param options0.repositoryUrl - The GitHub repository URL. * @param options0.version - The version being released. * @returns The PR numbers the generator skipped because an earlier release - * lists them, and the commits it accepted for each PR. + * lists them, the commits it accepted for each PR, and the canonical PR of + * each cherry-pick commit, plus the cherry-pick PR numbers of each canonical + * PR. */ function generateChangelog({ repositoryUrl, @@ -617,6 +827,8 @@ function generateChangelog({ }): { skippedPrNumbers: string[]; acceptedCommitsByPr: Map; + cherryPickedPrsByCommit: Map; + cherryPickAliasesByPr: Map; } { const commonArguments = [ 'update', @@ -640,6 +852,8 @@ function generateChangelog({ return { skippedPrNumbers: getHistoricalSkippedPrNumbers(diagnostics), acceptedCommitsByPr: getAcceptedPrCommits(diagnostics), + cherryPickedPrsByCommit: getCherryPickedPrsByCommit(diagnostics), + cherryPickAliasesByPr: getCherryPickAliasesByPr(diagnostics), }; } @@ -1086,6 +1300,8 @@ export function getDeletedPrNumbers({ * @param options0.proofreadingStage - The stage that failed, if any. * @param options0.presentInVersions - The earlier versions that already list the * cherry-picked PRs. + * @param options0.unlistedCherryPicks - PRs left out of this release that the + * earlier release's changelog does not list. * @returns The PR title and body. */ export function getChangelogPrPresentation({ @@ -1094,12 +1310,14 @@ export function getChangelogPrPresentation({ proofreadingStatus, proofreadingStage, presentInVersions = [], + unlistedCherryPicks, }: { version: string; changelogBranch: string; proofreadingStatus: ProofreadingStatus; proofreadingStage?: string; presentInVersions?: readonly string[]; + unlistedCherryPicks?: UnlistedCherryPicks; }): ChangelogPrPresentation { let title = `release: ${changelogBranch}`; let body = `This PR updates the change log for ${version}.`; @@ -1111,6 +1329,9 @@ export function getChangelogPrPresentation({ title = `${title} (no new PRs, manual edit required)`; body = `${body}\n\n${getNoNewPrsWarning(version, presentInVersions)}`; } + if (unlistedCherryPicks) { + body = `${body}\n\n${getUnlistedCherryPicksWarning(version, unlistedCherryPicks)}`; + } return { title, body }; } @@ -1305,6 +1526,8 @@ function createOrUpdateChangelogPr({ * section was generated and its proofreading failed. * @param options0.generatedThrough - The release tip the commit was generated * from. + * @param options0.unlistedCherryPicks - PRs left out of this release that the + * earlier release's changelog does not list. * @param options0.assertSourcesUnchanged - Throws when a source ref moved during * the run. */ @@ -1317,6 +1540,7 @@ function commitAndPushChangelog({ replacesWholeSection, markUnproofread, generatedThrough, + unlistedCherryPicks, assertSourcesUnchanged, }: { version: string; @@ -1327,6 +1551,7 @@ function commitAndPushChangelog({ replacesWholeSection: boolean; markUnproofread: boolean; generatedThrough: string; + unlistedCherryPicks?: UnlistedCherryPicks; assertSourcesUnchanged: () => void; }): void { const unexpectedChanges = capture('git', [ @@ -1392,6 +1617,7 @@ function commitAndPushChangelog({ ...(proofreading.presentInVersions ? { presentInVersions: proofreading.presentInVersions } : {}), + ...(unlistedCherryPicks ? { unlistedCherryPicks } : {}), }), }); } @@ -1541,10 +1767,60 @@ function main(): void { ); } console.log(`Generating changelog for ${platform} ${version}.`); - const { skippedPrNumbers, acceptedCommitsByPr } = generateChangelog({ - repositoryUrl, - version, - }); + const { + skippedPrNumbers, + acceptedCommitsByPr, + cherryPickedPrsByCommit, + cherryPickAliasesByPr, + } = generateChangelog({ repositoryUrl, version }); + + // The target's own cherry-picks are reachable from the target, not from an + // earlier baseline. + let unlistedCherryPicks: UnlistedCherryPicks | undefined; + if (baseline.kind !== 'target') { + const shippedEarlier = getPrsCherryPickedOntoBaseline({ + cherryPickedPrsByCommit, + baselineRef: baseline.ref, + }); + if (shippedEarlier.size > 0) { + const { section, excludedPrNumbers } = excludePrsCherryPickedOntoBaseline( + { + section: readCurrentReleaseSection(), + shippedEarlier, + aliasesByPr: cherryPickAliasesByPr, + reviewedPrNumbers: new Set( + getPrNumbers(preservedReviewedSection ?? ''), + ), + }, + ); + writeCurrentReleaseSection(section); + + if (excludedPrNumbers.length > 0) { + console.log( + `Excluding PRs already cherry-picked onto ${baseline.ref}: ${excludedPrNumbers.join(', ')}`, + ); + skippedPrNumbers.push(...excludedPrNumbers); + + // A PR whose earlier changelog never listed it would vanish from both. + const missingPrNumbers = findPrsMissingFromChangelog({ + changelog: readChangelog(), + prNumbers: excludedPrNumbers, + aliasesByPr: cherryPickAliasesByPr, + version, + repositoryUrl, + }); + if (missingPrNumbers.length > 0) { + console.warn( + `PRs left out of ${version} but missing from the ${baseline.version} changelog: ${missingPrNumbers.join(', ')}`, + ); + unlistedCherryPicks = { + baselineVersion: baseline.version, + prNumbers: missingPrNumbers, + }; + } + } + } + } // Lines already on the release branch, or reviewed in the open changelog PR, // are never reworded; only newly generated PRs go to the proofreader. @@ -1664,6 +1940,7 @@ function main(): void { markUnproofread: proofreading.status === 'failed' && !preservedReviewedSection, generatedThrough: targetReleaseSha, + ...(unlistedCherryPicks ? { unlistedCherryPicks } : {}), assertSourcesUnchanged, }); } diff --git a/.github/scripts/update-release-changelog.sh b/.github/scripts/update-release-changelog.sh old mode 100644 new mode 100755 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cc07802..bd34b845 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Leave PRs already cherry-picked onto the baseline release out of the generated section in `update-release-changelog` ([#307](https://github.com/MetaMask/github-tools/pull/307)) + - While the new release has no section of its own on the release branch, a PR whose cherry-pick is already on the older release's branch is not listed again, even if the older changelog is stale. + - Entries a reviewer already approved in the open changelog PR are kept, and an entry that also lists another PR is kept. + - The log and the changelog PR body warn about any left-out PR that the older release's changelog does not list. +- Restore the executable bit on `.github/scripts/update-release-changelog.sh`, which #303 dropped ([#307](https://github.com/MetaMask/github-tools/pull/307)) + ## [1.22.0] ### Added