/** * Recomputes the CI post's results from its raw data. The post publishes this file beside the data: * put every file it lists in one folder and run * * node reproduce.ts --check fails if results.json differs from a fresh run * node reproduce.ts writes results.json * * Node runs the TypeScript directly; nothing needs installing. In our repository, scripts/research.ts * runs the same computation on the files in data/. */ import { readFileSync, writeFileSync } from 'node:fs'; import { pathToFileURL } from 'node:url'; import { analyzeCiSpeed, parseChangelog, parseMerges, parseRuns, type CI_DATA_FILES } from './analysis.ts'; /** The exact text of results.json, from a reader of the raw data files. */ export function ciResultsText(read: (file: (typeof CI_DATA_FILES)[number]) => string): string { const results = analyzeCiSpeed({ runs: parseRuns(read('ci-runs.jsonl')), merges: parseMerges(read('merges.jsonl')), changelog: parseChangelog(JSON.parse(read('changelog.json'))), }); return `${JSON.stringify(results, null, 2)}\n`; } function main(args: string[]): number { const here = (file: string) => new URL(file, import.meta.url); const fresh = ciResultsText((file) => readFileSync(here(file), 'utf8')); if (!args.includes('--check')) { writeFileSync(here('results.json'), fresh); console.log('wrote results.json'); return 0; } let committed = ''; try { committed = readFileSync(here('results.json'), 'utf8'); } catch { // A missing file is reported as different below. } if (committed !== fresh) { console.error('results.json differs from a fresh run'); return 1; } console.log('results.json matches a fresh run'); return 0; } if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) process.exitCode = main(process.argv.slice(2));