Skip to content

Commit fd83ecd

Browse files
committed
fix(release): baseline only on newest meaningfully carried preview
Do not advance notes_range_start to a later empty or missing preview tag after an earlier preview contributed changelog text.
1 parent 40ced9b commit fd83ecd

4 files changed

Lines changed: 76 additions & 13 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,19 @@ jobs:
338338
339339
# Stable releases after matching previews: aggregate every matching preview
340340
# 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.
341+
# generate-notes / commits for the post-preview delta when the newest
342+
# *successfully carried* preview tag is an ancestor of this commit. Never
343+
# advance the baseline to a later preview that is missing/empty — that would
344+
# drop the gap between the last carried preview and that later tag.
344345
notes_range_start="$previous_tag"
345346
if [[ "$RELEASE_VERSION" != *-preview.* ]]; then
346347
preview_carry_tags="$(
347348
git tag --list "v${RELEASE_VERSION}-preview.*" |
348349
bun scripts/release-notes.ts matching-preview-tags "$RELEASE_VERSION"
349350
)"
350-
newest_preview_tag=""
351-
carried_any=false
351+
newest_carried_preview_tag=""
352352
while IFS= read -r preview_carry_tag; do
353353
[ -n "$preview_carry_tag" ] || continue
354-
newest_preview_tag="$preview_carry_tag"
355354
view_err="$(mktemp)"
356355
set +e
357356
gh release view "$preview_carry_tag" --json body --jq .body > "${carried_file}.raw" 2>"$view_err"
@@ -364,10 +363,10 @@ jobs:
364363
printf '\n\n' >> "$carried_file"
365364
fi
366365
cat "${carried_file}.one" >> "$carried_file"
367-
carried_any=true
366+
newest_carried_preview_tag="$preview_carry_tag"
368367
echo "::notice::Carrying preview release notes from ${preview_carry_tag} into ${release_tag}"
369368
else
370-
echo "::notice::Preview release ${preview_carry_tag} has no usable changelog after strip; leaving channel baseline unchanged for this tag"
369+
echo "::notice::Preview release ${preview_carry_tag} has no usable changelog after strip; leaving carried baseline unchanged for this tag"
371370
fi
372371
elif grep -qiE 'could not find|not found|HTTP[[:space:]]*404|Not Found' "$view_err"; then
373372
echo "::notice::Matching preview tag ${preview_carry_tag} has no GitHub Release; skipping"
@@ -378,12 +377,12 @@ jobs:
378377
fi
379378
done <<< "$preview_carry_tags"
380379
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})"
380+
if [ -n "$newest_carried_preview_tag" ]; then
381+
if git merge-base --is-ancestor "$newest_carried_preview_tag" "$GITHUB_SHA"; then
382+
notes_range_start="$newest_carried_preview_tag"
383+
echo "::notice::Using preview tag ${newest_carried_preview_tag} as notes/commits baseline (ancestor of ${GITHUB_SHA})"
385384
else
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"
385+
echo "::notice::Preview tag ${newest_carried_preview_tag} is not an ancestor of ${GITHUB_SHA}; keeping channel baseline ${previous_tag:-none} for generate-notes/commits"
387386
fi
388387
fi
389388
fi

‎scripts/release-notes.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ export function joinCarriedPreviewNotes(parts: string[]): string {
101101
.trim();
102102
}
103103

