ci: comment Playwright shard-selection triage on PRs (#14347)

This commit is contained in:
Shrinath Rao
2026-09-09 18:06:32 +00:00
committed by GitHub
parent ea55699946
commit c9f8d93cc6
2 changed files with 89 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env node
// Render the sticky PR shard-triage comment from $MATRIX + the select log (argv[2]) to stdout.
const fs = require("fs");
function readLog(path) {
if (!path) return "";
try {
return fs.readFileSync(path, "utf8").trim();
} catch {
return "";
}
}
const marker = process.env.MARKER || "<!-- playwright-shard-triage -->";
const smokeActive = process.env.SMOKE_ACTIVE === "true";
const headSha = (process.env.HEAD_SHA || "").slice(0, 9);
const attempt = process.env.ATTEMPT || "1";
const log = readLog(process.argv[2]);
let matrix;
try {
matrix = JSON.parse(process.env.MATRIX || "{}");
} catch {
matrix = {};
}
const shards = Array.isArray(matrix.include) ? matrix.include : [];
// smoke_active only says selection ran; a global_paths hit still returns the full
// matrix, so infer the real mode from the log rather than the flag alone.
const fellBackToFull = /falling back to full matrix|full matrix:/.test(log);
const mode = smokeActive && !fellBackToFull ? "smoke (changed-path)" : "full matrix";
const specsOf = (s) => (Array.isArray(s.run_files) ? s.run_files.length : 0);
const totalSpecs = shards.reduce((n, s) => n + specsOf(s), 0);
const shardList = shards
.map((s) => `${s.testfolder} (${specsOf(s)})`)
.join(" · ");
const lines = [
marker,
"### 🎯 Playwright shard selection",
`Mode: **${mode}** · **${shards.length} shard${shards.length === 1 ? "" : "s"}** · **${totalSpecs} spec${totalSpecs === 1 ? "" : "s"}**`,
"",
shardList || "_no shards selected_",
];
if (log) {
lines.push(
"",
"<details><summary>Why these shards</summary>",
"",
"```",
log,
"```",
"",
"</details>"
);
}
lines.push(
"",
`<sub>Updated for \`${headSha}\` · attempt ${attempt} · updates in place on every push.</sub>`
);
process.stdout.write(lines.join("\n") + "\n");