diff --git a/scripts/release-notes.cjs b/scripts/release-notes.cjs index 3dd7771..721c905 100644 --- a/scripts/release-notes.cjs +++ b/scripts/release-notes.cjs @@ -6,19 +6,28 @@ function readReleaseNotes(root = path.resolve(__dirname, '..')) { } function validateReleaseNotes(notes, version) { + const visibleNotes = notes.replace(//g, '').trim(); const failures = []; const expectedHeading = '## Changes in `v' + version + ':`'; - const firstHeadingIndex = notes.indexOf('## Changes in `v'); + const firstHeadingIndex = visibleNotes.indexOf('## Changes in `v'); const firstHeadingEnd = - firstHeadingIndex < 0 ? notes.length : notes.indexOf('\n## Changes in `v', firstHeadingIndex + 1); + firstHeadingIndex < 0 + ? visibleNotes.length + : visibleNotes.indexOf('\n## Changes in `v', firstHeadingIndex + 1); const currentRelease = firstHeadingIndex < 0 ? '' - : notes.slice(firstHeadingIndex, firstHeadingEnd < 0 ? notes.length : firstHeadingEnd); - const preamble = notes.slice(0, firstHeadingIndex < 0 ? notes.length : firstHeadingIndex); + : visibleNotes.slice( + firstHeadingIndex, + firstHeadingEnd < 0 ? visibleNotes.length : firstHeadingEnd, + ); + const preamble = visibleNotes.slice( + 0, + firstHeadingIndex < 0 ? visibleNotes.length : firstHeadingIndex, + ); const isPrerelease = version.includes('beta') || version.includes('alpha'); - if (!notes.startsWith('> [!')) { + if (!visibleNotes.startsWith('> [!')) { failures.push('CHANGELOG.md must begin with a release notice'); } if (!currentRelease.startsWith(expectedHeading)) { diff --git a/scripts/release-notes.test.cjs b/scripts/release-notes.test.cjs index dc2d994..f0df1f4 100644 --- a/scripts/release-notes.test.cjs +++ b/scripts/release-notes.test.cjs @@ -35,6 +35,15 @@ test('rejects a beta banner for stable release notes', () => { assert.equal(failures.some((failure) => failure.includes('beta-build banner')), true); }); +test('ignores a historical beta banner inside an HTML comment', () => { + const notes = [ + '', + notesFor('0.12.0', '> [!IMPORTANT]\n> Stable release'), + ].join('\n'); + assert.deepEqual(validateReleaseNotes(notes, '0.12.0'), []); +}); + test('requires the one-time v0.11.0 recovery advisory in v0.11.1 notes', () => { const failures = validateReleaseNotes(notesFor('0.11.1'), '0.11.1'); assert.equal(failures.some((failure) => failure.includes('manual-upgrade advisory')), true);