Skip to content

Commit 42d71da

Browse files
committed
ci: adjust release page generation
This change is a POC to address JoshuaKGoldberg/create-typescript-app#1913. Since it's not something we can really test locally, I figured we test it out here, and then, if successful, I can make the updates upstream. Here we've changed the release-it config from json to js, which allows us to create a custom function for `github.releaseNotes`. Using the context provided by release-it, we can filter by groups that we want to keep, and organize them into the same groups that we're organizing for the CHANGELOG (via conventional-changelog). I updated the prepare action to use node 22, which will allow us to use the `Object.groupBy` api (introduced in v21). Since 22 is now LTS, this felt like a reasonable change.
1 parent 62f5813 commit 42d71da

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

.github/actions/prepare/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ runs:
88
- uses: actions/setup-node@v4
99
with:
1010
cache: pnpm
11-
node-version: "18"
11+
node-version: "22"
1212
- run: pnpm install --frozen-lockfile
1313
shell: bash
1414
using: composite

.release-it.js

+57-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,60 @@
1-
{
2-
"git": {
3-
"commitMessage": "chore: release v${version}",
4-
"requireCommits": true
1+
module.exports = {
2+
git: {
3+
commitMessage: "chore: release v${version}",
4+
requireCommits: true,
55
},
6-
"github": {
7-
"autoGenerate": true,
8-
"release": true,
9-
"releaseName": "v${version}"
6+
github: {
7+
release: true,
8+
releaseName: "v${version}",
9+
releaseNotes(context) {
10+
const groupTitles = {
11+
feat: "Features",
12+
fix: "Bug Fixes",
13+
perf: "Performance Improvements",
14+
};
15+
const commits = context.changelog.split("\n").slice(1);
16+
const groups = Object.groupBy(commits, (commit) => {
17+
// If it matches one of the types we care to show, then add the
18+
// commit to that group.
19+
for (const type in groupTitles) {
20+
const regex = new RegExp(`^\s*[-*]?\s*${type}[(:]`);
21+
if (regex.test(commit)) {
22+
return type;
23+
}
24+
}
25+
26+
// If it didn't match any of the important groups, then add it to other
27+
return "other";
28+
});
29+
30+
// Use the data we've collected to build the release notes.
31+
const releaseNotes = [];
32+
for (const type in groupTitles) {
33+
if (groups[type]) {
34+
releaseNotes.push(`### ${groupTitles[type]}`);
35+
releaseNotes.push(...groups[type]);
36+
}
37+
}
38+
return releaseNotes.join("\n");
39+
},
1040
},
11-
"npm": { "publishArgs": ["--access public", "--provenance"] },
12-
"plugins": {
41+
npm: { publishArgs: ["--access public", "--provenance"] },
42+
plugins: {
1343
"@release-it/conventional-changelog": {
14-
"infile": "CHANGELOG.md",
15-
"preset": "angular",
16-
"types": [
17-
{ "section": "Features", "type": "feat" },
18-
{ "section": "Bug Fixes", "type": "fix" },
19-
{ "section": "Performance Improvements", "type": "perf" },
20-
{ "hidden": true, "type": "build" },
21-
{ "hidden": true, "type": "chore" },
22-
{ "hidden": true, "type": "ci" },
23-
{ "hidden": true, "type": "docs" },
24-
{ "hidden": true, "type": "refactor" },
25-
{ "hidden": true, "type": "style" },
26-
{ "hidden": true, "type": "test" }
27-
]
28-
}
29-
}
30-
}
44+
infile: "CHANGELOG.md",
45+
preset: "angular",
46+
types: [
47+
{ section: "Features", type: "feat" },
48+
{ section: "Bug Fixes", type: "fix" },
49+
{ section: "Performance Improvements", type: "perf" },
50+
{ hidden: true, type: "build" },
51+
{ hidden: true, type: "chore" },
52+
{ hidden: true, type: "ci" },
53+
{ hidden: true, type: "docs" },
54+
{ hidden: true, type: "refactor" },
55+
{ hidden: true, type: "style" },
56+
{ hidden: true, type: "test" },
57+
],
58+
},
59+
},
60+
};

eslint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = tseslint.config(
1919
"lib",
2020
"node_modules",
2121
"pnpm-lock.yaml",
22+
".release-it.js",
2223
],
2324
},
2425
{ linterOptions: { reportUnusedDisableDirectives: "error" } },

0 commit comments

Comments
 (0)