Files
client/scripts/check-version.mjs
T
2026-10-24 06:34:33 +03:00

27 lines
1.3 KiB
JavaScript

// On a tag build, refuses to continue unless the tag equals v<package.json version> and the core's
// Cargo package version is the same. A release candidate (package.json 0.1.2-rc.1) ships the core of
// its target version (0.1.2), so for prerelease app versions the core must equal the version without
// the prerelease part. Branch/manual builds pass through.
// GITHUB_REF=refs/tags/v0.1.0 node scripts/check-version.mjs
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const app = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')).version;
const cargo = /^\[package\][\s\S]*?^version\s*=\s*"([^"]+)"/m.exec(readFileSync(path.join(root, 'core', 'Cargo.toml'), 'utf8'))?.[1];
const ref = process.env.GITHUB_REF ?? '';
console.log(`package.json ${app}, core Cargo.toml ${cargo}, ref ${ref || '(none)'}`);
const rc = /^(\d+\.\d+\.\d+)-rc\.\d+$/.exec(app);
if (app !== cargo && !(rc && rc[1] === cargo)) {
console.error('package.json and core/Cargo.toml versions differ');
process.exit(1);
}
if (ref.startsWith('refs/tags/')) {
const tag = ref.slice('refs/tags/'.length);
if (tag !== `v${app}`) {
console.error(`tag ${tag} does not match version v${app}`);
process.exit(1);
}
}