Skip to content

Commit 40ced9b

Browse files
committed
fix(release): harden preview note carry for Codex review
Aggregate all matching preview changelogs, keep the channel baseline when carried notes are empty or the preview tag is not an ancestor, and fail closed on gh release view operational errors.
1 parent ecdb943 commit 40ced9b

4 files changed

Lines changed: 150 additions & 23 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,23 +336,54 @@ jobs:
336336
: > "$delta_file"
337337
: > "$commits_file"
338338
339-
# Stable releases after a matching preview: copy that preview changelog, then only
340-
# generate-notes / commits for the preview→latest delta. Preview tags often are not
341-
# ancestors of main, so match by version prefix (not --merged).
339+
# Stable releases after matching previews: aggregate every matching preview
340+
# changelog (oldest→newest; each preview body is incremental), then only
341+
# generate-notes / commits for the post-preview delta when the newest preview
342+
# tag is an ancestor of this commit. Preview tags often are not ancestors of
343+
# main, so we never use a divergent preview tag as a two-dot baseline.
342344
notes_range_start="$previous_tag"
343345
if [[ "$RELEASE_VERSION" != *-preview.* ]]; then
344-
preview_carry_tag="$(
345-
git tag --list "v${RELEASE_VERSION}-preview.*" --sort=-v:refname |
346-
head -n 1 || true
346+
preview_carry_tags="$(
347+
git tag --list "v${RELEASE_VERSION}-preview.*" |
348+
bun scripts/release-notes.ts matching-preview-tags "$RELEASE_VERSION"
347349
)"
348-
if [ -n "$preview_carry_tag" ]; then
349-
if gh release view "$preview_carry_tag" --json body --jq .body > "${carried_file}.raw" 2>/dev/null; then
350-
bun scripts/release-notes.ts strip-carried "${carried_file}.raw" > "$carried_file"
351-
notes_range_start="$preview_carry_tag"
352-
echo "::notice::Carrying preview release notes from ${preview_carry_tag} into ${release_tag}"
350+
newest_preview_tag=""
351+
carried_any=false
352+
while IFS= read -r preview_carry_tag; do
353+
[ -n "$preview_carry_tag" ] || continue
354+
newest_preview_tag="$preview_carry_tag"
355+
view_err="$(mktemp)"
356+
set +e
357+
gh release view "$preview_carry_tag" --json body --jq .body > "${carried_file}.raw" 2>"$view_err"
358+
view_status=$?
359+
set -e
360+
if [ "$view_status" -eq 0 ]; then
361+
bun scripts/release-notes.ts strip-carried "${carried_file}.raw" > "${carried_file}.one"
362+
if bun scripts/release-notes.ts has-meaningful "${carried_file}.one"; then
363+
if [ -s "$carried_file" ]; then
364+
printf '\n\n' >> "$carried_file"
365+
fi
366+
cat "${carried_file}.one" >> "$carried_file"
367+
carried_any=true
368+
echo "::notice::Carrying preview release notes from ${preview_carry_tag} into ${release_tag}"
369+
else
370+
echo "::notice::Preview release ${preview_carry_tag} has no usable changelog after strip; leaving channel baseline unchanged for this tag"
371+
fi
372+
elif grep -qiE 'could not find|not found|HTTP[[:space:]]*404|Not Found' "$view_err"; then
373+
echo "::notice::Matching preview tag ${preview_carry_tag} has no GitHub Release; skipping"
374+
else
375+
echo "::error::Failed to look up GitHub Release for ${preview_carry_tag} (operational error, not a missing release)"
376+
cat "$view_err" >&2 || true
377+
exit 1
378+
fi
379+
done <<< "$preview_carry_tags"
380+
381+
if [ "$carried_any" = true ] && [ -n "$newest_preview_tag" ]; then
382+
if git merge-base --is-ancestor "$newest_preview_tag" "$GITHUB_SHA"; then
383+
notes_range_start="$newest_preview_tag"
384+
echo "::notice::Using preview tag ${newest_preview_tag} as notes/commits baseline (ancestor of ${GITHUB_SHA})"
353385
else
354-
echo "::notice::Matching preview tag ${preview_carry_tag} has no GitHub Release; using channel notes only"
355-
: > "$carried_file"
386+
echo "::notice::Preview tag ${newest_preview_tag} is not an ancestor of ${GITHUB_SHA}; keeping channel baseline ${previous_tag:-none} for generate-notes/commits"
356387
fi
357388
fi
358389
fi

‎scripts/release-notes.ts‎

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,35 @@
22
/**
33
* Pure helpers for GitHub release note assembly.
44
* 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.
66
*
77
* CLI:
88
* bun scripts/release-notes.ts strip-carried <body-file>
99
* 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]
1012
* bun scripts/release-notes.ts assemble --npm-metadata ... --out ...
1113
*/
1214

15+
/** Newest matching preview tag for a stable version, or null. */
1316
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 [];
1528
const prefix = `v${version}-preview.`;
1629
const matches = tags
1730
.map(tag => tag.trim())
1831
.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;
2234
}
2335

