mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
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.
86 lines
3 KiB
YAML
86 lines
3 KiB
YAML
name: TheRespectPanda Bot
|
|
|
|
on:
|
|
issue_comment:
|
|
types: [created]
|
|
|
|
jobs:
|
|
listen-comment:
|
|
if: startsWith(github.event.comment.body, '@TheRespectPanda')
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
issues: write
|
|
actions: write
|
|
steps:
|
|
- uses: actions/github-script@v8
|
|
with:
|
|
github-token: ${{ secrets.PANDA_GITHUB_PAT }}
|
|
script: |
|
|
const body = (context.payload.comment && context.payload.comment.body).trim() || '';
|
|
const usage = 'Usage: `@TheRespectPanda ping|help|benchmark`';
|
|
|
|
if (!body.startsWith('@TheRespectPanda')) {
|
|
return;
|
|
}
|
|
|
|
let answer;
|
|
|
|
switch (body) {
|
|
case '@TheRespectPanda ping':
|
|
answer = 'Pong! 🐼';
|
|
break;
|
|
|
|
case '@TheRespectPanda':
|
|
case '@TheRespectPanda help':
|
|
answer = 'Hello! I am TheRespectPanda Bot. ' + usage;
|
|
break;
|
|
|
|
case '@TheRespectPanda benchmark':
|
|
// Only runnable on pull requests
|
|
if (!context.payload.issue.pull_request) {
|
|
answer = 'The `benchmark` command can only be used on pull requests.';
|
|
break;
|
|
}
|
|
|
|
// Only members can trigger benchmarks
|
|
const association = context.payload.comment.author_association;
|
|
const allowedAssociations = ['OWNER', 'MEMBER', 'COLLABORATOR'];
|
|
if (!allowedAssociations.includes(association)) {
|
|
answer = 'Only repository members can trigger benchmarks.';
|
|
break;
|
|
}
|
|
|
|
try {
|
|
// dispatch the perf workflow
|
|
const ref = (context.payload.repository && context.payload.repository.default_branch) || 'main';
|
|
|
|
const workflowId = 'ci-perf.yml';
|
|
await github.rest.actions.createWorkflowDispatch({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
workflow_id: workflowId,
|
|
ref,
|
|
inputs: {
|
|
baseline: 'latest',
|
|
pull: String(context.issue.number)
|
|
}
|
|
});
|
|
|
|
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/workflows/${workflowId}`;
|
|
answer = `Triggered phpbench benchmarks for PR #${context.issue.number} — workflow run: ${runUrl}`;
|
|
} catch (err) {
|
|
answer = `Failed to trigger benchmarks: ${err.message}`;
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
answer = "I'm sorry, I don't understand that command. " + usage;
|
|
}
|
|
|
|
await github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: answer
|
|
});
|