name: benchmark-report-dispatch
on:
issue_comment:
types: [created]
permissions:
actions: write
contents: read
pull-requests: write
jobs:
dispatch-benchmark-report:
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/benchmark')
runs-on: ubuntu-latest
steps:
- name: Validate trigger and dispatch benchmark report
uses: actions/github-script@v9
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const issueNumber = context.payload.issue.number;
const comment = context.payload.comment;
const body = comment.body.trim();
const association = comment.author_association;
const allowedAssociations = new Set([
"OWNER",
"MEMBER",
"COLLABORATOR",
"CONTRIBUTOR",
]);
if (!allowedAssociations.has(association)) {
core.setFailed(
`/${"benchmark"} requires OWNER, MEMBER, COLLABORATOR, or CONTRIBUTOR status. ${comment.user.login} is ${association}.`
);
return;
}
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: issueNumber,
});
const workflowRef = pr.base.ref;
const supportedCommandsByRef = new Map([
[
"master",
new Map([
["/benchmark", "basic"],
["/benchmark basic", "basic"],
["/benchmark extended", "extended"],
["/benchmark dist", "dist"],
["/benchmark leaf", "leaf"],
["/benchmark stems", "stems"],
["/benchmark construction", "construction"],
]),
],
[
"v5.x.x",
new Map([
["/benchmark", "basic"],
["/benchmark basic", "basic"],
["/benchmark extended", "extended"],
]),
],
]);
const supportedCommands = supportedCommandsByRef.get(workflowRef);
if (!supportedCommands) {
core.setFailed(
`No benchmark workflow is configured for PR base branch ${workflowRef}.`
);
return;
}
const benchmarkVariant = supportedCommands.get(body);
if (!benchmarkVariant) {
core.setFailed(
`Unsupported benchmark command for ${workflowRef}. Allowed commands: ${[...supportedCommands.keys()].join(", ")}.`
);
return;
}
await github.rest.actions.createWorkflowDispatch({
owner,
repo,
workflow_id: "benchmark-report.yml",
ref: workflowRef,
inputs: {
pr_number: String(pr.number),
head_sha: pr.head.sha,
head_ref: pr.head.ref,
head_repo: pr.head.repo.full_name,
benchmark_variant: benchmarkVariant,
},
});
const benchmarkLabel =
benchmarkVariant === "dist"
? "dist-focussed"
: benchmarkVariant === "extended"
? "query-family"
: benchmarkVariant === "leaf"
? "leaf-strategy"
: benchmarkVariant === "stems"
? "stem-strategy"
: benchmarkVariant === "construction"
? "tree-construction"
: "basic";
await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: `Queued ${benchmarkLabel} benchmark-report run for \`${pr.head.label}\` at \`${pr.head.sha.slice(0, 12)}\`.`,
});