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: 'Extension surface',47 cmd: ['npm', 'run', 'test:extension-surface'],48 },49 {50 name: 'Chrome build',51 cmd: ['npm', 'run', 'build:chrome'],52 },53 {54 name: 'Firefox build',55 cmd: ['npm', 'run', 'build:firefox'],56 },57 {58 name: 'Tests',59 cmd: ['npm', 'test', '--', '--reporter=verbose'],60 },61 ...(RUN_FIREFOX_SENDER_ONLY62 ? [{63 name: 'Firefox sender context',64 cmd: ['npm', 'run', 'test:firefox:sender'],65 }]66 : []),67];6869function run(step: Step): { ok: boolean; output: string; duration: number } {70 const start = Date.now();71 const cmd = typeof step.cmd === 'function' ? step.cmd() : step.cmd;72 const result = spawnSync(cmd, {73 cwd: step.cwd ?? process.cwd(),74 env: process.env,75 stdout: 'pipe',76 stderr: 'pipe',77 });78 const duration = Date.now() - start;79 const ok = result.exitCode === 0;80 const output = [81 result.stdout?.toString().trim(),82 result.stderr?.toString().trim(),83 ].filter(Boolean).join('\n');8485 return { ok, output, duration };86}8788function formatDuration(ms: number): string {89 if (ms < 1000) return `${ms}ms`;90 return `${(ms / 1000).toFixed(1)}s`;91}9293function printStep(name: string, ok: boolean, duration: number) {94 const icon = ok ? `${GREEN}✓${RESET}` : `${RED}✗${RESET}`;95 const time = `${DIM}${formatDuration(duration)}${RESET}`;96 console.log(` ${icon} ${name.padEnd(20)} ${time}`);97}9899async function main() {100 console.log();101 console.log(`${BOLD}peach-browser CI${RESET}`);102 console.log(`${DIM}${new Date().toLocaleTimeString()}${RESET}`);103 console.log();104105 let failed = false;106 const failures: { name: string; output: string }[] = [];107108 for (const step of steps) {109 process.stdout.write(` ${DIM}…${RESET} ${step.name.padEnd(20)}\r`);110 const result = run(step);111 printStep(step.name, result.ok, result.duration);112113 if (!result.ok) {114 failed = true;115 failures.push({ name: step.name, output: result.output });116 break; 117 }118 }119120 console.log();121122 if (!failed) {123 console.log(`${GREEN}${BOLD}All checks passed.${RESET}`);124 console.log();125126 127 const chromeManifest = 'dist-chrome/manifest.json';128 if (existsSync(chromeManifest)) {129 const manifest = JSON.parse(await Bun.file(chromeManifest).text());130 console.log(`${DIM}Version: ${manifest.version}${RESET}`);131 }132 } else {133 console.log(`${RED}${BOLD}Failed: ${failures[0].name}${RESET}`);134 console.log();135136 137 const output = failures[0].output;138 if (output) {139 140 const lines = output.split('\n');141 const relevant = lines.slice(-30).join('\n');142 console.log(`${DIM}${relevant}${RESET}`);143 }144145 console.log();146 process.exit(1);147 }148}149150main();