-
-
Notifications
You must be signed in to change notification settings - Fork 212
92 lines (78 loc) · 3.18 KB
/
bench-compare.yml
File metadata and controls
92 lines (78 loc) · 3.18 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Benchmark Comparison
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: bench-${{ github.head_ref }}
cancel-in-progress: true
jobs:
bench-compare:
name: 'Benchmark Comparison'
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v6
id: checkout
with:
# Full history so the script can git-archive the base branch.
fetch-depth: 0
# Use the PR head SHA so fork PRs resolve correctly
# (github.head_ref is a branch name that only exists on the fork remote).
ref: ${{ github.event.pull_request.head.sha }}
- uses: wyvox/action-setup-pnpm@v3
- name: Run benchmark comparison
env:
BENCH_JSON_OUTPUT: ${{ runner.temp }}/bench-results.json
run: |
set -o pipefail
pnpm bench:compare | sed 's/\x1b\[[0-9;]*m//g' > "$RUNNER_TEMP/bench-output.txt"
- name: Format PR comment
if: always() && steps.checkout.outcome == 'success'
env:
BENCH_OUTPUT_FILE: ${{ runner.temp }}/bench-output.txt
BENCH_JSON_OUTPUT: ${{ runner.temp }}/bench-results.json
BENCH_JOB_SUCCESS: ${{ job.status == 'success' }}
run: node scripts/format-bench-comment.mjs > "$RUNNER_TEMP/bench-comment.md"
- name: Write job summary
if: always() && steps.checkout.outcome == 'success'
run: cat "$RUNNER_TEMP/bench-comment.md" >> "$GITHUB_STEP_SUMMARY"
- name: Post PR comment
if: always() && steps.checkout.outcome == 'success'
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const marker = '<!-- bench-compare -->';
const body = fs.readFileSync(process.env.RUNNER_TEMP + '/bench-comment.md', 'utf8');
const headFullName = context.payload.pull_request?.head?.repo?.full_name;
const isFork = !headFullName || headFullName !== context.repo.owner + '/' + context.repo.repo;
if (isFork) {
core.info('PR is from a fork — skipping PR comment (results are in the job summary).');
core.info('--- Comment body start ---');
core.info(body);
core.info('--- Comment body end ---');
} else {
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
}