// On a tag build, refuses to continue unless the tag equals v and the core's // Cargo package version is the same. 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)'}`); if (app !== 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); } }