From 3fb0129c46f7bdc427cd3a2c57dfe588cb769a88 Mon Sep 17 00:00:00 2001 From: Christopher Little-Savage Date: Tue, 1 Dec 2026 17:19:44 +0000 Subject: [PATCH 1/2] fix(ci): skip OpenAPI updates that leave generated output unchanged The updater opened PRs that only moved the pin and added a minor changeset, which would ship an empty release. After generation, skip the commit, push and PR when nothing else changed, and close any open managed updater PR with an explanatory comment. Co-Authored-By: Claude Opus 5.5 --- docs/architecture.md | 3 +- scripts/README.md | 4 ++- scripts/update-openapi.test.ts | 57 +++++++++++++++++++++++++++++++ scripts/update-openapi.ts | 61 ++++++++++++++++++++++++++++++---- 4 files changed, 116 insertions(+), 9 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index a4090f27f9..dd7a823a05 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -993,7 +993,8 @@ The two Forge inputs are updated separately: hourly and on an `api-schemas-updated` `repository_dispatch`. It pins the latest `main` commit that changed `openapi.json`, regenerates with the pinned forge build, writes a `minor` changeset, and opens or refreshes the - `automation/update-forge` PR. The existing branch and concurrency group are + `automation/update-forge` PR. A revision that leaves the generated output + unchanged is skipped, and any open updater PR is closed. The existing branch and concurrency group are retained so the renamed workflow continues managing existing update PRs. Both PRs rewrite `_generated/`; whichever merges second is rebased or diff --git a/scripts/README.md b/scripts/README.md index 3eeafec622..8f267edb98 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -17,7 +17,9 @@ repository dispatch. It selects the latest commit on the `main` branch of [cloudflare/api-schemas](https://github.com/cloudflare/api-schemas) that changed `openapi.json`. It regenerates commands with the existing Forge package pin and adds a minor changeset. Generation and `pnpm check` must pass before it -pushes. +pushes. If a revision leaves the generated output unchanged, it skips the +update and closes any open updater PR, so the pin stays on the older revision +until a schema change affects cf. The OpenAPI workflow retains the former `automation/update-forge` branch and `update-forge` concurrency group so it can continue maintaining existing PRs. diff --git a/scripts/update-openapi.test.ts b/scripts/update-openapi.test.ts index 043bfad732..a57b7a2aa1 100644 --- a/scripts/update-openapi.test.ts +++ b/scripts/update-openapi.test.ts @@ -12,6 +12,8 @@ import type { TestContext } from "node:test"; const originalToken = process.env.GH_TOKEN; process.env.GH_TOKEN = "cf-write-token"; const { + changesGeneratedOutput, + closePullRequest, createOrUpdatePullRequest, extractOpenApiVersion, formatError, @@ -165,6 +167,61 @@ await test("a missing API schema repository is reported", async (context) => { assert.deepEqual(requests, ["/repos/cloudflare/api-schemas/commits"]); }); +await test("an update that only moves the pin and adds its changeset is a no-op", () => { + const bookkeeping = [ + "packages/cli/package.json", + `.changeset/update-openapi-${version.slice(0, 12)}.md`, + ]; + assert.equal(changesGeneratedOutput(bookkeeping, version), false); + assert.equal(changesGeneratedOutput([], version), false); + for (const changed of [ + "packages/cli/src/commands/_generated/index.ts", + `.changeset/update-openapi-${"c".repeat(12)}.md`, + "pnpm-lock.yaml", + ]) { + assert.equal( + changesGeneratedOutput([...bookkeeping, changed], version), + true + ); + } +}); + +await test("closing a no-op update PR explains why before closing it", async (context) => { + context.mock.method(console, "log", () => {}); + const requests: { request: string; body: unknown }[] = []; + context.mock.method( + globalThis, + "fetch", + async (url: string, init: RequestInit) => { + assert.equal( + new Headers(init.headers).get("Authorization"), + "Bearer cf-write-token" + ); + requests.push({ + request: `${init.method} ${new URL(url).pathname}`, + body: typeof init.body === "string" ? JSON.parse(init.body) : undefined, + }); + return Response.json({}); + } + ); + await closePullRequest("cloudflare/cf", 865, "no generated changes"); + await closePullRequest("cloudflare/cf", 866); + assert.deepEqual(requests, [ + { + request: "POST /repos/cloudflare/cf/issues/865/comments", + body: { body: "no generated changes" }, + }, + { + request: "PATCH /repos/cloudflare/cf/pulls/865", + body: { state: "closed" }, + }, + { + request: "PATCH /repos/cloudflare/cf/pulls/866", + body: { state: "closed" }, + }, + ]); +}); + await test("the renamed updater recognizes old and new bot commits while protecting human edits", async (context) => { const bot = "41898282+github-actions[bot]@users.noreply.github.com"; const sha = "a".repeat(40); diff --git a/scripts/update-openapi.ts b/scripts/update-openapi.ts index d3029ad5bd..8e28e354fe 100644 --- a/scripts/update-openapi.ts +++ b/scripts/update-openapi.ts @@ -508,13 +508,26 @@ async function assertCleanWorktree(): Promise { } } +function changesetPath(version: string): string { + return `.changeset/update-openapi-${version.slice(0, 12)}.md`; +} + +/** + * Whether an update changes more than its own bookkeeping: the package.json + * pin and the changeset. A schema revision that leaves the generated output + * unchanged would otherwise ship an empty minor release. + */ +export function changesGeneratedOutput( + changedPaths: string[], + version: string +): boolean { + const bookkeeping = new Set([CLI_PACKAGE_JSON, changesetPath(version)]); + return changedPaths.some((path) => !bookkeeping.has(path)); +} + function writeChangeset(version: string): void { - const changesetPath = join( - REPO_ROOT, - `.changeset/update-openapi-${version.slice(0, 12)}.md` - ); writeFileSync( - changesetPath, + join(REPO_ROOT, changesetPath(version)), `--- "cf": minor --- @@ -619,13 +632,20 @@ export async function createOrUpdatePullRequest( } } -async function closePullRequest( +export async function closePullRequest( repository: string, - prNumber: number + prNumber: number, + comment?: string ): Promise { if (!CF_GITHUB_TOKEN) { throw new Error("GH_TOKEN or GITHUB_TOKEN is required to close a PR"); } + if (comment !== undefined) { + await githubJson(`/repos/${repository}/issues/${prNumber}/comments`, { + method: "POST", + body: JSON.stringify({ body: comment }), + }); + } await githubJson(`/repos/${repository}/pulls/${prNumber}`, { method: "PATCH", body: JSON.stringify({ state: "closed" }), @@ -723,6 +743,33 @@ async function main(): Promise { logStep("Regenerating the command surface"); await run("pnpm", ["generate"], { env: forgeEnvironment }); + // The worktree was clean, so this lists every file the update touched. + const changedPaths = ( + await output("git", [ + "ls-files", + "--modified", + "--others", + "--exclude-standard", + ]) + ) + .split("\n") + .filter(Boolean); + if (!changesGeneratedOutput(changedPaths, version)) { + // Leave the pin on the older revision until a schema change affects cf. + // An open PR reached here is a single updater commit (checked above). + if (updatePr !== undefined) { + await closePullRequest( + repository, + updatePr.number, + `Closing because the latest Cloudflare API schemas revision (\`${latest}\`) no longer changes the generated output. A new PR will open when a schema revision changes it.` + ); + } + console.log( + `${latest} does not change the generated output; skipping the update.` + ); + return; + } + logStep("Validating the generated update"); await run("git", ["diff", "--check"], { env: forgeEnvironment }); await run("pnpm", ["check"], { env: forgeEnvironment }); From 0ed31f9a7297ca7ae560c774d474f3748c5566a8 Mon Sep 17 00:00:00 2001 From: Christopher Little-Savage Date: Tue, 1 Dec 2026 17:32:49 +0000 Subject: [PATCH 2/2] fix(ci): leave open updater PRs alone on no-op OpenAPI updates Only skip opening a PR when the generated output is unchanged; don't close or comment on an existing updater PR. Co-Authored-By: Claude Opus 5.5 --- docs/architecture.md | 2 +- scripts/README.md | 4 ++-- scripts/update-openapi.test.ts | 37 ---------------------------------- scripts/update-openapi.ts | 19 ++--------------- 4 files changed, 5 insertions(+), 57 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index dd7a823a05..244093d6e9 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -994,7 +994,7 @@ The two Forge inputs are updated separately: latest `main` commit that changed `openapi.json`, regenerates with the pinned forge build, writes a `minor` changeset, and opens or refreshes the `automation/update-forge` PR. A revision that leaves the generated output - unchanged is skipped, and any open updater PR is closed. The existing branch and concurrency group are + unchanged is skipped. The existing branch and concurrency group are retained so the renamed workflow continues managing existing update PRs. Both PRs rewrite `_generated/`; whichever merges second is rebased or diff --git a/scripts/README.md b/scripts/README.md index 8f267edb98..6cbd7ab4eb 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -18,8 +18,8 @@ repository dispatch. It selects the latest commit on the `main` branch of changed `openapi.json`. It regenerates commands with the existing Forge package pin and adds a minor changeset. Generation and `pnpm check` must pass before it pushes. If a revision leaves the generated output unchanged, it skips the -update and closes any open updater PR, so the pin stays on the older revision -until a schema change affects cf. +update, so the pin stays on the older revision until a schema change affects +cf. The OpenAPI workflow retains the former `automation/update-forge` branch and `update-forge` concurrency group so it can continue maintaining existing PRs. diff --git a/scripts/update-openapi.test.ts b/scripts/update-openapi.test.ts index a57b7a2aa1..cbf226ce2a 100644 --- a/scripts/update-openapi.test.ts +++ b/scripts/update-openapi.test.ts @@ -13,7 +13,6 @@ const originalToken = process.env.GH_TOKEN; process.env.GH_TOKEN = "cf-write-token"; const { changesGeneratedOutput, - closePullRequest, createOrUpdatePullRequest, extractOpenApiVersion, formatError, @@ -186,42 +185,6 @@ await test("an update that only moves the pin and adds its changeset is a no-op" } }); -await test("closing a no-op update PR explains why before closing it", async (context) => { - context.mock.method(console, "log", () => {}); - const requests: { request: string; body: unknown }[] = []; - context.mock.method( - globalThis, - "fetch", - async (url: string, init: RequestInit) => { - assert.equal( - new Headers(init.headers).get("Authorization"), - "Bearer cf-write-token" - ); - requests.push({ - request: `${init.method} ${new URL(url).pathname}`, - body: typeof init.body === "string" ? JSON.parse(init.body) : undefined, - }); - return Response.json({}); - } - ); - await closePullRequest("cloudflare/cf", 865, "no generated changes"); - await closePullRequest("cloudflare/cf", 866); - assert.deepEqual(requests, [ - { - request: "POST /repos/cloudflare/cf/issues/865/comments", - body: { body: "no generated changes" }, - }, - { - request: "PATCH /repos/cloudflare/cf/pulls/865", - body: { state: "closed" }, - }, - { - request: "PATCH /repos/cloudflare/cf/pulls/866", - body: { state: "closed" }, - }, - ]); -}); - await test("the renamed updater recognizes old and new bot commits while protecting human edits", async (context) => { const bot = "41898282+github-actions[bot]@users.noreply.github.com"; const sha = "a".repeat(40); diff --git a/scripts/update-openapi.ts b/scripts/update-openapi.ts index 8e28e354fe..1e9c04955a 100644 --- a/scripts/update-openapi.ts +++ b/scripts/update-openapi.ts @@ -632,20 +632,13 @@ export async function createOrUpdatePullRequest( } } -export async function closePullRequest( +async function closePullRequest( repository: string, - prNumber: number, - comment?: string + prNumber: number ): Promise { if (!CF_GITHUB_TOKEN) { throw new Error("GH_TOKEN or GITHUB_TOKEN is required to close a PR"); } - if (comment !== undefined) { - await githubJson(`/repos/${repository}/issues/${prNumber}/comments`, { - method: "POST", - body: JSON.stringify({ body: comment }), - }); - } await githubJson(`/repos/${repository}/pulls/${prNumber}`, { method: "PATCH", body: JSON.stringify({ state: "closed" }), @@ -756,14 +749,6 @@ async function main(): Promise { .filter(Boolean); if (!changesGeneratedOutput(changedPaths, version)) { // Leave the pin on the older revision until a schema change affects cf. - // An open PR reached here is a single updater commit (checked above). - if (updatePr !== undefined) { - await closePullRequest( - repository, - updatePr.number, - `Closing because the latest Cloudflare API schemas revision (\`${latest}\`) no longer changes the generated output. A new PR will open when a schema revision changes it.` - ); - } console.log( `${latest} does not change the generated output; skipping the update.` );