389 lines
27 KiB
JavaScript
389 lines
27 KiB
JavaScript
#!/usr/bin/env node
|
||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||
// SPDX-License-Identifier: Apache-2.0
|
||
/**
|
||
* The chain of the three repositories, checked and moved in order. pplus-web pins pplus-core (core/) by commit, and
|
||
* core pins pplus-library (core/library/) by commit; a change at the bottom reaches the site only when both pointers
|
||
* move, in that order, and each repository has pushed the commit the one above names. When that was first done by
|
||
* hand it broke twice and nobody saw it for five weeks (a pointer to a commit from before a move, a pointer to a
|
||
* commit that existed only on one machine). This script is the order written down.
|
||
*
|
||
* node scripts/release.mjs check [--offline] [--quick] [--json]
|
||
* Is the chain consistent? For each pointer (web -> core, core -> library):
|
||
* - the commit it names is in the submodule's checkout, the checkout is at it, and has no uncommitted change
|
||
* - it is on the submodule's branch (.gitmodules, `main`) on its remote: asked with `git ls-remote` unless
|
||
* --offline, else read from the last fetch; "cannot tell" when neither can say. A pointer to a commit only
|
||
* this machine has is the failure this exists for.
|
||
* and, unless --quick: the generated files are current (core's `library.mjs emit --check`, `corpus.py emit`
|
||
* writes nothing new, web's `quarto-css.mjs --check`), and Mojo, Node and Python are pinned alike in
|
||
* library/mojo/pin.json, both pixi.toml files and both pixi.lock files. --quick is what tests/chain.test.mjs
|
||
* runs: the pointers and the checkouts only, no network, no build.
|
||
* Exit status 1 when something is wrong (each line says what to run), 0 otherwise ("cannot tell" included).
|
||
*
|
||
* node scripts/release.mjs bump [--commit] [--no-gate]
|
||
* After a change in core/library (committed there) or in core: move core's pointer to the library checkout's
|
||
* commit and regenerate what core derives from the library (library-emit, mojo-emit), run core's gate; then
|
||
* move web's pointer, regenerate what web derives from core (quarto-css), run web's gate; print the commits
|
||
* to push, in order. Without --commit it stages core's new pointer and leaves the regenerated files in the
|
||
* working trees, and prints the commits to make; with --commit it makes them. It never pushes, tags or fetches.
|
||
*
|
||
* Needs a build for everything but --quick (pixi run release-check and release-bump build first). Commands run with
|
||
* the node and python on the PATH, which under pixi are the pinned ones.
|
||
*/
|
||
import fs from 'node:fs';
|
||
import path from 'node:path';
|
||
import { spawnSync } from 'node:child_process';
|
||
import { fileURLToPath } from 'node:url';
|
||
|
||
export const WEB = fileURLToPath(new URL('..', import.meta.url));
|
||
|
||
/* ------------------------------------------------------------------ */
|
||
/* git */
|
||
/* ------------------------------------------------------------------ */
|
||
|
||
const NO_PROMPT = { ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_SSH_COMMAND: process.env.GIT_SSH_COMMAND || 'ssh -o BatchMode=yes -o ConnectTimeout=10' };
|
||
|
||
/** Run git in dir; the trimmed stdout, or null when it fails. */
|
||
function git(dir, args, { timeout = 30000 } = {}) {
|
||
const r = spawnSync('git', ['-C', dir, ...args], { encoding: 'utf8', env: NO_PROMPT, timeout });
|
||
return r.status === 0 ? r.stdout.trim() : null;
|
||
}
|
||
const hasGit = () => spawnSync('git', ['--version']).status === 0;
|
||
const isCheckout = (dir) => fs.existsSync(path.join(dir, '.git')) && git(dir, ['rev-parse', '--is-inside-work-tree']) === 'true';
|
||
const short = (sha) => (sha ? sha.slice(0, 10) : '?');
|
||
|
||
/** The submodules a repository's .gitmodules names: path, url and branch (main when it names none). */
|
||
function submodules(dir) {
|
||
const file = path.join(dir, '.gitmodules');
|
||
if (!fs.existsSync(file)) return [];
|
||
const out = [];
|
||
let cur = null;
|
||
for (const line of fs.readFileSync(file, 'utf8').split('\n')) {
|
||
const head = /^\s*\[submodule "([^"]+)"\]/.exec(line);
|
||
if (head) { cur = { name: head[1], branch: 'main' }; out.push(cur); continue; }
|
||
const kv = /^\s*(\w+)\s*=\s*(.+?)\s*$/.exec(line);
|
||
if (cur && kv) cur[kv[1]] = kv[2];
|
||
}
|
||
return out.filter((s) => s.path);
|
||
}
|
||
|
||
/** The commit a repository's index records for a submodule path (what the next commit will pin). */
|
||
function pointer(dir, sub) {
|
||
const line = git(dir, ['ls-files', '--stage', '--', sub]);
|
||
const m = line && /^160000 ([0-9a-f]{40}) /.exec(line);
|
||
return m ? m[1] : null;
|
||
}
|
||
|
||
/** A repository's name: its package.json's, else its remote's (pplus-library has no package.json). */
|
||
function repoName(dir, url = null) {
|
||
const pkg = path.join(dir, 'package.json');
|
||
if (fs.existsSync(pkg)) { try { return JSON.parse(fs.readFileSync(pkg, 'utf8')).name; } catch { /* below */ } }
|
||
return path.basename(url || git(dir, ['remote', 'get-url', 'origin']) || dir).replace(/\.git$/, '');
|
||
}
|
||
|
||
/** The links of the chain from a root: web -> core -> library, each a parent, a submodule path and the child dir. */
|
||
export function chain(root = WEB) {
|
||
const links = [];
|
||
const walk = (dir, label) => {
|
||
for (const s of submodules(dir)) {
|
||
const child = path.join(dir, s.path);
|
||
const childLabel = repoName(child, s.url);
|
||
links.push({ parent: dir, parentLabel: label, path: s.path, child, childLabel, branch: s.branch, url: s.url });
|
||
walk(child, childLabel);
|
||
}
|
||
};
|
||
walk(root, repoName(root));
|
||
return links;
|
||
}
|
||
const rel = (dir) => path.relative(WEB, dir) || '.';
|
||
|
||
/* ------------------------------------------------------------------ */
|
||
/* check */
|
||
/* ------------------------------------------------------------------ */
|
||
|
||
/**
|
||
* The cheap half of check: every pointer names a commit its checkout has, and the checkout is at it. Returns a list
|
||
* of { level: 'problem' | 'note', text, unread? } (unread: there were no pointers to read). Used by tests/chain.test.mjs, so `npm test` says when a pointer is broken.
|
||
* @param {string} [root] the repository at the top of the chain (default: this one)
|
||
*/
|
||
export function quickCheck(root = WEB) {
|
||
const out = [];
|
||
if (!hasGit()) return [{ level: 'note', unread: true, text: 'git is not on the PATH: the pointers cannot be read' }];
|
||
if (!isCheckout(root)) return [{ level: 'note', unread: true, text: `${root} is not a git checkout (a package, say): no pointers to read` }];
|
||
for (const l of chain(root)) {
|
||
const name = `${l.parentLabel} -> ${l.childLabel} (${rel(l.child)})`;
|
||
const sha = pointer(l.parent, l.path);
|
||
if (!sha) { out.push({ level: 'problem', text: `${name}: ${l.parentLabel} records no commit for ${l.path}` }); continue; }
|
||
if (!isCheckout(l.child)) {
|
||
out.push({ level: 'problem', text: `${name}: ${rel(l.child)} is not checked out. Fix: git submodule update --init --recursive` });
|
||
continue;
|
||
}
|
||
const head = git(l.child, ['rev-parse', 'HEAD']);
|
||
if (git(l.child, ['cat-file', '-e', `${sha}^{commit}`]) === null) {
|
||
out.push({ level: 'problem', text: `${name}: ${l.parentLabel} pins ${short(sha)}, and ${rel(l.child)} does not have that commit. Fix: git submodule update --init --recursive (it fetches the pinned commit); if no remote has it either, it was never pushed: push ${l.childLabel} from the machine that made it, then this` });
|
||
continue;
|
||
}
|
||
if (head === sha) continue;
|
||
if (git(l.child, ['merge-base', '--is-ancestor', head, sha]) !== null) {
|
||
out.push({ level: 'problem', text: `${name}: ${rel(l.child)} is at ${short(head)}, behind the pinned ${short(sha)}, so everything built and tested here uses an older ${l.childLabel}. Fix: git submodule update --recursive` });
|
||
} else if (git(l.child, ['merge-base', '--is-ancestor', sha, head]) !== null) {
|
||
const n = git(l.child, ['rev-list', '--count', `${sha}..${head}`]);
|
||
out.push({ level: 'note', text: `${name}: ${rel(l.child)} is ${n} commit(s) ahead of the pinned ${short(sha)}; when they are done, move the pointer (pixi run release-bump)` });
|
||
} else {
|
||
out.push({ level: 'problem', text: `${name}: ${rel(l.child)} is at ${short(head)}, which is neither the pinned ${short(sha)} nor after it. Fix: git submodule update --recursive, or, if ${short(head)} is the one wanted, pixi run release-bump` });
|
||
}
|
||
}
|
||
return out;
|
||
}
|
||
|
||
/** Is a commit on the branch of the submodule's remote? { level, text } with level ok, problem or unknown. */
|
||
function onRemoteBranch(l, sha, offline) {
|
||
const dir = l.child;
|
||
const tracking = `origin/${l.branch}`;
|
||
if (!offline) {
|
||
const r = spawnSync('git', ['-C', dir, 'ls-remote', '--heads', 'origin', l.branch], { encoding: 'utf8', env: NO_PROMPT, timeout: 20000 });
|
||
if (r.status === 0) {
|
||
const remoteHead = r.stdout.split('\n')[0]?.split('\t')[0];
|
||
if (!remoteHead) return { level: 'problem', text: `the remote has no branch ${l.branch}` };
|
||
if (remoteHead === sha) return { level: 'ok', text: `${short(sha)} is the head of ${l.branch} on the remote` };
|
||
if (git(dir, ['cat-file', '-e', `${remoteHead}^{commit}`]) === null) return { level: 'unknown', text: `cannot tell: the remote's ${l.branch} is at ${short(remoteHead)}, which this checkout has not fetched (git -C ${rel(dir)} fetch, then check again)` };
|
||
if (git(dir, ['merge-base', '--is-ancestor', sha, remoteHead]) !== null) return { level: 'ok', text: `${short(sha)} is on ${l.branch} on the remote (at ${short(remoteHead)})` };
|
||
return { level: 'problem', text: `${short(sha)} is not on ${l.branch} on the remote (at ${short(remoteHead)}), so a clone of ${l.childLabel}'s ${l.branch} does not have it. Push ${l.childLabel} first; the order is library, core, web` };
|
||
}
|
||
}
|
||
const why = offline ? '--offline' : 'the remote could not be asked';
|
||
if (git(dir, ['rev-parse', '--verify', '--quiet', `refs/remotes/${tracking}`]) === null) return { level: 'unknown', text: `cannot tell: ${why}, and there is no ${tracking} from an earlier fetch` };
|
||
if (git(dir, ['merge-base', '--is-ancestor', sha, `refs/remotes/${tracking}`]) !== null) return { level: 'ok', text: `${short(sha)} is on ${tracking} as of the last fetch (${why})` };
|
||
return { level: 'unknown', text: `cannot tell for sure (${why}): ${short(sha)} is not on ${tracking} as of the last fetch, so it is unpushed or was pushed after that fetch; if unpushed, push ${l.childLabel} to ${l.branch} first` };
|
||
}
|
||
|
||
/** Run a command in dir; { ok, out }. */
|
||
function sh(dir, cmd, args, opts = {}) {
|
||
const r = spawnSync(cmd, args, { cwd: dir, encoding: 'utf8', maxBuffer: 64 << 20, ...opts });
|
||
return { ok: r.status === 0, status: r.status, out: `${r.stdout || ''}${r.stderr || ''}`.trim(), missing: r.error?.code === 'ENOENT' };
|
||
}
|
||
const python = () => (spawnSync('python3', ['--version']).status === 0 ? 'python3' : spawnSync('python', ['--version']).status === 0 ? 'python' : null);
|
||
|
||
/** Every file under the given directories of dir. */
|
||
function filesUnder(dir, watched) {
|
||
const out = [];
|
||
const walk = (p) => { if (!fs.existsSync(p)) return; if (fs.statSync(p).isDirectory()) for (const e of fs.readdirSync(p)) walk(path.join(p, e)); else out.push(p); };
|
||
for (const w of watched) walk(path.join(dir, w));
|
||
return out;
|
||
}
|
||
|
||
/** Run a generator and say which files under `watched` it changed or added; then put them back as they were. */
|
||
function writesNothing(dir, watched, cmd, args) {
|
||
const before = new Map(filesUnder(dir, watched).map((f) => [f, fs.readFileSync(f)]));
|
||
const r = sh(dir, cmd, args);
|
||
const changed = [];
|
||
for (const [f, buf] of before) if (!fs.existsSync(f) || !fs.readFileSync(f).equals(buf)) { changed.push(path.relative(dir, f)); fs.writeFileSync(f, buf); }
|
||
for (const f of filesUnder(dir, watched)) if (!before.has(f)) { changed.push(path.relative(dir, f)); fs.rmSync(f); }
|
||
return { ...r, changed };
|
||
}
|
||
|
||
/** The version a pixi.toml installs of a package, as written ("==1.2.0", ">=26.10.0,<26.11"). */
|
||
const pixiDep = (text, name) => new RegExp(`^${name} = "([^"]+)"`, 'm').exec(text)?.[1] ?? null;
|
||
|
||
/** Full check: the quick part, the remote, the generated files and the pins. */
|
||
export function fullCheck({ root = WEB, offline = false } = {}) {
|
||
const lines = [];
|
||
const add = (level, where, text) => lines.push({ level, where, text });
|
||
for (const q of quickCheck(root)) add(q.level, 'pointers', q.text);
|
||
const links = chain(root);
|
||
if (!hasGit() || !isCheckout(root)) return lines;
|
||
|
||
for (const l of links) {
|
||
const where = `${l.parentLabel} -> ${l.childLabel}`;
|
||
const sha = pointer(l.parent, l.path);
|
||
if (!sha || git(l.child, ['cat-file', '-e', `${sha}^{commit}`]) === null) continue;
|
||
add('ok', where, `${l.parentLabel} pins ${l.childLabel} at ${short(sha)}${git(l.child, ['rev-parse', 'HEAD']) === sha ? ', and the checkout is there' : ''}`);
|
||
const dirty = git(l.child, ['status', '--porcelain', '--untracked-files=no', '--ignore-submodules=dirty']);
|
||
if (dirty) add('problem', where, `${rel(l.child)} has uncommitted changes, so what is tested here is not what the pointer names: ${dirty.split('\n').slice(0, 5).map((s) => s.trim()).join('; ')}${dirty.split('\n').length > 5 ? '; ...' : ''}. Commit them in ${l.childLabel} (then pixi run release-bump) or put them aside`);
|
||
const untracked = git(l.child, ['ls-files', '--others', '--exclude-standard', '--directory']);
|
||
if (untracked) add('note', where, `${rel(l.child)} has untracked files: ${untracked.split('\n').slice(0, 5).join(', ')}${untracked.split('\n').length > 5 ? ', ...' : ''}`);
|
||
const r = onRemoteBranch(l, sha, offline);
|
||
add(r.level, where, r.text);
|
||
}
|
||
// the top of the chain: its own commit is what the push order ends with; say if it is not on its branch either
|
||
const top = { child: root, childLabel: repoName(root), branch: 'main' };
|
||
const head = git(root, ['rev-parse', 'HEAD']);
|
||
if (head) { const r = onRemoteBranch(top, head, offline); add(r.level === 'problem' ? 'note' : r.level, top.childLabel, `this checkout's own commit: ${r.text}`); }
|
||
|
||
// generated files
|
||
const core = links.find((l) => l.childLabel === 'pplus-core')?.child ?? (fs.existsSync(path.join(root, 'scripts/library.mjs')) ? root : null);
|
||
const lib = core ? path.join(core, 'library') : null;
|
||
if (core) {
|
||
if (!fs.existsSync(path.join(core, 'dist', 'library', 'registry.js'))) add('unknown', 'generated', `cannot tell whether core's registry is current: core is not built (pixi run build)`);
|
||
else {
|
||
const r = sh(core, process.execPath, ['scripts/library.mjs', 'emit', '--check']);
|
||
add(r.ok ? 'ok' : 'problem', 'generated', r.ok ? "core's registry (src/library/generated.ts) is current with the library" : `${r.out}`);
|
||
}
|
||
const py = python();
|
||
if (!py) add('unknown', 'generated', 'cannot tell whether corpus.py emit is current: no python on the PATH (run through pixi)');
|
||
else {
|
||
const r = writesNothing(core, ['src/mojo/generated', 'library/syntax'], py, ['scripts/mojo/corpus.py', 'emit']);
|
||
if (!r.ok) add('problem', 'generated', `corpus.py emit failed: ${r.out.split('\n').slice(-3).join(' ')}`);
|
||
else add(r.changed.length ? 'problem' : 'ok', 'generated', r.changed.length ? `corpus.py emit would change ${r.changed.join(', ')} (put back as they were): run core's mojo-emit task (pixi run --manifest-path core/pixi.toml mojo-emit) and commit the result in core` : 'corpus.py emit writes nothing new (src/mojo/generated/, library/syntax/mojo.xml)');
|
||
}
|
||
}
|
||
if (fs.existsSync(path.join(root, 'scripts/quarto-css.mjs'))) {
|
||
if (!fs.existsSync(path.join(root, 'dist', 'quarto', 'render.js'))) add('unknown', 'generated', 'cannot tell whether the Quarto extension\'s generated files are current: the site is not built (pixi run build)');
|
||
else {
|
||
const r = sh(root, process.execPath, ['scripts/quarto-css.mjs', '--check']);
|
||
add(r.ok ? 'ok' : 'problem', 'generated', r.ok ? "the Quarto extension's generated files are current (quarto-css --check)" : `${r.out.split('\n').slice(-3).join(' ')}: run pixi run quarto-css and commit the result`);
|
||
}
|
||
}
|
||
|
||
// the pins: Mojo, Node and Python alike everywhere
|
||
if (lib && fs.existsSync(path.join(lib, 'mojo', 'pin.json'))) {
|
||
const want = JSON.parse(fs.readFileSync(path.join(lib, 'mojo', 'pin.json'), 'utf8')).mojo.version;
|
||
const wrong = [];
|
||
for (const dir of [core, root === core ? null : root].filter(Boolean)) {
|
||
const toml = fs.readFileSync(path.join(dir, 'pixi.toml'), 'utf8');
|
||
const name = rel(path.join(dir, 'pixi.toml'));
|
||
if (pixiDep(toml, 'mojo') !== `==${want}`) wrong.push(`${name} installs mojo ${pixiDep(toml, 'mojo')}`);
|
||
const lock = fs.existsSync(path.join(dir, 'pixi.lock')) ? fs.readFileSync(path.join(dir, 'pixi.lock'), 'utf8') : '';
|
||
const locked = [...new Set([...lock.matchAll(/\/mojo-(\d+\.\d+\.\d+)-[^/]*\.conda/g)].map((m) => m[1]))];
|
||
if (locked.length !== 1 || locked[0] !== want) wrong.push(`${rel(path.join(dir, 'pixi.lock'))} locks mojo ${locked.join(', ') || 'nowhere'}`);
|
||
}
|
||
const gen = path.join(core, 'src', 'mojo', 'generated', 'pin.ts');
|
||
const genVersion = fs.existsSync(gen) ? /MOJO_VERSION = "([^"]+)"/.exec(fs.readFileSync(gen, 'utf8'))?.[1] : null;
|
||
if (genVersion !== want) wrong.push(`core's src/mojo/generated/pin.ts says ${genVersion}`);
|
||
add(wrong.length ? 'problem' : 'ok', 'pins', wrong.length ? `library/mojo/pin.json pins Mojo ${want}, and ${wrong.join('; ')}` : `Mojo ${want} in library/mojo/pin.json, core's generated pin, every pixi.toml and pixi.lock`);
|
||
if (root !== core) {
|
||
const a = fs.readFileSync(path.join(core, 'pixi.toml'), 'utf8'); const b = fs.readFileSync(path.join(root, 'pixi.toml'), 'utf8');
|
||
const differ = ['nodejs', 'python'].filter((p) => pixiDep(a, p) !== pixiDep(b, p));
|
||
add(differ.length ? 'problem' : 'ok', 'pins', differ.length ? differ.map((p) => `${p}: core pins ${pixiDep(a, p)}, web pins ${pixiDep(b, p)}`).join('; ') : `Node ${pixiDep(a, 'nodejs')} and Python ${pixiDep(a, 'python')} alike in core and web`);
|
||
}
|
||
}
|
||
return lines;
|
||
}
|
||
|
||
/* ------------------------------------------------------------------ */
|
||
/* bump */
|
||
/* ------------------------------------------------------------------ */
|
||
|
||
function step(text) { console.log(`\n== ${text}`); }
|
||
function must(r, what) {
|
||
if (r.ok) return r;
|
||
console.error(r.out.split('\n').slice(-25).join('\n'));
|
||
console.error(`\nrelease bump: ${what} failed; nothing was committed. Fix it and run release-bump again.`);
|
||
process.exit(1);
|
||
}
|
||
const testFiles = (dir) => fs.readdirSync(path.join(dir, 'tests')).filter((f) => f.endsWith('.test.mjs')).sort().map((f) => `tests/${f}`);
|
||
const tsc = () => path.join(WEB, 'node_modules', 'typescript', 'bin', 'tsc');
|
||
/** The tracked files with changes in dir (porcelain lines are "XY path"; read untrimmed, X may be a space). */
|
||
const tracked = (dir) => (spawnSync('git', ['-C', dir, 'status', '--porcelain', '--untracked-files=no', '--ignore-submodules=dirty'], { encoding: 'utf8' }).stdout || '').split('\n').filter(Boolean).map((l) => l.slice(3));
|
||
|
||
/** Move the pointers bottom up; see the header. */
|
||
export function bump({ commit = false, gate = true } = {}) {
|
||
const links = chain(WEB);
|
||
const toCore = links.find((l) => l.childLabel === 'pplus-core');
|
||
const toLib = links.find((l) => l.childLabel === 'pplus-library');
|
||
if (!toCore || !toLib) { console.error('release bump: run it in pplus-web, with core/ and core/library/ checked out (git submodule update --init --recursive)'); process.exit(2); }
|
||
const core = toCore.child; const lib = toLib.child;
|
||
const py = python();
|
||
if (!py) { console.error('release bump: no python on the PATH; run it as pixi run release-bump'); process.exit(2); }
|
||
const push = [];
|
||
// with --commit, a commit must hold the pointer and what was regenerated, and nothing else someone was editing
|
||
const editing = [...tracked(core).filter((f) => f !== 'library').map((f) => `core/${f}`), ...tracked(WEB).filter((f) => f !== 'core')];
|
||
if (commit && editing.length) { console.error(`release bump --commit: there are uncommitted changes that are not the pointers (${editing.join(', ')}); commit or put them aside first, or run without --commit`); process.exit(1); }
|
||
|
||
// 1. the library: committed, and clean
|
||
const libHead = git(lib, ['rev-parse', 'HEAD']);
|
||
const libDirty = tracked(lib);
|
||
if (libDirty.length) { console.error(`release bump: core/library has uncommitted changes (${libDirty.join(', ')}). Commit them in pplus-library first.`); process.exit(1); }
|
||
const libPinned = pointer(core, 'library');
|
||
if (libHead !== libPinned) {
|
||
if (git(lib, ['merge-base', '--is-ancestor', libPinned, libHead]) === null) console.log(`note: the library checkout (${short(libHead)}) does not descend from the commit core pinned (${short(libPinned)})`);
|
||
step(`core: move library from ${short(libPinned)} to ${short(libHead)}, and regenerate what core derives from it`);
|
||
must(sh(core, 'git', ['add', 'library']), 'git add library in core');
|
||
} else step(`core already pins the library checkout (${short(libHead)}); regenerating to be sure`);
|
||
must(sh(WEB, process.execPath, [tsc(), '-p', 'core/tsconfig.json']), 'building core');
|
||
// what core derives from the library; library CI (pplus-library's .gitea/workflows/test.yml) runs the same two
|
||
console.log(must(sh(core, process.execPath, ['scripts/library.mjs', 'emit']), 'library-emit').out);
|
||
console.log(must(sh(core, py, ['scripts/mojo/corpus.py', 'emit']), 'mojo-emit').out.split('\n').slice(-2).join('\n'));
|
||
if (tracked(lib).length) { console.error(`release bump: mojo-emit changed the library (${tracked(lib).join(', ')}): commit that in pplus-library, then run release-bump again`); process.exit(1); }
|
||
must(sh(WEB, process.execPath, [tsc(), '-p', 'core/tsconfig.json']), 'building core again, with the regenerated sources');
|
||
if (gate) {
|
||
step("core's gate: every test, and no program of ours failing");
|
||
const t = must(sh(core, process.execPath, ['--test', ...testFiles(core)]), "core's tests");
|
||
console.log(t.out.split('\n').filter((l) => /^ℹ (tests|pass|fail|skipped)/.test(l)).join('\n'));
|
||
console.log(must(sh(core, py, ['scripts/mojo/corpus.py', 'status', '--strict']), 'mojo-status-strict').out.split('\n').slice(-2).join('\n'));
|
||
console.log(must(sh(core, process.execPath, ['scripts/library.mjs', 'check']), 'library-check').out.split('\n').slice(-1).join('\n'));
|
||
if (tracked(lib).length) { console.error(`release bump: library-check rewrote ${tracked(lib).join(', ')}: the library's records were not current. Commit them in pplus-library, then run release-bump again`); process.exit(1); }
|
||
}
|
||
const coreChanges = tracked(core);
|
||
const coreMsg = `Move pplus-library to ${short(libHead)}, and regenerate what core derives from it`;
|
||
const libBranch = toLib.branch;
|
||
push.push({ repo: 'pplus-library', dir: lib, sha: libHead, branch: libBranch });
|
||
let coreSha = git(core, ['rev-parse', 'HEAD']);
|
||
if (coreChanges.length) {
|
||
if (commit) {
|
||
must(sh(core, 'git', ['add', '--', ...coreChanges]), 'git add in core');
|
||
must(sh(core, 'git', ['commit', '-q', '-m', coreMsg]), 'git commit in core');
|
||
coreSha = git(core, ['rev-parse', 'HEAD']);
|
||
console.log(`committed core ${short(coreSha)}: ${coreMsg}`);
|
||
} else {
|
||
console.log(`\nto commit in core (or run again with --commit):\n git -C core add ${coreChanges.join(' ')}\n git -C core commit -m "${coreMsg}"`);
|
||
}
|
||
} else console.log('core: nothing to commit');
|
||
push.push({ repo: 'pplus-core', dir: core, sha: coreChanges.length && !commit ? null : coreSha, branch: toCore.branch });
|
||
|
||
// 2. web: pointer to core's commit, regenerate, gate
|
||
const corePinned = pointer(WEB, 'core');
|
||
const coreMoved = coreSha !== corePinned || (coreChanges.length && !commit);
|
||
if (commit && coreSha !== corePinned) { step(`web: move core from ${short(corePinned)} to ${short(coreSha)}`); must(sh(WEB, 'git', ['add', 'core']), 'git add core in web'); }
|
||
else if (!coreMoved) step(`web already pins core at ${short(coreSha)}`);
|
||
else step("web: built and tested against core's working tree (the pointer moves when core's commit exists)");
|
||
must(sh(WEB, process.execPath, [tsc(), '-p', 'tsconfig.json']), 'building the site');
|
||
console.log(must(sh(WEB, process.execPath, ['scripts/quarto-css.mjs']), 'quarto-css').out.split('\n').slice(-2).join('\n'));
|
||
if (gate) {
|
||
step("web's gate: every test of the site");
|
||
const t = must(sh(WEB, process.execPath, ['--test', ...testFiles(WEB)]), "the site's tests");
|
||
console.log(t.out.split('\n').filter((l) => /^ℹ (tests|pass|fail|skipped)/.test(l)).join('\n'));
|
||
}
|
||
const webChanges = tracked(WEB);
|
||
const webMsg = `Move pplus-core to ${short(coreSha)}`;
|
||
let webSha = git(WEB, ['rev-parse', 'HEAD']);
|
||
if (webChanges.length && commit) {
|
||
must(sh(WEB, 'git', ['add', '--', ...webChanges]), 'git add in web');
|
||
must(sh(WEB, 'git', ['commit', '-q', '-m', webMsg]), 'git commit in web');
|
||
webSha = git(WEB, ['rev-parse', 'HEAD']);
|
||
console.log(`committed web ${short(webSha)}: ${webMsg}`);
|
||
} else if (webChanges.length || coreMoved) {
|
||
console.log(`\nto commit in web, after core's commit:\n git add core${webChanges.filter((f) => f !== 'core').map((f) => ` ${f}`).join('')}\n git commit -m "Move pplus-core to <core's new commit>"`);
|
||
}
|
||
push.push({ repo: 'pplus-web', dir: WEB, sha: webChanges.length && !commit ? null : webSha, branch: 'main' });
|
||
|
||
console.log('\nPush in this order, each before the next (a pointer may only name a pushed commit); nothing was pushed:');
|
||
push.forEach((p, i) => console.log(` ${i + 1}. ${p.repo} ${p.sha ? short(p.sha) : '(the commit above, once made)'} to ${p.branch}: git -C ${rel(p.dir)} push origin ${p.sha ?? 'HEAD'}:refs/heads/${p.branch}`));
|
||
console.log('Then pixi run release-check should say every pointer is on its branch.');
|
||
}
|
||
|
||
/* ------------------------------------------------------------------ */
|
||
/* Command line */
|
||
/* ------------------------------------------------------------------ */
|
||
|
||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||
const args = process.argv.slice(2);
|
||
const cmd = args[0];
|
||
if (cmd === 'check') {
|
||
const lines = args.includes('--quick') ? quickCheck().map((q) => ({ ...q, where: 'pointers' })) : fullCheck({ offline: args.includes('--offline') });
|
||
if (args.includes('--json')) console.log(JSON.stringify(lines, null, 2));
|
||
else {
|
||
const tag = { ok: 'ok ', problem: 'PROBLEM ', unknown: 'cannot tell', note: 'note ' };
|
||
for (const l of lines) console.log(`${tag[l.level]} [${l.where}] ${l.text}`);
|
||
const n = (lv) => lines.filter((l) => l.level === lv).length;
|
||
console.log(`\n${n('problem') ? `${n('problem')} problem(s)` : 'the chain is consistent'}${n('unknown') ? `; ${n('unknown')} thing(s) it cannot tell` : ''}`);
|
||
}
|
||
process.exit(lines.some((l) => l.level === 'problem') ? 1 : 0);
|
||
} else if (cmd === 'bump') {
|
||
bump({ commit: args.includes('--commit'), gate: !args.includes('--no-gate') });
|
||
} else {
|
||
console.error('usage: node scripts/release.mjs check [--offline] [--quick] [--json] | bump [--commit] [--no-gate]');
|
||
process.exit(2);
|
||
}
|
||
}
|