Skip to content

Computer use for the Pi coding agent — Windows apps, browsers and desktops through native UI trees, screenshots and real input.

2.0 KB
Raw Blame
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { registryUrl, REPOSITORY, REPOSITORY_OWNER, VERSION_PATTERN } from "./package.ts";
import { synchronizeDevelop } from "./sync-develop.ts";

const version = process.env.RELEASE_VERSION;
if (!version || !VERSION_PATTERN.test(version) || process.env.CONFIRM_CANCEL !== "cancel")
  throw new Error("Explicit release version and cancel confirmation required");
if (process.env.GITHUB_REF !== "refs/heads/main") throw new Error("Cancel releases from main only");
const registry = await fetch(registryUrl(version));
if (registry.status !== 404) throw new Error("Published or registry unavailable; cannot cancel");
const git = (...args: string[]) => execFileSync("git", args, { encoding: "utf8" }).trim();
if (git("tag", "--list", `v${version}`)) throw new Error("Tagged releases cannot be canceled");
const branch = `refs/heads/release/${version}`;
const head = git("ls-remote", "origin", branch).split("\t")[0] ?? "";
if (!/^[0-9a-f]{40}$/.test(head)) throw new Error("No active release branch");
const prs = JSON.parse(execFileSync("gh", ["api", `repos/${REPOSITORY}/pulls?state=all&head=${REPOSITORY_OWNER}:release/${version}`],
  { encoding: "utf8" })) as { number: number; merged_at: string | null; state: string }[];
if (prs.some(pr => pr.merged_at)) {
  const main = JSON.parse(readFileSync("package.json", "utf8")) as { version: string };
  const changelog = readFileSync("CHANGELOG.md", "utf8");
  if (main.version === version && changelog.includes(`## ${version} —`))
    throw new Error("Revert the merged release PR on main and review the rollback before canceling");
}
// Keep the freeze in place if main has not made it back into develop.
synchronizeDevelop();
for (const pr of prs.filter(pr => pr.state === "open")) execFileSync("gh", ["pr", "close", String(pr.number)], { stdio: "inherit" });
execFileSync("git", ["push", `--force-with-lease=${branch}:${head}`, "origin", `:${branch}`], { stdio: "inherit" });