Skip to content

Commit

Permalink
ci: adjust release page generation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelfaith committed Jan 25, 2025
1 parent 62f5813 commit 42d71da
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ runs:
- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: "18"
node-version: "22"
- run: pnpm install --frozen-lockfile
shell: bash
using: composite
84 changes: 57 additions & 27 deletions .release-it.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
{
"git": {
"commitMessage": "chore: release v${version}",
"requireCommits": true
module.exports = {
git: {
commitMessage: "chore: release v${version}",
requireCommits: true,
},
"github": {
"autoGenerate": true,
"release": true,
"releaseName": "v${version}"
github: {
release: true,
releaseName: "v${version}",
releaseNotes(context) {
const groupTitles = {
feat: "Features",
fix: "Bug Fixes",
perf: "Performance Improvements",
};
const commits = context.changelog.split("\n").slice(1);
const groups = Object.groupBy(commits, (commit) => {
// If it matches one of the types we care to show, then add the
// commit to that group.
for (const type in groupTitles) {
const regex = new RegExp(`^\s*[-*]?\s*${type}[(:]`);
if (regex.test(commit)) {
return type;
}
}

// If it didn't match any of the important groups, then add it to other
return "other";
});

// Use the data we've collected to build the release notes.
const releaseNotes = [];
for (const type in groupTitles) {
if (groups[type]) {
releaseNotes.push(`### ${groupTitles[type]}`);
releaseNotes.push(...groups[type]);
}
}
return releaseNotes.join("\n");
},
},
"npm": { "publishArgs": ["--access public", "--provenance"] },
"plugins": {
npm: { publishArgs: ["--access public", "--provenance"] },
plugins: {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"preset": "angular",
"types": [
{ "section": "Features", "type": "feat" },
{ "section": "Bug Fixes", "type": "fix" },
{ "section": "Performance Improvements", "type": "perf" },
{ "hidden": true, "type": "build" },
{ "hidden": true, "type": "chore" },
{ "hidden": true, "type": "ci" },
{ "hidden": true, "type": "docs" },
{ "hidden": true, "type": "refactor" },
{ "hidden": true, "type": "style" },
{ "hidden": true, "type": "test" }
]
}
}
}
infile: "CHANGELOG.md",
preset: "angular",
types: [
{ section: "Features", type: "feat" },
{ section: "Bug Fixes", type: "fix" },
{ section: "Performance Improvements", type: "perf" },
{ hidden: true, type: "build" },
{ hidden: true, type: "chore" },
{ hidden: true, type: "ci" },
{ hidden: true, type: "docs" },
{ hidden: true, type: "refactor" },
{ hidden: true, type: "style" },
{ hidden: true, type: "test" },
],
},
},
};
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = tseslint.config(
"lib",
"node_modules",
"pnpm-lock.yaml",
".release-it.js",
],
},
{ linterOptions: { reportUnusedDisableDirectives: "error" } },
Expand Down

0 comments on commit 42d71da

Please sign in to comment.