Files
DeepSeek-Reasonix/scripts/brew-cask-guard.mjs
T
esengine f89c934e47 ci(release): the Homebrew cask is written only after the CLI release it points at exists, and never moves backwards
cli-channels and cli-pointer both waited only for cli-tag, so the cask could be
pushed while the v<version> release holding its archives was still being
created, and stayed pointing at nothing if cli-pointer then failed. The cask
step also overwrote the tap whatever its version, so a workflow_dispatch of an
older tag moved Homebrew backwards; it now skips a tap that is ahead and fails
closed when the tap's version cannot be read.
2026-10-04 04:32:09 -07:00

25 lines
1.0 KiB
JavaScript

import { readFileSync, realpathSync } from "node:fs";
import { pathToFileURL } from "node:url";
import { compareSemver } from "../npm/publish.mjs";
const VERSION_LINE = /^\s*version "([^"]+)"\s*$/m;
// Returns "write" when the candidate is not older than the tap's cask, "skip"
// when the tap is ahead; throws when the tap's version cannot be read.
export function caskDecision(caskText, candidate) {
const current = caskText.match(VERSION_LINE)?.[1];
if (!current) throw new Error("the tap's cask has no readable version line; refusing to overwrite it");
return compareSemver(candidate, current) < 0 ? "skip" : "write";
}
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
const [file, candidate] = process.argv.slice(2);
if (!file || !candidate) throw new Error("usage: brew-cask-guard.mjs CASK_FILE VERSION");
try {
console.log(caskDecision(readFileSync(file, "utf8"), candidate));
} catch (error) {
console.error(`::error::${error.message}`);
process.exit(1);
}
}