import { appendFileSync, readFileSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; import { esc, extractHistory, renderHistory } from './bench-utils.mjs'; const shortSha = process.env.COMMIT_SHA.slice(0, 7); const commitMsg = process.env.COMMIT_MSG; const runUrl = process.env.WORKFLOW_RUN_URL; const oldBody = readFileSync(`${process.env.RUNNER_TEMP}/old-comment.txt`, 'utf8'); const history = extractHistory(oldBody); // Read benchmark results from artifacts function readResult(os) { const file = join('results', `bench-result-${os}`, 'bench-result.json'); try { return JSON.parse(readFileSync(file, 'utf8')); } catch { return null; } } function formatResult(data) { if (!data) return '-'; const prSec = (data.pr / 1000).toFixed(2); const mainSec = (data.main / 1000).toFixed(2); const prIqr = (data.prIqr / 1000).toFixed(2); const mainIqr = (data.mainIqr / 1000).toFixed(2); const diff = data.pr - data.main; const diffSec = `${diff >= 0 ? '+' : ''}${(diff / 1000).toFixed(2)}`; const diffPct = data.main > 0 ? `${diff >= 0 ? '+' : ''}${((diff / data.main) * 100).toFixed(1)}` : 'N/A'; return `${mainSec}s (\u00b1${mainIqr}s) \u2192 ${prSec}s (\u00b1${prIqr}s) \u00b7 ${diffSec}s (${diffPct}%)`; } const ubuntuStr = formatResult(readResult('ubuntu-latest')); const macosStr = formatResult(readResult('macos-latest')); const windowsStr = formatResult(readResult('windows-latest')); const jsonComment = ``; let body = `\n${jsonComment}\n`; body += '## \u26a1 Performance Benchmark\n\n'; body += `\n`; body += `\n`; body += `\n`; body += `\n`; body += `\n`; body += '
Latest commit:${shortSha} ${esc(commitMsg)}
Status:\u2705 Benchmark complete!
Ubuntu:${ubuntuStr}
macOS:${macosStr}
Windows:${windowsStr}
\n\n'; body += '
\nDetails\n\n'; body += '- Packing the repomix repository with `node bin/repomix.cjs`\n'; body += '- Warmup: 2 runs (discarded), interleaved execution\n'; body += '- Measurement: 20 runs / 30 on macOS (median \u00b1 IQR)\n'; body += `- [Workflow run](${runUrl})\n\n`; body += '
'; const historyHtml = renderHistory(history); if (historyHtml) { body += `\n\n
\nHistory\n\n${historyHtml}\n\n
`; } // Write to step summary (without HTML comments) const summaryFile = process.env.GITHUB_STEP_SUMMARY; if (summaryFile) { const summaryBody = body .split('\n') .filter((l) => !l.startsWith('