mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(ci): a catalog publish run that main overtook ends clean instead of failing (#7816)
Every push to main starts its own Publish catalog run, so a run that finds main ahead of its checkout has nothing left to do. It used to throw, which marked 6 of the last 100 main runs red with nothing to fix. Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
c7876f3330
commit
77e675574f
@@ -116,6 +116,9 @@ const endpoint = args[1];
|
||||
const method = args[args.indexOf("--method") + 1];
|
||||
const body = args.includes("--input") ? JSON.parse(fs.readFileSync(0, "utf8")) : undefined;
|
||||
fs.appendFileSync(process.env.API_CALLS, JSON.stringify({ endpoint, method, body }) + "\\n");
|
||||
const mainAdvanced = () =>
|
||||
process.env.MAIN_ADVANCES === "before" ||
|
||||
(process.env.MAIN_ADVANCES === "after-commit" && fs.readFileSync(process.env.API_CALLS, "utf8").includes('"graphql"'));
|
||||
if (!process.env.PUBLISH_SUCCESS && (endpoint === "graphql" || method === "DELETE")) {
|
||||
console.error(endpoint === "graphql" ? "commit rejected" : "cleanup rejected");
|
||||
process.exit(1);
|
||||
@@ -123,7 +126,7 @@ if (!process.env.PUBLISH_SUCCESS && (endpoint === "graphql" || method === "DELET
|
||||
if (endpoint === "graphql") console.log("c".repeat(40));
|
||||
else if (endpoint.includes("/runs?")) console.log(JSON.stringify({ workflow_runs: JSON.parse(process.env.WORKFLOW_RUNS || "[]") }));
|
||||
else if (endpoint.endsWith("/dispatches") && process.env.DISPATCH_FAIL) process.exit(1);
|
||||
else if (endpoint.endsWith("/ref/heads/main")) console.log(process.env.BASE);
|
||||
else if (endpoint.endsWith("/ref/heads/main")) console.log(mainAdvanced() ? "b".repeat(40) : process.env.BASE);
|
||||
else if (endpoint.includes("/matching-refs/")) console.log(process.env.NO_BRANCH ? "" : "refs/heads/bot/catalog-publish");
|
||||
else if (endpoint.includes("/ref/heads/bot/catalog-publish")) console.log("a".repeat(40));
|
||||
else if (endpoint.includes("/pulls?")) console.log(process.env.NO_OPEN_PR ? "" : "42");
|
||||
@@ -191,6 +194,29 @@ test("reverting unpublished sources closes the obsolete PR and resets its branch
|
||||
);
|
||||
});
|
||||
|
||||
test("a run that main overtook before it started ends clean and writes nothing", (t) => {
|
||||
const fixture = publicationFixture(t, true, { MAIN_ADVANCES: "before" });
|
||||
assert.match(fixture.run(), /^::notice::Main advanced during publication/m);
|
||||
assert.deepEqual(
|
||||
fixture.calls().filter((call) => call.method !== "GET"),
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
test("a run that main overtook after its commits ends clean and leaves the publication alone", (t) => {
|
||||
const fixture = publicationFixture(t, true, {
|
||||
MAIN_ADVANCES: "after-commit",
|
||||
PUBLISH_SUCCESS: "1",
|
||||
});
|
||||
assert.match(fixture.run(), /^::notice::Main advanced during publication/m);
|
||||
const writes = fixture.calls().filter((call) => call.method !== "GET");
|
||||
assert.equal(writes.at(-1).method, "DELETE");
|
||||
assert.equal(
|
||||
writes.some((call) => call.method === "PATCH" || call.endpoint.endsWith("/dispatches")),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test("a failed staging cleanup preserves the publication failure as well", (t) => {
|
||||
const fixture = publicationFixture(t, true);
|
||||
assert.throws(fixture.run, (error) => {
|
||||
|
||||
@@ -229,10 +229,14 @@ function actionEnvironment() {
|
||||
return { repository, run, endpoint: `repos/${repository}/git` };
|
||||
}
|
||||
|
||||
class MainAdvanced extends Error {}
|
||||
|
||||
function assertCurrentMain(endpoint, base) {
|
||||
const current = commitOid(api(`${endpoint}/ref/heads/main`, "GET", undefined, ".object.sha"));
|
||||
if (current !== base)
|
||||
throw new Error("Main advanced during publication; the next push run will regenerate it.");
|
||||
throw new MainAdvanced(
|
||||
"Main advanced during publication; the next push run will regenerate it.",
|
||||
);
|
||||
}
|
||||
|
||||
function updateStandingBranch(endpoint, exists, head) {
|
||||
@@ -334,6 +338,15 @@ function publishSnapshot(context, base, exists, batches) {
|
||||
}
|
||||
|
||||
export function publish(root) {
|
||||
try {
|
||||
publishMain(root);
|
||||
} catch (error) {
|
||||
if (!(error instanceof MainAdvanced)) throw error;
|
||||
console.log(`::notice::${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function publishMain(root) {
|
||||
const base = commitOid(git(root, ["rev-parse", "HEAD"]));
|
||||
const changes = catalogChanges(root, base);
|
||||
const batches = commitBatches(changes);
|
||||
|
||||
Reference in New Issue
Block a user