Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(ci): show vs-base delta in the eager graph comment (#63137)

Paul D'Ambra0e84a7b66d0a
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index 04e4c80ed0c7..22bac160fcf9 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -199,17 +199,20 @@ for (const { root, label, budgetBytes, forbidden } of ROOTS) {
}
// Consumed by the workflow's comment + enforcement steps; written even on failure so
-// the PR comment can show what went over. The filename carries the built tree's HEAD
-// sha because compressed-size-action runs this for BOTH the PR build and the base
-// build in the same workspace — a plain filename would be overwritten by the base
-// build, making downstream steps report the wrong branch.
-const serialized = JSON.stringify(report, null, 2)
-fs.writeFileSync(path.join(frontendDir, 'eager-graph-report.json'), serialized)
+// the PR comment can show what went over. The filename and the embedded sha carry the
+// built tree's HEAD because compressed-size-action runs this for BOTH the PR build and
+// the base build in the same workspace — the PR build's report is found by sha, and the
+// plain filename (last write = the base build) doubles as the base-branch measurement
+// for the comment's vs-base delta.
try {
- const headSha = execSync('git rev-parse HEAD', { cwd: frontendDir, encoding: 'utf-8' }).trim()
- fs.writeFileSync(path.join(frontendDir, `eager-graph-report-${headSha}.json`), serialized)
+ report.sha = execSync('git rev-parse HEAD', { cwd: frontendDir, encoding: 'utf-8' }).trim()
} catch (err) {
- console.error(`Could not write sha-specific report: ${err.message}`)
+ console.error(`Could not resolve HEAD sha for the report: ${err.message}`)
+}
+const serialized = JSON.stringify(report, null, 2)
+fs.writeFileSync(path.join(frontendDir, 'eager-graph-report.json'), serialized)
+if (report.sha) {
+ fs.writeFileSync(path.join(frontendDir, `eager-graph-report-${report.sha}.json`), serialized)
}
if (process.env.GITHUB_STEP_SUMMARY) {
diff --git a/frontend/bin/post-eager-graph-comment.mjs b/frontend/bin/post-eager-graph-comment.mjs
index 65c17daa95a1..507006569688 100644
--- a/frontend/bin/post-eager-graph-comment.mjs
+++ b/frontend/bin/post-eager-graph-comment.mjs
@@ -46,6 +46,31 @@ if (!shaReportPath) {
const report = JSON.parse(fs.readFileSync(reportPath, 'utf-8'))
+// The base build runs last (see the write-side comment in check-eager-graph.mjs),
+// so the plain report filename holds the base branch's measurement — the comparison
+// baseline, like the compressed-size check's. The embedded sha guards against the
+// plain file being this PR's own report (the base build didn't run the check, e.g.
+// a base branch that predates it).
+const baseReport = (() => {
+ const candidate = path.join(frontendDir, 'eager-graph-report.json')
+ if (!fs.existsSync(candidate)) {
+ return null
+ }
+ try {
+ const parsed = JSON.parse(fs.readFileSync(candidate, 'utf-8'))
+ if (parsed.sha && report.sha && parsed.sha !== report.sha) {
+ return parsed
+ }
+ } catch {
+ return null
+ }
+ return null
+})()
+const baseBytes = Object.fromEntries((baseReport?.roots ?? []).map((r) => [r.root, r.bytes]))
+if (!baseReport) {
+ console.warn('No base-branch report found — the comment will not show a vs-base delta.')
+}
+
function formatBytes(bytes) {
const abs = Math.abs(bytes)
if (abs >= 1024 * 1024) {
@@ -57,15 +82,21 @@ function formatBytes(bytes) {
return `${bytes} B`
}
-function formatDelta(bytes, previousBytes) {
- if (previousBytes === undefined) {
- return '_(first run)_'
+function formatDelta(bytes, baselineBytes) {
+ if (baselineBytes === undefined) {
+ return '_(no base measurement)_'
}
- const delta = bytes - previousBytes
+ const delta = bytes - baselineBytes
if (delta === 0) {
return 'no change'
}
- return `${delta > 0 ? '+' : '-'}${formatBytes(Math.abs(delta))}`
+ const sign = delta > 0 ? '+' : '-'
+ const magnitude = `${delta > 0 ? '🔺' : '🟢'} ${sign}${formatBytes(Math.abs(delta))}`
+ if (baselineBytes === 0) {
+ return `${magnitude} (new)`
+ }
+ const percent = ((Math.abs(delta) / baselineBytes) * 100).toFixed(1)
+ return `${magnitude} (${sign}${percent}%)`
}
function budgetBar(bytes, budgetBytes) {
@@ -106,31 +137,21 @@ try {
process.exit(0)
}
-const previous = (() => {
- const match = existing?.body?.match(/<!-- posthog-eager-graph-data (.*?) -->/s)
- try {
- return match ? JSON.parse(match[1]) : {}
- } catch {
- return {}
- }
-})()
-
const anyFailure = report.roots.some((r) => r.overBudget || r.forbiddenHits.length > 0) || report.errors?.length > 0
const lines = [
MARKER,
- `<!-- posthog-eager-graph-data ${JSON.stringify(Object.fromEntries(report.roots.map((r) => [r.root, r.bytes])))} -->`,
`## ${anyFailure ? '❌' : '🕸️'} Eager graph`,
'',
"How much code each root forces the browser to download and decode through *static* imports — the regression class total bundle size can't see.",
'',
- '| Root | Eager closure | Δ this PR run | Budget |',
+ '| Root | Eager closure | Δ vs base | Budget |',
'| --- | --- | --- | --- |',
]
for (const r of report.roots) {
const status = r.overBudget ? '❌ ' : ''
lines.push(
- `| ${status}**${r.label}**<br/>\`${r.root}\` | ${formatBytes(r.bytes)} · ${r.files.toLocaleString()} files | ${formatDelta(r.bytes, previous[r.root])} | ${budgetBar(r.bytes, r.budgetBytes)} |`
+ `| ${status}**${r.label}**<br/>\`${r.root}\` | ${formatBytes(r.bytes)} · ${r.files.toLocaleString()} files | ${formatDelta(r.bytes, baseBytes[r.root])} | ${budgetBar(r.bytes, r.budgetBytes)} |`
)
}
lines.push('')