123456import { spawnSync } from 'bun';7import { existsSync } from 'node:fs';8import { resolveBin } from './release-lib';910const RESET = '\x1b[0m';11const GREEN = '\x1b[32m';12const RED = '\x1b[31m';13const BOLD = '\x1b[1m';14const DIM = '\x1b[2m';15const RUN_FIREFOX_SENDER_ONLY = process.env.PEACH_E2E_FIREFOX === '1';1617interface Step {18 name: string;19 cmd: string[] | (() => string[]);20 cwd?: string;21}2223const steps: Step[] = [24 {25 26 27 28 name: 'Lockfile freshness',29 cmd: ['bun', 'install', '--frozen-lockfile'],30 },31 {32 name: 'TypeScript',33 cmd: () => [resolveBin('tsc'), '--noEmit'],34 },35 {36 name: 'Lint',37 cmd: ['npm', 'run', 'lint'],38 },39 {40 41 42 name: 'Noise WASM provenance',43 cmd: ['node', 'scripts/check-noise-core.mjs'],44 },45 {46 name: 'Chrome build',47 cmd: ['npm', 'run', 'build:chrome'],48 },49 {50 name: 'Firefox build',51 cmd: ['npm', 'run', 'build:firefox'],52 },53 {54 name: 'Tests',55 cmd: ['npm', 'test', '--', '--reporter=verbose'],56 },57 ...(RUN_FIREFOX_SENDER_ONLY58 ? [{59 name: 'Firefox sender context',60 cmd: ['npm', 'run', 'test:firefox:sender'],61 }]62 : []),63];6465function run(step: Step): { ok: boolean; output: string; duration: number } {66 const start = Date.now();67 const cmd = typeof step.cmd === 'function' ? step.cmd() : step.cmd;68 const result = spawnSync(cmd, {69 cwd: step.cwd ?? process.cwd(),70 env: process.env,71 stdout: 'pipe',72 stderr: 'pipe',73 });74 const duration = Date.now() - start;75 const ok = result.exitCode === 0;76 const output = [77 result.stdout?.toString().trim(),78 result.stderr?.toString().trim(),79 ].filter(Boolean).join('\n');8081 return { ok, output, duration };82}8384function formatDuration(ms: number): string {85 if (ms < 1000) return `${ms}ms`;86 return `${(ms / 1000).toFixed(1)}s`;87}8889function printStep(name: string, ok: boolean, duration: number) {90 const icon = ok ? `${GREEN}✓${RESET}` : `${RED}✗${RESET}`;91 const time = `${DIM}${formatDuration(duration)}${RESET}`;92 console.log(` ${icon} ${name.padEnd(20)} ${time}`);93}9495async function main() {96 console.log();97 console.log(`${BOLD}peach-browser CI${RESET}`);98 console.log(`${DIM}${new Date().toLocaleTimeString()}${RESET}`);99 console.log();100101 let failed = false;102 const failures: { name: string; output: string }[] = [];103104 for (const step of steps) {105 process.stdout.write(` ${DIM}…${RESET} ${step.name.padEnd(20)}\r`);106 const result = run(step);107 printStep(step.name, result.ok, result.duration);108109 if (!result.ok) {110 failed = true;111 failures.push({ name: step.name, output: result.output });112 break; 113 }114 }115116 console.log();117118 if (!failed) {119 console.log(`${GREEN}${BOLD}All checks passed.${RESET}`);120 console.log();121122 123 const chromeManifest = 'dist-chrome/manifest.json';124 if (existsSync(chromeManifest)) {125 const manifest = JSON.parse(await Bun.file(chromeManifest).text());126 console.log(`${DIM}Version: ${manifest.version}${RESET}`);127 }128 } else {129 console.log(`${RED}${BOLD}Failed: ${failures[0].name}${RESET}`);130 console.log();131132 133 const output = failures[0].output;134 if (output) {135 136 const lines = output.split('\n');137 const relevant = lines.slice(-30).join('\n');138 console.log(`${DIM}${relevant}${RESET}`);139 }140141 console.log();142 process.exit(1);143 }144}145146main();