Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/funny-insects-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ implements the described behavior.

[badge:license:Apache2]: <https://img.shields.io/badge/license-Apache_2.0-informational?style=for-the-badge>

[badge:engine:nodejs]: <https://img.shields.io/badge/Node.js-20-informational?style=for-the-badge&logo=node.js&logoColor=white>
[badge:engine:nodejs]: <https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FCoreMedia%2Fckeditor-plugins%2Fmain%2Fpackage.json&query=%24.engines.node&label=Node.js&color=informational&style=for-the-badge&logo=node.js&logoColor=white>

[badge:engine:pnpm]: <https://img.shields.io/badge/pnpm-8.6.9-informational?style=for-the-badge&logo=pnpm&logoColor=white>
[badge:engine:pnpm]: <https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FCoreMedia%2Fckeditor-plugins%2Fmain%2Fpackage.json&query=%24.engines.pnpm&label=pnpm&color=informational&style=for-the-badge&logo=pnpm&logoColor=white>

[badge:lang:typescript]: <https://img.shields.io/badge/TypeScript-5.3.3-informational?style=for-the-badge&logo=typescript&logoColor=white>
[badge:lang:typescript]: <https://img.shields.io/badge/dynamic/yaml?url=https%3A%2F%2Fraw.githubusercontent.com%2FCoreMedia%2Fckeditor-plugins%2Fmain%2Fpnpm-workspace.yaml&query=%24.catalog.typescript&label=TypeScript&color=informational&style=for-the-badge&logo=typescript&logoColor=white>

[badge:ckeditor]: <https://img.shields.io/badge/CKEditor-41.1.0-informational?style=for-the-badge&logo=ckeditor5&logoColor=white>
[badge:ckeditor]: <https://img.shields.io/badge/dynamic/yaml?url=https%3A%2F%2Fraw.githubusercontent.com%2FCoreMedia%2Fckeditor-plugins%2Fmain%2Fpnpm-workspace.yaml&query=%24.catalog.ckeditor5&label=CKEditor&color=informational&style=for-the-badge&logo=ckeditor5&logoColor=white>

[CKEditor 4]: <https://ckeditor.com/ckeditor-4/> "CKEditor 4 | Visual Text Editor for HTML"

Expand Down
75 changes: 40 additions & 35 deletions scripts/release-notes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Assembles the notes of the single GitHub release `vX.Y.Z` from the `## X.Y.Z`
* sections of all package changelogs written by Changesets.
*
* Packages whose section only lists dependency updates are skipped: in the fixed
* versioning group every package is bumped, but most of them without own changes.
* Entries are grouped by change type and deduplicated by changeset hash because a
* changeset affecting multiple packages appears in each package's changelog.
*
* Usage: node scripts/release-notes.mjs <version> [packages-dir]
*/
Expand Down Expand Up @@ -37,56 +37,61 @@ const isDependencyUpdate = (entry) =>
/^- Updated dependencies\b/.test(entry[0]) ||
entry.filter((line) => line.trim() !== "").every((line) => /^\s*- \S+@\d\S*$/.test(line));

/**
* Removes dependency update entries (including their nested list) and drops `###`
* subsections that end up empty.
*/
const withoutDependencyUpdates = (section) => {
const subsections = [];
let current = { heading: undefined, entries: [] };
const changeTypes = ["Major", "Minor", "Patch"];
const entriesByChangeType = Object.fromEntries(changeTypes.map((type) => [type, []]));
const seenChangesetHashes = new Set();

const collectChangeEntries = (section) => {
let changeType;
let currentEntry;
const flushEntry = () => {
if (!currentEntry) {
return;
}
if (!isDependencyUpdate(currentEntry)) {
const hash = currentEntry[0].match(/^- ([a-f0-9]{7,40}):/i)?.[1].toLowerCase();
if (!hash || !seenChangesetHashes.has(hash)) {
entriesByChangeType[changeType].push(currentEntry.join("\n").trimEnd());
if (hash) {
seenChangesetHashes.add(hash);
}
}
}
currentEntry = undefined;
};

for (const line of section.split("\n")) {
if (/^###\s/.test(line)) {
subsections.push(current);
current = { heading: line, entries: [] };
} else if (/^- /.test(line)) {
current.entries.push([line]);
} else if (current.entries.length > 0) {
current.entries.at(-1).push(line);
flushEntry();
const heading = line.match(/^### (Major|Minor|Patch) Changes$/);
changeType = heading?.[1];
} else if (changeType && /^- /.test(line)) {
flushEntry();
currentEntry = [line];
} else if (currentEntry) {
currentEntry.push(line);
}
}
subsections.push(current);

return subsections
.map(({ heading, entries }) => ({
heading,
entries: entries
.filter((entry) => !isDependencyUpdate(entry))
.map((entry) => entry.join("\n").trimEnd()),
}))
.filter(({ entries }) => entries.length > 0)
.map(({ heading, entries }) => [heading, entries.join("\n\n")].filter(Boolean).join("\n\n"))
.join("\n\n");
flushEntry();
};

const directories = (await readdir(packagesDir, { withFileTypes: true }))
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
.sort();

const sections = [];
for (const directory of directories) {
let changelog;
try {
changelog = await readFile(path.join(packagesDir, directory, "CHANGELOG.md"), "utf8");
} catch {
continue;
}
const notes = withoutDependencyUpdates(extractSection(changelog, version));
if (notes) {
sections.push(notes);
}
collectChangeEntries(extractSection(changelog, version));
}

process.stdout.write(
sections.length > 0 ? `${sections.join("\n\n")}\n` : "No changes besides dependency updates.\n",
);
const sections = changeTypes
.filter((type) => entriesByChangeType[type].length > 0)
.map((type) => `### ${type} Changes\n\n${entriesByChangeType[type].join("\n\n")}`);

process.stdout.write(sections.length > 0 ? `${sections.join("\n\n")}\n` : "No changes besides dependency updates.\n");
Loading