Skip to content

Commit 11b2933

Browse files
committed
fix(release): classify preview lookup by HTTP status, not stderr
Fail closed on auth/permission 404s, wire join-carried into the workflow, and tighten CI contract tests.
1 parent fd83ecd commit 11b2933

4 files changed

Lines changed: 89 additions & 21 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,26 +349,32 @@ jobs:
349349
bun scripts/release-notes.ts matching-preview-tags "$RELEASE_VERSION"
350350
)"
351351
newest_carried_preview_tag=""
352+
carried_part_files=()
353+
# Probe repo readability once so a token/permission 404 cannot be
354+
# mistaken for "this preview tag has no release".
355+
gh api "repos/${GITHUB_REPOSITORY}" --jq '.full_name' > /dev/null
356+
view_err="$(mktemp)"
352357
while IFS= read -r preview_carry_tag; do
353358
[ -n "$preview_carry_tag" ] || continue
354-
view_err="$(mktemp)"
359+
: > "$view_err"
355360
set +e
356-
gh release view "$preview_carry_tag" --json body --jq .body > "${carried_file}.raw" 2>"$view_err"
361+
# Prefer HTTP status over stderr prose: auth failures also say "Not Found".
362+
gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${preview_carry_tag}" \
363+
--jq '.body' > "${carried_file}.raw" 2>"$view_err"
357364
view_status=$?
358365
set -e
359366
if [ "$view_status" -eq 0 ]; then
360367
bun scripts/release-notes.ts strip-carried "${carried_file}.raw" > "${carried_file}.one"
361368
if bun scripts/release-notes.ts has-meaningful "${carried_file}.one"; then
362-
if [ -s "$carried_file" ]; then
363-
printf '\n\n' >> "$carried_file"
364-
fi
365-
cat "${carried_file}.one" >> "$carried_file"
369+
part_file="${carried_file}.part.${#carried_part_files[@]}"
370+
cp "${carried_file}.one" "$part_file"
371+
carried_part_files+=("$part_file")
366372
newest_carried_preview_tag="$preview_carry_tag"
367373
echo "::notice::Carrying preview release notes from ${preview_carry_tag} into ${release_tag}"
368374
else
369375
echo "::notice::Preview release ${preview_carry_tag} has no usable changelog after strip; leaving carried baseline unchanged for this tag"
370376
fi
371-
elif grep -qiE 'could not find|not found|HTTP[[:space:]]*404|Not Found' "$view_err"; then
377+
elif grep -qE 'HTTP 404' "$view_err"; then
372378
echo "::notice::Matching preview tag ${preview_carry_tag} has no GitHub Release; skipping"
373379
else
374380
echo "::error::Failed to look up GitHub Release for ${preview_carry_tag} (operational error, not a missing release)"
@@ -377,6 +383,10 @@ jobs:
377383
fi
378384
done <<< "$preview_carry_tags"
379385
386+
if [ "${#carried_part_files[@]}" -gt 0 ]; then
387+
bun scripts/release-notes.ts join-carried --out "$carried_file" "${carried_part_files[@]}"
388+
fi
389+
380390
if [ -n "$newest_carried_preview_tag" ]; then
381391
if git merge-base --is-ancestor "$newest_carried_preview_tag" "$GITHUB_SHA"; then
382392
notes_range_start="$newest_carried_preview_tag"
@@ -407,15 +417,15 @@ jobs:
407417
if [ -n "$notes_range_start" ]; then
408418
commit_range="${notes_range_start}..${GITHUB_SHA}"
409419
git log --pretty=format:'- %s (%h)' "$commit_range" > "$commits_file"
410-
# git log may omit a trailing newline; normalize empty output for assemble.
411-
if [ ! -s "$commits_file" ]; then
412-
: > "$commits_file"
413-
fi
414420
else
415421
# First release on a channel has no previous tag; cap history so the notes
416422
# body stays within GitHub release size limits.
417423
git log --pretty=format:'- %s (%h)' --max-count=100 "$GITHUB_SHA" > "$commits_file"
418424
fi
425+
# `--pretty=format:` omits the trailing newline; normalize for downstream readers.
426+
if [ -s "$commits_file" ]; then
427+
printf '\n' >> "$commits_file"
428+
fi
419429
420430
assemble_args=(
421431
bun scripts/release-notes.ts assemble

‎scripts/release-notes.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,37 @@ async function main(argv: string[]): Promise<void> {
181181
process.exit(hasMeaningfulCarriedNotes(stripped) ? 0 : 1);
182182
}
183183

184+
if (cmd === "join-carried") {
185+
let out: string | undefined;
186+
const files: string[] = [];
187+
for (let i = 0; i < rest.length; i += 1) {
188+
const arg = rest[i];
189+
if (arg === "--out") {
190+
const value = rest[i + 1];
191+
if (!value || value.startsWith("--")) {
192+
console.error("Missing value for --out");
193+
process.exit(1);
194+
}
195+
out = value;
196+
i += 1;
197+
continue;
198+
}
199+
if (arg?.startsWith("--")) {
200+
console.error(`Unknown flag: ${arg}`);
201+
process.exit(1);
202+
}
203+
if (arg) files.push(arg);
204+
}
205+
if (!out || files.length === 0) {
206+
console.error("Usage: bun scripts/release-notes.ts join-carried --out <file> <part-file>...");
207+
process.exit(1);
208+
}
209+
const parts = await Promise.all(files.map(path => Bun.file(path).text()));
210+
const joined = joinCarriedPreviewNotes(parts);
211+
await Bun.write(out, joined ? joined + "\n" : "");
212+
return;
213+
}
214+
184215
if (cmd === "matching-preview-tag" || cmd === "matching-preview-tags") {
185216
const version = rest[0];
186217
if (!version) {
@@ -244,6 +275,7 @@ async function main(argv: string[]): Promise<void> {
244275
Usage:
245276
bun scripts/release-notes.ts strip-carried [body-file]
246277
bun scripts/release-notes.ts has-meaningful [body-file]
278+
bun scripts/release-notes.ts join-carried --out <file> <part-file>...
247279
bun scripts/release-notes.ts matching-preview-tag <version> # tags on stdin
248280
bun scripts/release-notes.ts matching-preview-tags <version> # tags on stdin, oldest→newest
249281
bun scripts/release-notes.ts assemble --npm-metadata ... --out ...`);

‎tests/ci-workflows.test.ts‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ describe("GitHub Actions hardening", () => {
136136
expect(workflow).toContain("bun scripts/release-notes.ts assemble");
137137
expect(workflow).toContain("bun scripts/release-notes.ts matching-preview-tags");
138138
expect(workflow).toContain("bun scripts/release-notes.ts has-meaningful");
139+
expect(workflow).toContain("bun scripts/release-notes.ts join-carried");
140+
expect(workflow).toContain("releases/tags/");
141+
expect(workflow).toContain('gh api "repos/${GITHUB_REPOSITORY}" --jq \'.full_name\'');
139142
expect(workflow).toContain("git merge-base --is-ancestor");
140143
expect(workflow).toContain("operational error, not a missing release");
141144
expect(workflow).toContain("not an ancestor");
@@ -144,28 +147,41 @@ describe("GitHub Actions hardening", () => {
144147
expect(workflow).toContain("--commits");
145148
expect(workflow).toContain('git tag --list "v${RELEASE_VERSION}-preview.*"');
146149
expect(workflow).toContain("Carrying preview release notes from");
150+
// Every subcommand the workflow invokes must be dispatched by the CLI.
147151
const releaseNotesHelper = await readText("scripts/release-notes.ts");
148-
expect(releaseNotesHelper).toContain("## Commits");
149-
expect(releaseNotesHelper).toContain("## Since preview");
150-
expect(releaseNotesHelper).toContain("matchingPreviewTags");
151-
expect(releaseNotesHelper).toContain("hasMeaningfulCarriedNotes");
152-
expect(releaseNotesHelper).toContain("selectNewestCarriedPreviewTag");
152+
const invoked = [...workflow.matchAll(/bun scripts\/release-notes\.ts ([a-z-]+)/g)]
153+
.map(m => m[1]!);
154+
expect(invoked.length).toBeGreaterThan(0);
155+
for (const cmd of new Set(invoked)) {
156+
expect(releaseNotesHelper).toContain(`"${cmd}"`);
157+
}
153158
expect(workflow).toMatch(/gh release create[\s\S]*?--notes-file "\$notes_file"/);
154159
expect(workflow).not.toContain("gh release edit");
155160
expect(workflow).not.toContain("--generate-notes");
156161
// Notes must be assembled before tagging so a notes API failure does not leave
157162
// a remote tag that blocks release retries at preflight.
158163
const createStep = workflow.split("- name: Create GitHub release")[1]!.split(/\n {6}- name:/)[0]!;
159-
// Fail closed when generate-notes fails (no soft skip on the API call itself).
160-
expect(createStep).not.toMatch(/pr_notes="\$\(gh api[\s\S]*?\|\| true\)"/);
164+
// Preview carry lookup must use tag-specific API status, not `gh release view` stderr prose.
165+
expect(createStep).toContain("releases/tags/");
166+
expect(createStep).not.toContain("gh release view");
167+
// Fail closed: no soft-skip in any spelling around gh api calls in this step.
168+
for (const line of createStep.split("\n").filter(l => l.includes("gh api"))) {
169+
expect(line).not.toMatch(/\|\|\s*(true|echo|:)/);
170+
}
171+
expect(createStep).not.toContain("set +e\n pr_notes");
161172
expect(createStep.indexOf("gh api")).toBeGreaterThan(-1);
162173
expect(createStep.indexOf('git tag "$release_tag"')).toBeGreaterThan(-1);
163174
expect(createStep.indexOf("gh api")).toBeLessThan(createStep.indexOf('git tag "$release_tag"'));
164175
// First-channel releases must not call generate-notes without an explicit baseline
165176
// (GitHub would otherwise pick the newest repo tag, possibly from the other channel).
166-
expect(createStep).toMatch(
167-
/if \[ -n "\$notes_range_start" \]; then[\s\S]*previous_tag_name=\$\{notes_range_start\}[\s\S]*else[\s\S]*skipping generate-notes/,
168-
);
177+
// Scope to the single if-block that owns generate-notes; createStep has two
178+
// `[ -n "$notes_range_start" ]` blocks, so an unanchored [\s\S]* can straddle them.
179+
const notesBlock = createStep
180+
.split(/if \[ -n "\$notes_range_start" \]; then/)[1]!
181+
.split(/\n {10}if \[/)[0]!;
182+
expect(notesBlock).toContain("previous_tag_name=${notes_range_start}");
183+
expect(notesBlock).toContain("skipping generate-notes");
184+
expect(notesBlock).toMatch(/\n {10}else\n/);
169185
});
170186

171187
test("docs deployment is pinned, bounded, and scoped to Pages", async () => {

‎tests/release-notes.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ describe("matchingPreviewTags", () => {
4040
"v2.7.39-preview.20260725",
4141
]);
4242
});
43+
44+
test("orders same-day previews numerically, not lexicographically", () => {
45+
expect(matchingPreviewTags("2.7.39", [
46+
"v2.7.39-preview.20260725.10",
47+
"v2.7.39-preview.20260725.2",
48+
])).toEqual([
49+
"v2.7.39-preview.20260725.2",
50+
"v2.7.39-preview.20260725.10",
51+
]);
52+
});
4353
});
4454

4555
describe("stripCarriedReleaseNotes", () => {

0 commit comments

Comments
 (0)