(args = Bun.argv.slice(2))
| 421 | |
| 422 | /** Run the release benchmark comparison CLI. */ |
| 423 | export async function main(args = Bun.argv.slice(2)) { |
| 424 | const options = await parseArgs(args); |
| 425 | const headPath = options.head ?? releaseBenchmarkPath(options.version, options.releaseDir); |
| 426 | if (!existsSync(headPath)) { |
| 427 | throw new Error( |
| 428 | `Missing release benchmark ${headPath}. Run bun run bench:release before tagging this release.`, |
| 429 | ); |
| 430 | } |
| 431 | |
| 432 | const baseCandidate = options.base |
| 433 | ? { version: path.basename(options.base), path: options.base } |
| 434 | : findPreviousReleaseBenchmark(options.version, options.releaseDir); |
| 435 | if (!baseCandidate) { |
| 436 | throw new Error( |
| 437 | `Missing previous release benchmark in ${options.releaseDir}. Backfill at least one lower stable release benchmark before releasing.`, |
| 438 | ); |
| 439 | } |
| 440 | |
| 441 | const [base, head] = await Promise.all([ |
| 442 | loadBenchmarkRun(baseCandidate.path), |
| 443 | loadBenchmarkRun(headPath), |
| 444 | ]); |
| 445 | const comparison = compareBenchmarkRuns(base, head); |
| 446 | |
| 447 | if (options.out) { |
| 448 | mkdirSync(path.dirname(options.out), { recursive: true }); |
| 449 | writeFileSync(options.out, `${JSON.stringify(comparison, null, 2)}\n`); |
| 450 | } |
| 451 | |
| 452 | const markdown = formatComparisonMarkdown(comparison, { |
| 453 | baseLabel: options.base ?? baseCandidate.version, |
| 454 | headLabel: path.basename(headPath), |
| 455 | }); |
| 456 | process.stdout.write(markdown); |
| 457 | |
| 458 | if (options.summary) { |
| 459 | appendFileSync(options.summary, `\n${markdown}`); |
| 460 | } |
| 461 | |
| 462 | if (comparison.failed) { |
| 463 | throw new Error( |
| 464 | "Release benchmark gate failed. Resolve the regression or use an explicit manual override.", |
| 465 | ); |
| 466 | } |
| 467 | |
| 468 | console.log(`Release benchmark gate passed on ${os.platform()}/${os.arch()}.`); |
| 469 | } |
| 470 | |
| 471 | if (import.meta.main) { |
| 472 | await main(); |
no test coverage detected