104+
/**
105+
* Newest preview tag whose GitHub Release body strips to a meaningful changelog.
106+
* Missing releases (`releaseBody === null`) and empty/commits-only bodies must not
107+
* advance the baseline — otherwise a later empty preview.2 would hide the
108+
* preview.1→preview.2 gap from both carried notes and the generated delta.
109+
*/
110+
export function selectNewestCarriedPreviewTag(
111+
entries: Array<{ tag: string; releaseBody: string | null }>,
112+
): string | null {
113+
let newest: string | null = null;
114+
for (const entry of entries) {
115+
if (entry.releaseBody === null) continue;
116+
const stripped = stripCarriedReleaseNotes(entry.releaseBody);
117+
if (hasMeaningfulCarriedNotes(stripped)) newest = entry.tag;
118+
}
119+
return newest;
120+
}
121+
104122
export function assembleReleaseNotes(input: {
105123
npmMetadata: string;
106124
carriedPreviewNotes?: string;

‎tests/ci-workflows.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ describe("GitHub Actions hardening", () => {
139139
expect(workflow).toContain("git merge-base --is-ancestor");
140140
expect(workflow).toContain("operational error, not a missing release");
141141
expect(workflow).toContain("not an ancestor");
142+
expect(workflow).toContain("newest_carried_preview_tag");
143+
expect(workflow).not.toMatch(/newest_preview_tag="\$preview_carry_tag"/);
142144
expect(workflow).toContain("--commits");
143145
expect(workflow).toContain('git tag --list "v${RELEASE_VERSION}-preview.*"');
144146
expect(workflow).toContain("Carrying preview release notes from");
@@ -147,6 +149,7 @@ describe("GitHub Actions hardening", () => {
147149
expect(releaseNotesHelper).toContain("## Since preview");
148150
expect(releaseNotesHelper).toContain("matchingPreviewTags");
149151
expect(releaseNotesHelper).toContain("hasMeaningfulCarriedNotes");
152+
expect(releaseNotesHelper).toContain("selectNewestCarriedPreviewTag");
150153
expect(workflow).toMatch(/gh release create[\s\S]*?--notes-file "\$notes_file"/);
151154
expect(workflow).not.toContain("gh release edit");
152155
expect(workflow).not.toContain("--generate-notes");

‎tests/release-notes.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
joinCarriedPreviewNotes,
77
matchingPreviewTag,
88
matchingPreviewTags,
9+
selectNewestCarriedPreviewTag,
910
stripCarriedReleaseNotes,
1011
stripGenerateNotesCompareLink,
1112
} from "../scripts/release-notes";
@@ -104,6 +105,48 @@ describe("joinCarriedPreviewNotes", () => {
104105
});
105106
});
106107

108+
describe("selectNewestCarriedPreviewTag", () => {
109+
const meaningfulBody = [
110+
"Published to npm as `@[email protected]` with dist-tag `preview`.",
111+
"",
112+
"## What's Changed",
113+
"* fix from preview.1",
114+
"",
115+
"## Commits",
116+
"- release preview.1",
117+
].join("\n");
118+
119+
const emptyBody = [
120+
"Published to npm as `@[email protected]` with dist-tag `preview`.",
121+
"",
122+
"<!-- Release notes generated using configuration in .github/release.yml at abc -->",
123+
"",
124+
"## Commits",
125+
"- release preview.2",
126+
"",
127+
"**Full Changelog**: https://example/compare/a...b",
128+
].join("\n");
129+
130+
test("keeps preview.1 as baseline when preview.2 is missing or empty", () => {
131+
expect(selectNewestCarriedPreviewTag([
132+
{ tag: "v1.0.0-preview.1", releaseBody: meaningfulBody },
133+
{ tag: "v1.0.0-preview.2", releaseBody: null },
134+
])).toBe("v1.0.0-preview.1");
135+
136+
expect(selectNewestCarriedPreviewTag([
137+
{ tag: "v1.0.0-preview.1", releaseBody: meaningfulBody },
138+
{ tag: "v1.0.0-preview.2", releaseBody: emptyBody },
139+
])).toBe("v1.0.0-preview.1");
140+
});
141+
142+
test("advances to preview.2 only when its body is meaningful", () => {
143+
expect(selectNewestCarriedPreviewTag([
144+
{ tag: "v1.0.0-preview.1", releaseBody: meaningfulBody },
145+
{ tag: "v1.0.0-preview.2", releaseBody: "## What's Changed\n* fix from preview.2" },
146+
])).toBe("v1.0.0-preview.2");
147+
});
148+
});
149+
107150
describe("assembleReleaseNotes", () => {
108151
test("copies preview notes and appends only the since-preview delta", () => {
109152
const notes = assembleReleaseNotes({

0 commit comments

Comments
 (0)