-
Notifications
You must be signed in to change notification settings - Fork 22
149 lines (127 loc) · 4.45 KB
/
Copy pathbenchmark.yml
File metadata and controls
149 lines (127 loc) · 4.45 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Benchmarks
on:
pull_request:
branches: [main]
paths:
- 'src/**'
- 'benchmarks/**'
- 'package.json'
- '.github/workflows/benchmark.yml'
push:
branches: [main]
paths:
- 'src/**'
- 'benchmarks/**'
- '.github/workflows/benchmark.yml'
workflow_dispatch:
permissions:
contents: write # For committing benchmark history
pull-requests: write # For commenting on PRs
issues: write # For commit comments via issues API
jobs:
benchmark:
name: Run Performance Benchmarks
runs-on: ubuntu-latest
# Skip benchmarks for Dependabot PRs
if: github.actor != 'dependabot[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Cache Node.js dependencies
uses: actions/cache@v4
with:
path: |
~/.npm
node_modules
benchmarks/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Install benchmark dependencies
working-directory: ./benchmarks
run: npm ci
- name: Install wrk
run: |
sudo apt-get update
sudo apt-get install -y wrk
- name: Run HTTP benchmarks
working-directory: ./benchmarks
run: node run.js --duration 15 --output results.md
- name: Save benchmark history
working-directory: ./benchmarks
run: npm run benchmark:save
continue-on-error: true
- name: Compare with history
id: compare-history
working-directory: ./benchmarks
run: npm run benchmark:compare
continue-on-error: true
- name: Commit history (main branch only)
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add benchmarks/history/
git diff --staged --quiet || git commit -m "chore: update benchmark history [skip ci]"
git pull --rebase --autostash origin ${{ github.ref_name }}
git push
continue-on-error: true
- name: Upload benchmark results
if: always()
uses: actions/upload-artifact@v6
with:
name: benchmark-results
path: benchmarks/results.md
retention-days: 30
- name: Comment on commit
if: github.event_name == 'push'
continue-on-error: true
uses: peter-evans/commit-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body-path: benchmarks/results.md
- name: Comment on pull request
if: github.event_name == 'pull_request'
continue-on-error: true
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const marker = '<!-- benchmark-results -->';
let body = fs.readFileSync('benchmarks/results.md', 'utf8');
// Ensure marker is present for comment matching
if (!body.includes(marker)) {
body = marker + '\n' + body;
}
const issue_number = context.payload.pull_request.number;
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number
});
const existing = comments.find((comment) =>
comment.user && comment.user.type === 'Bot' && comment.body && comment.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,
body
});
}