58 lines
2.2 KiB
JavaScript
58 lines
2.2 KiB
JavaScript
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
// The release's Nix pin (docs/verify.md): .fabrica/nix/pin.json, written by scripts/nix-pin.sh on
|
|
// Linux and committed before tagging, becomes target/nix/ianitor-nix.json with the tag and the
|
|
// commit, published under SHA256SUMS signed by domi-release. Refuses a pin of another version.
|
|
// node scripts/release-pin.mjs <X.Y.Z> <tag> <commit>
|
|
// Exit codes: 0 written, 1 no pin or a pin of another version, 2 usage.
|
|
|
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const repo = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
const [version, tag, commit] = process.argv.slice(2);
|
|
if (
|
|
process.argv.length !== 5 ||
|
|
!/^\d+\.\d+\.\d+$/.test(version) ||
|
|
!/^[0-9a-f]{40}$/.test(commit ?? "")
|
|
) {
|
|
console.error("usage: node scripts/release-pin.mjs <X.Y.Z> <tag> <commit sha>");
|
|
process.exit(2);
|
|
}
|
|
|
|
let pin;
|
|
try {
|
|
pin = JSON.parse(readFileSync(join(repo, ".fabrica/nix/pin.json"), "utf8"));
|
|
} catch (e) {
|
|
console.error(`no usable .fabrica/nix/pin.json (run scripts/nix-pin.sh on Linux and commit it): ${e.message}`);
|
|
process.exit(1);
|
|
}
|
|
if (pin.version !== version) {
|
|
console.error(`.fabrica/nix/pin.json is for ${pin.version}, the tag is ${version}: run scripts/nix-pin.sh again`);
|
|
process.exit(1);
|
|
}
|
|
for (const attr of ["ianitor", "ianitor-web"]) {
|
|
const o = pin.outputs?.[attr];
|
|
if (!o || !/^\/nix\/store\/[0-9a-z]{32}-/.test(o.storePath) || !/^sha256[-:][A-Za-z0-9+/=]{43,52}$/.test(o.narHash)) {
|
|
console.error(`.fabrica/nix/pin.json: ${attr} has no store path and NAR hash`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
const out = {
|
|
name: "Ianitor Domi",
|
|
version,
|
|
tag,
|
|
commit,
|
|
flake: `git+https://gitea.marek-novak.cz/mnovak/Ianitor.git?rev=${commit}`,
|
|
system: pin.system,
|
|
outputs: pin.outputs,
|
|
verify: "docs/verify.md",
|
|
};
|
|
mkdirSync(join(repo, "target/nix"), { recursive: true });
|
|
writeFileSync(join(repo, "target/nix/ianitor-nix.json"), JSON.stringify(out, null, 2) + "\n");
|
|
console.log(`target/nix/ianitor-nix.json: ${version} at ${commit}`);
|