|
2 | 2 | /** |
3 | 3 | * Pure helpers for GitHub release note assembly. |
4 | 4 | * Used by `.github/workflows/release.yml` so stable (latest) releases can carry |
5 | | - * the matching preview changelog, plus any delta since that preview. |
| 5 | + * matching preview changelogs, plus any delta since the last carried preview. |
6 | 6 | * |
7 | 7 | * CLI: |
8 | 8 | * bun scripts/release-notes.ts strip-carried <body-file> |
9 | 9 | * bun scripts/release-notes.ts matching-preview-tag <version> |
| 10 | + * bun scripts/release-notes.ts matching-preview-tags <version> |
| 11 | + * bun scripts/release-notes.ts has-meaningful [body-file] |
10 | 12 | * bun scripts/release-notes.ts assemble --npm-metadata ... --out ... |
11 | 13 | */ |
12 | 14 |
|
| 15 | +/** Newest matching preview tag for a stable version, or null. */ |
13 | 16 | export function matchingPreviewTag(version: string, tags: string[]): string | null { |
14 | | - if (!version || version.includes("-")) return null; |
| 17 | + const matches = matchingPreviewTags(version, tags); |
| 18 | + return matches.length === 0 ? null : matches[matches.length - 1]!; |
| 19 | +} |
| 20 | + |
| 21 | +/** |
| 22 | + * All matching preview tags for a stable version, oldest → newest. |
| 23 | + * Each preview's notes are incremental vs the previous preview, so stable |
| 24 | + * releases must aggregate in this order to avoid dropping earlier preview work. |
| 25 | + */ |
| 26 | +export function matchingPreviewTags(version: string, tags: string[]): string[] { |
| 27 | + if (!version || version.includes("-")) return []; |
15 | 28 | const prefix = `v${version}-preview.`; |
16 | 29 | const matches = tags |
17 | 30 | .map(tag => tag.trim()) |
18 | 31 | .filter(tag => tag.startsWith(prefix)); |
19 | | - if (matches.length === 0) return null; |
20 | | - matches.sort((a, b) => b.localeCompare(a, undefined, { numeric: true, sensitivity: "base" })); |
21 | | - return matches[0] ?? null; |
| 32 | + matches.sort((a, b) => a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" })); |
| 33 | + return matches; |
22 | 34 | } |
23 | 35 |
|
24 | 36 | /** Drop npm blurb, Commits section, and Full Changelog link from a prior release body. */ |
@@ -67,10 +79,28 @@ export function isEmptyGeneratedNotes(body: string): boolean { |
67 | 79 | return !hasNonWhitespace(withoutComment); |
68 | 80 | } |
69 | 81 |
|
| 82 | +/** |
| 83 | + * True when stripped carried notes contain a usable changelog (not blank / |
| 84 | + * comment-only). Commits-only preview releases strip down to empty and must not |
| 85 | + * move the stable notes baseline. |
| 86 | + */ |
| 87 | +export function hasMeaningfulCarriedNotes(stripped: string): boolean { |
| 88 | + return !isEmptyGeneratedNotes(stripped); |
| 89 | +} |
| 90 | + |
70 | 91 | export function hasNonWhitespace(text: string): boolean { |
71 | 92 | return text.replace(/\s+/g, "").length > 0; |
72 | 93 | } |
73 | 94 |
|
| 95 | +/** Join multiple stripped preview bodies in chronological order. */ |
| 96 | +export function joinCarriedPreviewNotes(parts: string[]): string { |
| 97 | + return parts |
| 98 | + .map(part => part.trim()) |
| 99 | + .filter(part => hasMeaningfulCarriedNotes(part)) |
| 100 | + .join("\n\n") |
| 101 | + .trim(); |
| 102 | +} |
| 103 | + |
74 | 104 | export function assembleReleaseNotes(input: { |
75 | 105 | npmMetadata: string; |
76 | 106 | carriedPreviewNotes?: string; |
@@ -128,15 +158,27 @@ async function main(argv: string[]): Promise<void> { |
128 | 158 | return; |
129 | 159 | } |
130 | 160 |
|
131 | | - if (cmd === "matching-preview-tag") { |
| 161 | + if (cmd === "has-meaningful") { |
| 162 | + const stripped = (await readStdinOrFile(rest[0])).trim(); |
| 163 | + process.exit(hasMeaningfulCarriedNotes(stripped) ? 0 : 1); |
| 164 | + } |
| 165 | + |
| 166 | + if (cmd === "matching-preview-tag" || cmd === "matching-preview-tags") { |
132 | 167 | const version = rest[0]; |
133 | 168 | if (!version) { |
134 | | - console.error("Usage: bun scripts/release-notes.ts matching-preview-tag <version>"); |
| 169 | + console.error(`Usage: bun scripts/release-notes.ts ${cmd} <version>`); |
135 | 170 | process.exit(1); |
136 | 171 | } |
137 | 172 | const tagsText = await new Response(Bun.stdin).text(); |
138 | | - const tag = matchingPreviewTag(version, tagsText.split(/\r?\n/)); |
139 | | - if (tag) process.stdout.write(tag + "\n"); |
| 173 | + const tags = tagsText.split(/\r?\n/); |
| 174 | + if (cmd === "matching-preview-tag") { |
| 175 | + const tag = matchingPreviewTag(version, tags); |
| 176 | + if (tag) process.stdout.write(tag + "\n"); |
| 177 | + return; |
| 178 | + } |
| 179 | + for (const tag of matchingPreviewTags(version, tags)) { |
| 180 | + process.stdout.write(tag + "\n"); |
| 181 | + } |
140 | 182 | return; |
141 | 183 | } |
142 | 184 |
|
@@ -183,7 +225,9 @@ async function main(argv: string[]): Promise<void> { |
183 | 225 | console.error(`Unknown command: ${cmd ?? "(none)"} |
184 | 226 | Usage: |
185 | 227 | bun scripts/release-notes.ts strip-carried [body-file] |
186 | | - bun scripts/release-notes.ts matching-preview-tag <version> # tags on stdin |
| 228 | + bun scripts/release-notes.ts has-meaningful [body-file] |
| 229 | + bun scripts/release-notes.ts matching-preview-tag <version> # tags on stdin |
| 230 | + bun scripts/release-notes.ts matching-preview-tags <version> # tags on stdin, oldest→newest |
187 | 231 | bun scripts/release-notes.ts assemble --npm-metadata ... --out ...`); |
188 | 232 | process.exit(1); |
189 | 233 | } |
|
0 commit comments