2436
/** Drop npm blurb, Commits section, and Full Changelog link from a prior release body. */
@@ -67,10 +79,28 @@ export function isEmptyGeneratedNotes(body: string): boolean {
6779
return !hasNonWhitespace(withoutComment);
6880
}
6981

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+
7091
export function hasNonWhitespace(text: string): boolean {
7192
return text.replace(/\s+/g, "").length > 0;
7293
}
7394

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+
74104
export function assembleReleaseNotes(input: {
75105
npmMetadata: string;
76106
carriedPreviewNotes?: string;
@@ -128,15 +158,27 @@ async function main(argv: string[]): Promise<void> {
128158
return;
129159
}
130160

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") {
132167
const version = rest[0];
133168
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>`);
135170
process.exit(1);
136171
}
137172
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+
}
140182
return;
141183
}
142184

@@ -183,7 +225,9 @@ async function main(argv: string[]): Promise<void> {
183225
console.error(`Unknown command: ${cmd ?? "(none)"}
184226
Usage:
185227
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
187231
bun scripts/release-notes.ts assemble --npm-metadata ... --out ...`);
188232
process.exit(1);
189233
}

‎tests/ci-workflows.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,19 @@ describe("GitHub Actions hardening", () => {
134134
expect(workflow).toContain("skipping generate-notes (commits-only notes)");
135135
expect(workflow).toContain("bun scripts/release-notes.ts strip-carried");
136136
expect(workflow).toContain("bun scripts/release-notes.ts assemble");
137+
expect(workflow).toContain("bun scripts/release-notes.ts matching-preview-tags");
138+
expect(workflow).toContain("bun scripts/release-notes.ts has-meaningful");
139+
expect(workflow).toContain("git merge-base --is-ancestor");
140+
expect(workflow).toContain("operational error, not a missing release");
141+
expect(workflow).toContain("not an ancestor");
137142
expect(workflow).toContain("--commits");
138143
expect(workflow).toContain('git tag --list "v${RELEASE_VERSION}-preview.*"');
139144
expect(workflow).toContain("Carrying preview release notes from");
140145
const releaseNotesHelper = await readText("scripts/release-notes.ts");
141146
expect(releaseNotesHelper).toContain("## Commits");
142147
expect(releaseNotesHelper).toContain("## Since preview");
148+
expect(releaseNotesHelper).toContain("matchingPreviewTags");
149+
expect(releaseNotesHelper).toContain("hasMeaningfulCarriedNotes");
143150
expect(workflow).toMatch(/gh release create[\s\S]*?--notes-file "\$notes_file"/);
144151
expect(workflow).not.toContain("gh release edit");
145152
expect(workflow).not.toContain("--generate-notes");

‎tests/release-notes.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { describe, expect, test } from "bun:test";
22
import {
33
assembleReleaseNotes,
4+
hasMeaningfulCarriedNotes,
45
hasNonWhitespace,
6+
joinCarriedPreviewNotes,
57
matchingPreviewTag,
8+
matchingPreviewTags,
69
stripCarriedReleaseNotes,
710
stripGenerateNotesCompareLink,
811
} from "../scripts/release-notes";
@@ -24,6 +27,20 @@ describe("matchingPreviewTag", () => {
2427
});
2528
});
2629

30+
describe("matchingPreviewTags", () => {
31+
test("returns all matching preview tags oldest to newest", () => {
32+
expect(matchingPreviewTags("2.7.39", [
33+
"v2.7.39-preview.20260725",
34+
"v2.7.38-preview.20260724",
35+
"v2.7.39-preview.20260724",
36+
"v2.7.39",
37+
])).toEqual([
38+
"v2.7.39-preview.20260724",
39+
"v2.7.39-preview.20260725",
40+
]);
41+
});
42+
});
43+
2744
describe("stripCarriedReleaseNotes", () => {
2845
test("keeps PR categories and drops npm blurb, commits, and compare link", () => {
2946
const body = [
@@ -58,6 +75,33 @@ describe("stripCarriedReleaseNotes", () => {
5875
"* @someone made their first contribution",
5976
].join("\n"));
6077
});
78+
79+
test("commits-only preview bodies strip to non-meaningful notes", () => {
80+
const body = [
81+
"Published to npm as `@bitkyc08/[email protected]` with dist-tag `preview`.",
82+
"",
83+
"<!-- Release notes generated using configuration in .github/release.yml at abc -->",
84+
"",
85+
"## Commits",
86+
"",
87+
"- release: v2.7.39-preview.20260724 (8894e40e)",
88+
"",
89+
"**Full Changelog**: https://example/compare/a...b",
90+
].join("\n");
91+
const stripped = stripCarriedReleaseNotes(body);
92+
expect(hasMeaningfulCarriedNotes(stripped)).toBe(false);
93+
});
94+
});
95+
96+
describe("joinCarriedPreviewNotes", () => {
97+
test("aggregates multiple incremental preview bodies in order", () => {
98+
const joined = joinCarriedPreviewNotes([
99+
"## What's Changed\n* fix A",
100+
"<!-- only comment -->",
101+
"## What's Changed\n* fix B",
102+
]);
103+
expect(joined).toBe("## What's Changed\n* fix A\n\n## What's Changed\n* fix B");
104+
});
61105
});
62106

63107
describe("assembleReleaseNotes", () => {
@@ -109,5 +153,6 @@ describe("assembleReleaseNotes", () => {
109153
expect(notes).toContain("## What's Changed\n* feat X");
110154
expect(notes).not.toContain("https://example/compare/a...b");
111155
expect(hasNonWhitespace("")).toBe(false);
156+
expect(stripGenerateNotesCompareLink("x\n**Full Changelog**: y")).toBe("x");
112157
});
113158
});

0 commit comments

Comments
 (0)