Files
paseo/scripts/stamp-rollout.mjs
T
Mohamed Boudra 47171b419b fix(release): run release scripts as main on Windows runners (#4474)
The ESM main-module guard compared import.meta.url with "file://" + process.argv[1],
which never matches on Windows (file://D:\a\... vs file:///D:/a/...). On the Windows
desktop release job, scripts/github-release.mjs therefore printed nothing and
gh release upload received an empty release lookup ("release not found"), leaving
v0.8.0-beta.1 without a Windows build. Compare resolved paths instead, shared by
every release script that runs as a CLI.
2026-09-08 11:07:13 +02:00

48 lines
1.6 KiB
JavaScript

import fs from "node:fs";
import { dump, load } from "js-yaml";
import { isMainModule } from "./is-main-module.mjs";
export function stampRollout({ releaseDate, rolloutHours }, paths) {
if (releaseDate === undefined && rolloutHours === undefined) {
throw new Error("stampRollout requires at least one of releaseDate or rolloutHours");
}
for (const filePath of paths) {
const manifest = load(fs.readFileSync(filePath, "utf8")) ?? {};
const next = { ...manifest };
if (releaseDate !== undefined) next.releaseDate = releaseDate;
if (rolloutHours !== undefined) next.rolloutHours = rolloutHours;
fs.writeFileSync(filePath, dump(next, { lineWidth: -1, noRefs: true }));
}
}
function parseArgs(argv) {
const opts = {};
const paths = [];
for (let i = 0; i < argv.length; i++) {
const arg = argv[i];
if (arg === "--release-date") {
opts.releaseDate = argv[++i];
} else if (arg === "--rollout-hours") {
const raw = argv[++i];
const parsed = Number(raw);
if (!Number.isFinite(parsed) || parsed < 0) {
throw new Error(`--rollout-hours must be a non-negative number, got ${raw}`);
}
opts.rolloutHours = parsed;
} else {
paths.push(arg);
}
}
return { opts, paths };
}
if (isMainModule(import.meta.url)) {
const { opts, paths } = parseArgs(process.argv.slice(2));
if (paths.length === 0 || (opts.releaseDate === undefined && opts.rolloutHours === undefined)) {
throw new Error(
"Usage: node scripts/stamp-rollout.mjs [--release-date <iso>] [--rollout-hours <n>] <yaml-path>...",
);
}
stampRollout(opts, paths);
}