Skip to content
Open
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
3 changes: 2 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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
Expand Down
4 changes: 3 additions & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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.
Expand Down
20 changes: 20 additions & 0 deletions scripts/update-openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { TestContext } from "node:test";
const originalToken = process.env.GH_TOKEN;
process.env.GH_TOKEN = "cf-write-token";
const {
changesGeneratedOutput,
createOrUpdatePullRequest,
extractOpenApiVersion,
formatError,
Expand Down Expand Up @@ -165,6 +166,25 @@ 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("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);
Expand Down
42 changes: 37 additions & 5 deletions scripts/update-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,26 @@ async function assertCleanWorktree(): Promise<void> {
}
}

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
---
Expand Down Expand Up @@ -723,6 +736,25 @@ async function main(): Promise<void> {
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.
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 });
Expand Down
Loading