Skip to content

Commit db2d9ac

Browse files
committed
Allow panda.yml to request benchmark runs for PRs
This change introduces a new command to `@TheRespectPanda` bot, allowing him to dispatch the ci-perf.yml workflow benchmarks for a pull request. Initially, the bot will just trigger it and return the workflow run URL for manual inspection. Future iterations on this feature could then grab the benchmark results and update the comment.
1 parent e1ff5aa commit db2d9ac

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

.github/workflows/ci-perf.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ on:
2121
options:
2222
- 'latest'
2323
- 'rebaseline'
24+
pull:
25+
description: 'Pull request number to benchmark (optional)'
26+
required: false
2427

2528
jobs:
2629
tests:
@@ -34,6 +37,18 @@ jobs:
3437
- uses: actions/checkout@v6
3538
with:
3639
persist-credentials: true
40+
41+
- name: Checkout PR head (if requested)
42+
if: ${{ github.event.inputs.pull }}
43+
run: |
44+
set -euo pipefail
45+
PR=${{ github.event.inputs.pull }}
46+
# fetch the pull request head (works for forks)
47+
git fetch origin pull/${PR}/head:pr-${PR} || git fetch origin +refs/pull/${PR}/head:pr-${PR}
48+
git checkout pr-${PR}
49+
echo "Checked out PR #${PR}"
50+
echo "GITHUB_SHA=$(git rev-parse --verify HEAD)" >> $GITHUB_ENV
51+
3752
- uses: ./.github/actions/setup-action
3853
with:
3954
extensions: xdebug

.github/workflows/panda.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ jobs:
1111
permissions:
1212
issues: write
1313
pull-requests: write
14+
actions: write
1415
steps:
1516
- uses: actions/github-script@v8
1617
with:
1718
github-token: ${{ secrets.PANDA_GITHUB_PAT }}
1819
script: |
1920
const body = (context.payload.comment && context.payload.comment.body).trim() || '';
20-
const usage = 'Usage: `@TheRespectPanda ping|help`';
21+
const usage = 'Usage: `@TheRespectPanda ping|help|benchmark`';
2122
2223
if (!body.startsWith('@TheRespectPanda')) {
2324
return;
@@ -27,10 +28,51 @@ jobs:
2728
case '@TheRespectPanda ping':
2829
answer = 'Pong! 🐼';
2930
break;
31+
3032
case '@TheRespectPanda':
3133
case '@TheRespectPanda help':
3234
answer = 'Hello! I am TheRespectPanda Bot. ' + usage;
3335
break;
36+
37+
case '@TheRespectPanda benchmark':
38+
// Only runnable on pull requests
39+
if (!context.payload.issue.pull_request) {
40+
answer = 'The `benchmark` command can only be used on pull requests.';
41+
break;
42+
}
43+
44+
try {
45+
// fetch PR details
46+
const pr = await github.rest.pulls.get({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
pull_number: context.issue.number
50+
});
51+
52+
// dispatch the perf workflow
53+
const repoInfo = await github.rest.repos.get({ owner: context.repo.owner, repo: context.repo.repo });
54+
const ref = repoInfo.data.default_branch || 'main';
55+
56+
const workflowId = 'ci-perf.yml';
57+
const dispatchResp = await github.rest.actions.createWorkflowDispatch({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
workflow_id: workflowId,
61+
ref,
62+
inputs: {
63+
baseline: 'latest',
64+
pull: String(context.issue.number)
65+
}
66+
});
67+
68+
let runUrl = dispatchResp && dispatchResp.data && dispatchResp.data.workflow_run && dispatchResp.data.workflow_run.html_url;
69+
answer = `Triggered phpbench benchmarks for PR #${context.issue.number} — workflow run: ${runUrl}`;
70+
} catch (err) {
71+
answer = `Failed to trigger benchmarks: ${err.message}`;
72+
}
73+
74+
break;
75+
3476
default:
3577
answer = "I'm sorry, I don't understand that command. " + usage;
3678
}

0 commit comments

Comments
 (0)