Files
excalidraw/scripts/stats/post.mjs
T
David Luzar 4eb1e648aa ci(repo): track bundle size and performance of master builds (#12469)
- `Stats` workflow on master: posts the production build's file sizes (raw, gzip, Brotli; initial load vs. lazy; bytes per source package) and, once staging serves the commit, its page-load and pan/zoom measurements to the Excalidraw+ backend; OSS_STATS_TOKEN lives in the master-only `stats` environment
- `scripts/stats/`: bundle-stats Vite plugin and wrapper config (`yarn stats:bundle`), the Playwright runner (`yarn stats:perf`) and the poster
- `yarn stats:compare`: builds the checkout, serves it with `vite preview` and compares it with staging (alternating loads, Mann-Whitney U test); prints a table or writes CSV with `--out`
- `excalidraw:app-start` mark in the app's entry, ending the runs' "HTML + JS" phase
- `playwright` 1.58.2 dev dependency (installs no browsers by itself)

Claude Opus 5.5 (xhigh)
2026-10-27 15:34:46 +01:00

88 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Posts a performance run (`perf.mjs --out`) or a build's bundle stats
* (`yarn stats:bundle` → `excalidraw-app/build/bundle-stats.json`) to the
* Excalidraw+ api, which stores it for the admin's Performance and Bundle size
* pages. Needs `OSS_STATS_TOKEN`; the commit is `--commit`, `GITHUB_SHA` or
* HEAD, read from this repo.
*
* node scripts/stats/post.mjs perf perf.json
* node scripts/stats/post.mjs bundle excalidraw-app/build/bundle-stats.json
*/
import { execFileSync } from "node:child_process";
import fs from "node:fs";
import { parseArgs } from "node:util";
const {
positionals: [kind, file],
values: args,
} = parseArgs({
allowPositionals: true,
options: {
commit: { type: "string" },
api: {
type: "string",
default:
process.env.OSS_STATS_API_URL || "https://backend.excalidraw.com",
},
},
});
/** The api's `OSS_STATS_TOKEN_HEADER`. */
const TOKEN_HEADER = "x-oss-stats-token";
if (!["perf", "bundle"].includes(kind) || !file) {
console.error(
"Usage: post.mjs <perf|bundle> <file.json> [--commit <sha>] [--api <url>]",
);
process.exit(1);
}
const token = process.env.OSS_STATS_TOKEN;
if (!token) {
console.error("OSS_STATS_TOKEN is not set");
process.exit(1);
}
const git = (...gitArgs) =>
execFileSync("git", gitArgs, { encoding: "utf8" }).trim();
const commitSha = git(
"rev-parse",
args.commit || process.env.GITHUB_SHA || "HEAD",
);
const commit = {
commitSha,
commitTitle: git("log", "-1", "--format=%s", commitSha),
runUrl: process.env.GITHUB_RUN_ID
? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
: null,
};
const data = JSON.parse(fs.readFileSync(file, "utf8"));
const body =
kind === "perf"
? { ...commit, ...data }
: {
...commit,
committedAt: git("log", "-1", "--format=%cI", commitSha),
...data,
};
const response = await fetch(`${args.api}/api/oss/${kind}-runs`, {
method: "POST",
headers: { "content-type": "application/json", [TOKEN_HEADER]: token },
body: JSON.stringify(body),
});
if (!response.ok) {
console.error(
`${response.status} ${response.statusText}: ${await response.text()}`,
);
process.exit(1);
}
const { id } = await response.json();
console.info(`Stored the ${kind} run of ${commitSha.slice(0, 7)} as ${id}`);