fix(release): recognize conventional titles in GitHub merge commits
This commit is contained in:
+3
-1
@@ -75,7 +75,9 @@ to the bot branch can create new approval-required runs; approval of an older
|
||||
head does not verify the normalized candidate. Wait for the final head's CI.
|
||||
|
||||
The validator reads the actual ancestry range from the published baseline tag
|
||||
to the selected checkpoint, including visible first-parent Conventional Commits.
|
||||
to the selected checkpoint, including visible first-parent Conventional Commits
|
||||
and the PR titles in GitHub's default merge messages. The report preserves the
|
||||
original merge subject alongside the extracted Conventional Commit title.
|
||||
This matters after merging a side-branch release back into a newer main:
|
||||
Release Please's chronological history cutoff can omit unreleased mainline
|
||||
commits. Unreleased breaking markers require a major increment and references
|
||||
|
||||
@@ -9,6 +9,20 @@ const sectionsSchema = z.object({
|
||||
z.object({ type: z.string(), hidden: z.boolean().optional() }),
|
||||
),
|
||||
});
|
||||
const GITHUB_MERGE_SUBJECT = /^Merge pull request #(\d+) from \S+/u;
|
||||
|
||||
function conventionalTitle(subject, body) {
|
||||
if (!GITHUB_MERGE_SUBJECT.test(subject)) return subject;
|
||||
// GitHub's default merge message puts the PR title after its subject.
|
||||
// Inspect that first nonempty line, not arbitrary examples in commit prose.
|
||||
return (
|
||||
body
|
||||
.split(/\r?\n/u)
|
||||
.slice(1)
|
||||
.find((line) => line.trim() !== "")
|
||||
?.trim() ?? subject
|
||||
);
|
||||
}
|
||||
|
||||
function releaseVersion(value, location) {
|
||||
if (valid(value) !== value || value.includes("+")) {
|
||||
@@ -48,13 +62,15 @@ function readCommits(text) {
|
||||
const sha = shaSchema.parse(fields[index]);
|
||||
const subject = z.string().parse(fields[index + 1]);
|
||||
const body = z.string().parse(fields[index + 2]);
|
||||
const type = /^([a-z]+)(?:\([^)]*\))?!?: /u.exec(subject)?.[1];
|
||||
const title = conventionalTitle(subject, body);
|
||||
const type = /^([a-z]+)(?:\([^)]*\))?!?: /u.exec(title)?.[1];
|
||||
commits.push({
|
||||
sha,
|
||||
subject,
|
||||
...(title !== subject ? { conventionalTitle: title } : {}),
|
||||
type,
|
||||
breaking:
|
||||
/^[a-z]+(?:\([^)]*\))?!: /u.test(subject) ||
|
||||
/^[a-z]+(?:\([^)]*\))?!: /u.test(title) ||
|
||||
/^BREAKING(?: CHANGE|-CHANGE):\s*\S/mu.test(body),
|
||||
});
|
||||
}
|
||||
@@ -63,7 +79,9 @@ function readCommits(text) {
|
||||
|
||||
function referencesCommit(text, commit) {
|
||||
if (text.includes(commit.sha.slice(0, 7))) return true;
|
||||
const pullRequest = /\(#(\d+)\)$/u.exec(commit.subject)?.[1];
|
||||
const pullRequest =
|
||||
GITHUB_MERGE_SUBJECT.exec(commit.subject)?.[1] ??
|
||||
/\(#(\d+)\)$/u.exec(commit.subject)?.[1];
|
||||
return (
|
||||
pullRequest !== undefined &&
|
||||
new RegExp(`#${pullRequest}(?!\\d)`, "u").test(text)
|
||||
|
||||
@@ -75,6 +75,7 @@ async function metadata(directory: string, version: string, notes: string) {
|
||||
async function fixture(
|
||||
subject = "fix(contracts)!: require absolute paths (#948)",
|
||||
footer = "",
|
||||
options: { mergePullRequest?: boolean } = {},
|
||||
) {
|
||||
const directory = await createTestTempDirectory("rea-release-ancestry-");
|
||||
await git(directory, ["init", "--initial-branch=main"]);
|
||||
@@ -92,6 +93,9 @@ async function fixture(
|
||||
const releasedSha = await git(directory, ["rev-parse", "HEAD"]);
|
||||
await git(directory, ["tag", "rea-agents-5.0.0"]);
|
||||
await git(directory, ["switch", "main"]);
|
||||
if (options.mergePullRequest) {
|
||||
await git(directory, ["switch", "-c", "change/contracts"]);
|
||||
}
|
||||
await writeFile(
|
||||
join(directory, "behavior.txt"),
|
||||
"Unreleased mainline behavior\n",
|
||||
@@ -102,6 +106,22 @@ async function fixture(
|
||||
["commit", "-m", subject, "-m", footer],
|
||||
"2026-01-02T00:00:00Z",
|
||||
);
|
||||
if (options.mergePullRequest) {
|
||||
await git(directory, ["switch", "main"]);
|
||||
await git(
|
||||
directory,
|
||||
[
|
||||
"merge",
|
||||
"--no-ff",
|
||||
"change/contracts",
|
||||
"-m",
|
||||
"Merge pull request #948 from fixture/absolute-paths",
|
||||
"-m",
|
||||
subject,
|
||||
],
|
||||
"2026-01-02T00:00:00Z",
|
||||
);
|
||||
}
|
||||
const changedSha = await git(directory, ["rev-parse", "HEAD"]);
|
||||
await git(directory, [
|
||||
"merge",
|
||||
@@ -159,12 +179,18 @@ const reportSchema = z.object({
|
||||
baselineVersion: z.string(),
|
||||
applicationSha: z.string(),
|
||||
commits: z.array(
|
||||
z.object({ sha: z.string(), subject: z.string(), breaking: z.boolean() }),
|
||||
z.object({
|
||||
sha: z.string(),
|
||||
subject: z.string(),
|
||||
conventionalTitle: z.string().optional(),
|
||||
breaking: z.boolean(),
|
||||
}),
|
||||
),
|
||||
missingNotes: z.array(
|
||||
z.object({
|
||||
sha: z.string(),
|
||||
subject: z.string(),
|
||||
conventionalTitle: z.string().optional(),
|
||||
type: z.string().optional(),
|
||||
breaking: z.boolean(),
|
||||
}),
|
||||
@@ -213,6 +239,54 @@ it("rejects a requested minor that omits the breaking ancestry", async () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a minor when a GitHub merge commit carries its bang marker in the PR title", async () => {
|
||||
const f = await fixture("fix(contracts)!: require absolute paths", "", {
|
||||
mergePullRequest: true,
|
||||
});
|
||||
await expect(verify(f, "5.1.0", "prepare", "source")).rejects.toMatchObject({
|
||||
code: 1,
|
||||
stderr: expect.stringContaining("contains unreleased breaking markers"),
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
subject: "fix(contracts)!: require absolute paths",
|
||||
version: "6.0.0",
|
||||
breaking: true,
|
||||
},
|
||||
{ subject: "fix: improve diagnostics", version: "5.0.1", breaking: false },
|
||||
])(
|
||||
"recognizes GitHub merge titles and PR note references for $version",
|
||||
async ({ subject, version, breaking }) => {
|
||||
const f = await fixture(subject, "", { mergePullRequest: true });
|
||||
await candidate(
|
||||
f,
|
||||
version,
|
||||
`${breaking ? "### ⚠ BREAKING CHANGES" : "### Bug Fixes"}\n\nSee #948 for the change and migration.`,
|
||||
);
|
||||
const report = reportSchema.parse(
|
||||
JSON.parse((await verify(f, version)).stdout),
|
||||
);
|
||||
expect(report.missingNotes).toEqual([]);
|
||||
expect(report.commits).toContainEqual({
|
||||
sha: f.changedSha,
|
||||
subject: "Merge pull request #948 from fixture/absolute-paths",
|
||||
conventionalTitle: subject,
|
||||
breaking,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("does not treat an ordinary body example as a merge title or breaking declaration", async () => {
|
||||
const f = await fixture(
|
||||
"fix: improve diagnostics",
|
||||
"Example subject:\n\nfix(contracts)!: example only",
|
||||
);
|
||||
await candidate(f, "5.0.1", `### Bug Fixes\n\n${f.changedSha}`);
|
||||
await expect(verify(f, "5.0.1")).resolves.toMatchObject({ stderr: "" });
|
||||
});
|
||||
|
||||
it("cannot satisfy migration references with notes retained from an older release", async () => {
|
||||
const f = await fixture();
|
||||
await candidate(
|
||||
|
||||
Reference in New Issue
Block a user