Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/release-local/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
manifestUrl,
type PublishedManifest,
} from "../release-manifest";
import { notesFromGit } from "./notes";
import { notesFromGit } from "./notes-sources";
import { assetUrl, LATEST, RELEASE_DIR } from "./paths";
import { arg, fail, log, REPO } from "./process";

Expand All @@ -25,7 +25,7 @@ export interface Manifest {
platforms: Record<string, { signature: string; url: string }>;
}

/** Writes `latest.json`; the notes come from `--notes FILE` or the commits since the last tag. */
/** Writes `latest.json`; the notes come from `--notes FILE` or the PRs since the last tag. */
export function writeManifest(
version: string,
tag: string,
Expand All @@ -44,7 +44,7 @@ export function writeManifest(
writeFileSync(LATEST, `${JSON.stringify(latest, null, 2)}\n`);

if (notesArg === null) {
latest.notes = notesFromGit(sha);
latest.notes = notesFromGit(sha, version);
writeFileSync(LATEST, `${JSON.stringify(latest, null, 2)}\n`);
}
return latest;
Expand Down
64 changes: 64 additions & 0 deletions scripts/release-local/notes-sources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* The process-backed half of release notes.
*
* git supplies the range: the last tag reachable from the commit being released, which exists locally
* even though the tag being cut does not. gh supplies PR titles and bodies; the `(#NNN)` suffix in each
* subject is the only link needed. Every gh call is optional to the release.
*/

import { composeNotes, type NotesSources, type PullRequest } from "./notes";
import { fail, REPO, run } from "./process";

export const processSources: NotesSources = {
previousTag(commit: string): string {
// An existing release tag points at its own commit: describe would name that tag and leave an
// empty range. The release path has no tag at the commit yet and takes the other branch.
const here = run("git", ["tag", "--points-at", commit]).trim();
const anchor = here === "" ? commit : `${commit}^`;
return run("git", ["describe", "--tags", "--abbrev=0", anchor]).trim();
},
subjects(commit: string, previous: string): string[] {
return run("git", ["log", "--no-merges", "--pretty=format:%s", `${previous}..${commit}`])
.split("\n")
.map((line) => line.trim())
.filter((line) => line !== "");
},
pullRequest(number: number): PullRequest | null {
const raw = run("gh", [
"pr",
"view",
String(number),
"--repo",
REPO,
"--json",
"title,body",
]);
const parsed = JSON.parse(raw) as Partial<PullRequest>;
return {
title: typeof parsed.title === "string" ? parsed.title : "",
body: typeof parsed.body === "string" ? parsed.body : "",
};
},
};

/** Notes for the range ending at `commit`; git failures leave the old minimal body. */
export function notesFromGit(commit: string, version: string): string {
try {
return composeNotes(commit, version, processSources);
} catch {
return "Local alpha build.";
}
}

/** The version recorded at a tag, so a dry run never reads the working tree's already-bumped version. */
export function versionAtTag(tag: string): string {
const raw = run("git", ["show", `${tag}:package.json`]);
const version = (JSON.parse(raw) as { version?: unknown }).version;
if (typeof version !== "string" || version === "") fail(`no version recorded at tag ${tag}`);
return version;
}

/** Printable body for an existing tag; the release path uses `notesFromGit` with the built version. */
export function notesForTag(tag: string, commit: string = tag): string {
return notesFromGit(commit, versionAtTag(tag));
}
167 changes: 167 additions & 0 deletions scripts/release-local/notes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import { describe, expect, test } from "bun:test";
import {
composeNotes,
firstProseParagraph,
groupFor,
isVersionBump,
type NotesSources,
summaryIndex,
updateLine,
} from "./notes";

const BODY =
"Now an Initialize panel offers four kinds.\n\n" +
"The panel reuses the existing pickers, so there is no second list to drift.\n\nGate green.";

function sources(
subjects: string[],
pullRequest: NotesSources["pullRequest"] = () => null,
): NotesSources {
return {
previousTag: () => "quarry-alpha104",
subjects: () => subjects,
pullRequest,
};
}

describe("grouping", () => {
test("a chore lands Under the hood and a version bump nowhere", () => {
const notes = composeNotes(
"HEAD",
"0.1.0-alpha.105",
sources(
[
"feat(ui): initialize panel (#231)",
"chore: tidy the lockfile (#229)",
"chore: bump to 0.1.0-alpha.105 (#232)",
],
() => ({ title: "chore: tidy the lockfile", body: BODY }),
),
);
expect(notes).toContain("## Under the hood");
expect(notes).toContain("- tidy the lockfile (#229)");
expect(notes).not.toContain("bump to 0.1.0-alpha.105");
expect(isVersionBump("chore(release): bump to 1.2.3 (#3)")).toBe(true);
expect(groupFor("docs: explain settings")).toBe("under");
expect(groupFor("fix(term): flat pane (#7)")).toBe("fixes");
});

test("an empty range says so", () => {
expect(composeNotes("HEAD", "1.0.0", sources(["chore: bump to 1.0.0 (#1)"]))).toBe(
"No user-visible changes since quarry-alpha104.",
);
});
});

describe("pull request bodies", () => {
test("a PR body paragraph is indented under the PR title", () => {
const notes = composeNotes(
"HEAD",
"1.0.0",
sources(["fix(term): ring around pane (#7)"], () => ({
title: "fix(term): one flat surface",
body: BODY,
})),
);
expect(notes).toContain("- one flat surface (#7)");
expect(notes).not.toContain("fix(term):");
expect(notes).toContain(" Now an Initialize panel offers four kinds.");
expect(notes).toContain("## Fixes");
});

test("the index names the displayed title, not the body prose", () => {
const notes = composeNotes(
"HEAD",
"1.0.0",
sources(["feat(ui): initialize panel (#231)"], () => ({
title: "feat(ui): initialize panel",
body: BODY,
})),
);
expect(notes.split("\n")[0]).toBe("One change: initialize panel.");
expect(notes).not.toContain("Changes since");
expect(firstProseParagraph("## Summary\n- a list\n\nNow the panel opens.\n")).toBe(
"Now the panel opens.",
);
});
});

describe("degradation", () => {
test("gh failure falls back to the subject list and says why", () => {
const thrown = sources(
["feat(ui): initialize panel (#231)", "chore: bump to 1.0.0 (#232)"],
() => {
throw new Error("gh: could not resolve host");
},
);
const notes = composeNotes("HEAD", "1.0.0", thrown);
expect(notes.split("\n")[0]).toBe(
"Summary unavailable: could not read the merged pull requests.",
);
expect(notes).toContain("- feat(ui): initialize panel (#231)");
expect(notes).not.toContain("## Features");
expect(notes).not.toContain("bump to 1.0.0");
});

test("a missing PR is a bare subject beside the enriched ones", () => {
const notes = composeNotes(
"HEAD",
"1.0.0",
sources(["feat(a): one (#1)", "feat(b): two (#2)"], (number) =>
number === 1 ? { title: "feat(a): one", body: BODY } : null,
),
);
expect(notes).toContain("- feat(b): two (#2)");
expect(notes).not.toContain("Summary unavailable");
});
});

describe("the summary index", () => {
test("One, Two and N changes all come from the displayed titles", () => {
expect(summaryIndex(["a"])).toBe("One change: a.");
expect(summaryIndex(["a", "b"])).toBe("Two changes: a; b.");
expect(summaryIndex(["a", "b", "c", "d"])).toBe("4 changes: a; b; c; d.");
const notes = composeNotes(
"HEAD",
"1.0.0",
sources(
[1, 2, 3, 4].map((number) => `feat(ui): change ${number} (#${number})`),
(number) => ({
title: `feat(ui): change ${number}`,
body: `Body prose for ${number}.\n\nSecond paragraph for ${number}.`,
}),
),
);
expect(notes.split("\n")[0]).toBe("4 changes: change 1; change 2; change 3; change 4.");
});

test("no summary sentence appears inside an entry paragraph", () => {
const notes = composeNotes(
"HEAD",
"1.0.0",
sources(["feat(a): alpha title (#1)", "feat(b): beta title (#2)"], (number) => ({
title: `feat(x): body ${number}`,
body: `Body prose for ${number}.`,
})),
);
const summary = notes.split("\n")[0] ?? "";
const paragraphs = notes
.split("\n")
.filter((line) => line.startsWith(" "))
.map((line) => line.trim());
expect(paragraphs.length).toBe(2);
for (const sentence of summary.split(/(?<=[.!?])\s+/)) {
for (const paragraph of paragraphs) expect(paragraph.includes(sentence)).toBe(false);
}
expect(paragraphs).not.toContain(summary);
});
});

describe("the update line", () => {
test("names the version it was given, not a constant", () => {
expect(updateLine("9.8.7-alpha.42")).toContain("quarry_9.8.7-alpha.42_universal.dmg");
expect(
composeNotes("HEAD", "9.8.7-alpha.42", sources(["feat(ui): panel (#231)"])),
).toContain("quarry_9.8.7-alpha.42_universal.dmg");
});
});
Loading
Loading