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");
+24
View File
@@ -322,6 +322,30 @@ jobs:
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
# One sticky comment per PR (found by the hidden marker) so the triage result updates
# in place on every push instead of spamming a fresh comment. Same idiom as Kinora below.
- name: Upsert shard-selection comment on PR
if: ${{ github.event_name == 'pull_request' }}
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.ORG_ADMIN_TOKEN }} # PAT: comment as a human, not github-actions[bot]
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
MATRIX: ${{ steps.gen.outputs.matrix }}
SMOKE_ACTIVE: ${{ steps.gen.outputs.smoke_active }}
ATTEMPT: ${{ github.run_attempt }}
run: |
MARKER="<!-- playwright-shard-triage -->"
BODY=$(MARKER="$MARKER" node .github/scripts/pw-triage-comment.js /tmp/pw-select-log.txt)
CID=$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" --paginate \
-q ".[] | select(.body | contains(\"$MARKER\")) | .id" | head -1)
if [ -n "$CID" ]; then
gh api -X PATCH "repos/$REPO/issues/comments/$CID" -f body="$BODY" >/dev/null && echo "Updated triage comment ($CID)."
else
gh api -X POST "repos/$REPO/issues/$PR_NUMBER/comments" -f body="$BODY" >/dev/null && echo "Posted triage comment."
fi
ui_integration_tests:
timeout-minutes: 45
name: e2e / ${{ matrix.testfolder }}