-
Notifications
You must be signed in to change notification settings - Fork 158
73 lines (60 loc) · 2.13 KB
/
Copy pathbenchmark-comment.yaml
File metadata and controls
73 lines (60 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Benchmark Comment
on:
workflow_run:
workflows: ["Benchmark"]
types:
- completed
permissions:
pull-requests: write
jobs:
comment:
runs-on: ubuntu-24.04
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure'
steps:
- name: Download benchmark results
uses: actions/download-artifact@v4
with:
name: benchmark-results
path: benchmark-results/
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const prNumber = parseInt(fs.readFileSync('benchmark-results/pr_number.txt', 'utf8').trim());
const summaryContent = fs.readFileSync('benchmark-results/summary.md', 'utf8');
const body = `### 📊 Benchmark Comparison
${summaryContent}
<details>
<summary>Benchmark Details</summary>
- Baseline: \`main\` branch
- Comparison: This PR
- Threshold: 10% regression triggers warning
</details>`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📊 Benchmark Comparison')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}