Skip to content

Commit ed46cee

Browse files
committed
Generate changelogs per release
1 parent bbb7a40 commit ed46cee

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

deploy/deployChangedPackages.mjs

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import fetch from "node-fetch";
1212
import { spawnSync } from "child_process";
1313
import { Octokit } from "@octokit/core";
1414
import printDiff from "print-diff";
15+
import { generateChangelogFrom } from "../lib/changelog.js";
1516

1617
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1718
// @ts-ignore
@@ -44,6 +45,9 @@ const go = async () => {
4445
.readdirSync(join(generatedDir, dirName))
4546
.filter((f) => f.endsWith(".d.ts"));
4647

48+
/** @type {string[]} */
49+
let releaseNotes = [];
50+
4751
// Look through each .d.ts file included in a package to
4852
// determine if anything has changed
4953
let upload = false;
@@ -57,6 +61,11 @@ const go = async () => {
5761
console.log(`Comparing ${file} from unpkg, to generated version:`);
5862
printDiff(npmDTSText, generatedDTSContent);
5963

64+
const title = `\n## \`${file}\`\n`;
65+
const notes = generateChangelogFrom(npmDTSText, generatedDTSContent);
66+
releaseNotes.push(title);
67+
releaseNotes.push(notes.trim() === "" ? "No changes" : notes);
68+
6069
upload = upload || npmDTSText !== generatedDTSContent;
6170
} catch (error) {
6271
// Could not find a previous build
@@ -93,8 +102,10 @@ Assuming that this means we need to upload this package.`);
93102

94103
uploaded.push(dirName);
95104
}
96-
}
97105

106+
console.log("\n# Release notes:");
107+
console.log(releaseNotes.join("\n"), "\n\n");
108+
}
98109
// Warn if we did a dry run.
99110
if (!process.env.NODE_AUTH_TOKEN) {
100111
console.log(
@@ -109,7 +120,7 @@ Assuming that this means we need to upload this package.`);
109120
}
110121
};
111122

112-
async function createRelease(tag) {
123+
async function createRelease(tag, body) {
113124
const authToken = process.env.GITHUB_TOKEN || process.env.GITHUB_API_TOKEN;
114125
const octokit = new Octokit({ auth: authToken });
115126

@@ -119,6 +130,7 @@ async function createRelease(tag) {
119130
repo: "TypeScript-DOM-lib-generator",
120131
tag_name: tag,
121132
target_commitish: process.env.GITHUB_SHA,
133+
body,
122134
});
123135
} catch (error) {
124136
console.error(

src/changelog.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,17 @@ function writeAddedRemovedInline(added: Set<string>, removed: Set<string>) {
137137

138138
const dom = "baselines/dom.generated.d.ts";
139139

140-
export function generate(): string {
140+
export function generateDefaultFromRecentTag(): string {
141141
const [base = gitLatestTag(), head = "HEAD"] = process.argv.slice(2);
142142
const previous = gitShowFile(base, dom);
143143
const current = gitShowFile(head, dom);
144+
return generateChangelogFrom(previous, current);
145+
}
146+
147+
export function generateChangelogFrom(
148+
previous: string,
149+
current: string
150+
): string {
144151
const {
145152
interfaces: { added, removed, modified },
146153
others,
@@ -150,6 +157,7 @@ export function generate(): string {
150157
if (added.size || removed.size) {
151158
outputs.push(writeAddedRemoved(added, removed));
152159
}
160+
153161
if (modified.size) {
154162
const modifiedOutput = [`## Modified\n`];
155163
for (const [key, value] of modified.entries()) {
@@ -169,14 +177,9 @@ export function generate(): string {
169177
}
170178

171179
const output = outputs.join("\n\n");
172-
173-
if (!output.length) {
174-
throw new Error(`No change reported between ${base} and ${head}.`);
175-
}
176-
177180
return output;
178181
}
179182

180183
if (process.argv[1] === fileURLToPath(import.meta.url)) {
181-
console.log(generate());
184+
console.log(generateDefaultFromRecentTag());
182185
}

src/version.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { execSync } from "child_process";
22
import { readFile, writeFile } from "fs/promises";
3-
import { generate } from "./changelog.js";
3+
import { generateDefaultFromRecentTag } from "./changelog.js";
44

5-
const output = generate();
5+
const output = generateDefaultFromRecentTag();
66

77
const path = new URL("../CHANGELOG.md", import.meta.url);
88

0 commit comments

Comments
 (0)