Files
indiekit-server/scripts/patch-micropub-gitea-dispatch-conditional.mjs
Sven 5342cd1ff0
All checks were successful
Deploy Indiekit Server / deploy (push) Successful in 1m11s
fix: skip workflow_dispatch for delete — Gitea DELETE commits trigger on:push
Gitea Contents API DELETE commits fire on:push CI; POST/PUT do not.
delete was triggering both on:push and workflow_dispatch → 2 CI runs.
Now dispatch is skipped for delete; on:push handles the rebuild.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 17:19:34 +02:00

43 lines
1.5 KiB
JavaScript

/**
* Patch: skip workflow_dispatch for delete actions.
*
* Gitea's Contents API DELETE commits DO trigger on:push CI, while
* POST/PUT commits do not. Without this patch, delete fires both
* on:push and workflow_dispatch → 2 CI runs.
*
* create/update/undelete: only dispatch fires (1 CI run) ✓
* delete: only on:push fires (1 CI run) ✓
*/
import { readFile, writeFile, access } from "node:fs/promises";
const TARGET = "node_modules/@indiekit/endpoint-micropub/lib/controllers/action.js";
const MARKER = "// [patch] micropub-gitea-dispatch-conditional";
const OLD = ` _dispatchGiteaBuild().catch(() => {});`;
const NEW = ` if (action !== "delete") _dispatchGiteaBuild().catch(() => {}); ${MARKER}`;
async function exists(p) {
try { await access(p); return true; } catch { return false; }
}
if (!(await exists(TARGET))) {
console.log(`[postinstall] micropub-gitea-dispatch-conditional: target not found, skipping`);
process.exit(0);
}
const source = await readFile(TARGET, "utf8");
if (source.includes(MARKER)) {
console.log("[postinstall] micropub-gitea-dispatch-conditional: already patched");
process.exit(0);
}
if (!source.includes(OLD)) {
console.warn("[postinstall] micropub-gitea-dispatch-conditional: snippet not found — is patch-micropub-gitea-dispatch applied first?");
process.exit(0);
}
await writeFile(TARGET, source.replace(OLD, NEW), "utf8");
console.log(`[postinstall] micropub-gitea-dispatch-conditional: patched ${TARGET}`);