-
-
Notifications
You must be signed in to change notification settings - Fork 97
315 lines (265 loc) · 14.3 KB
/
Copy pathperformance-benchmark.yml
File metadata and controls
315 lines (265 loc) · 14.3 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
name: Performance Benchmark
on:
pull_request:
push:
branches: [main]
workflow_dispatch:
env:
BCR_VERSION: "1.11.7"
ANALYSIS_BCR_VERSION: "2.0.0-alpha.4"
jobs:
startup:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout PR
uses: actions/checkout@v6
with:
fetch-depth: 0
path: rules_py_pr
- name: Checkout HEAD main
uses: actions/checkout@v6
with:
ref: main
path: rules_py_main
- name: Install hyperfine
run: |
set -euo pipefail
HYPERFINE_VERSION="1.18.0"
DEB="hyperfine_${HYPERFINE_VERSION}_amd64.deb"
URL="https://github.com/sharkdp/hyperfine/releases/download/v${HYPERFINE_VERSION}/${DEB}"
wget -qO "$DEB" "$URL"
sudo dpkg -i "$DEB"
rm -f "$DEB"
hyperfine --version
# ── BCR baseline ────────────────────────────────────────────────────────
- name: Benchmark BCR ${{ env.BCR_VERSION }}
run: |
set -euo pipefail
cd rules_py_pr/benchmark/startup
python3 generate_module.py bcr --version "${BCR_VERSION}"
OUT_BASE="/tmp/bazel-bcr"
rm -rf "$OUT_BASE"
START=$(date +%s%N)
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= //:bench //:bench_syspath
END=$(date +%s%N)
BUILD_MS=$(( (END - START) / 1000000 ))
echo "{\"build_ms\": $BUILD_MS}" > "${GITHUB_WORKSPACE}/bcr-build.json"
BIN=$(bazel --output_base="$OUT_BASE" cquery //:bench --disk_cache= --output=starlark --starlark:expr='target.files_to_run.executable.path' | tail -n1)
test -x "$BIN" || { echo "ERROR: benchmark binary not executable: $BIN"; exit 1; }
RUNFILES_DIR="$PWD/$BIN.runfiles" hyperfine --warmup 5 --runs 50 --export-json "${GITHUB_WORKSPACE}/bcr.json" "$BIN"
BIN_SP=$(bazel --output_base="$OUT_BASE" cquery //:bench_syspath --disk_cache= --output=starlark --starlark:expr='target.files_to_run.executable.path' | tail -n1)
test -x "$BIN_SP" || { echo "ERROR: bench_syspath binary not executable: $BIN_SP"; exit 1; }
RUNFILES_DIR="$PWD/$BIN_SP.runfiles" "$BIN_SP" "$GITHUB_WORKSPACE/bcr-syspath.json"
# ── HEAD main ───────────────────────────────────────────────────────────
- name: Benchmark HEAD main
run: |
set -euo pipefail
cd rules_py_pr/benchmark/startup
python3 generate_module.py local --path "$GITHUB_WORKSPACE/rules_py_main"
OUT_BASE="/tmp/bazel-main"
rm -rf "$OUT_BASE"
START=$(date +%s%N)
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= //:bench //:bench_syspath
END=$(date +%s%N)
BUILD_MS=$(( (END - START) / 1000000 ))
echo "{\"build_ms\": $BUILD_MS}" > "${GITHUB_WORKSPACE}/main-build.json"
BIN=$(bazel --output_base="$OUT_BASE" cquery //:bench --disk_cache= --output=starlark --starlark:expr='target.files_to_run.executable.path' | tail -n1)
test -x "$BIN" || { echo "ERROR: benchmark binary not executable: $BIN"; exit 1; }
RUNFILES_DIR="$PWD/$BIN.runfiles" hyperfine --warmup 5 --runs 50 --export-json "${GITHUB_WORKSPACE}/main.json" "$BIN"
BIN_SP=$(bazel --output_base="$OUT_BASE" cquery //:bench_syspath --disk_cache= --output=starlark --starlark:expr='target.files_to_run.executable.path' | tail -n1)
test -x "$BIN_SP" || { echo "ERROR: bench_syspath binary not executable: $BIN_SP"; exit 1; }
RUNFILES_DIR="$PWD/$BIN_SP.runfiles" "$BIN_SP" "$GITHUB_WORKSPACE/main-syspath.json"
# ── Current commit (PR) ─────────────────────────────────────────────────
- name: Benchmark current PR
run: |
set -euo pipefail
cd rules_py_pr/benchmark/startup
python3 generate_module.py local --path "$GITHUB_WORKSPACE/rules_py_pr"
OUT_BASE="/tmp/bazel-pr"
rm -rf "$OUT_BASE"
START=$(date +%s%N)
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= //:bench //:bench_syspath
END=$(date +%s%N)
BUILD_MS=$(( (END - START) / 1000000 ))
echo "{\"build_ms\": $BUILD_MS}" > "${GITHUB_WORKSPACE}/pr-build.json"
BIN=$(bazel --output_base="$OUT_BASE" cquery //:bench --disk_cache= --output=starlark --starlark:expr='target.files_to_run.executable.path' | tail -n1)
test -x "$BIN" || { echo "ERROR: benchmark binary not executable: $BIN"; exit 1; }
RUNFILES_DIR="$PWD/$BIN.runfiles" hyperfine --warmup 5 --runs 50 --export-json "${GITHUB_WORKSPACE}/pr.json" "$BIN"
BIN_SP=$(bazel --output_base="$OUT_BASE" cquery //:bench_syspath --disk_cache= --output=starlark --starlark:expr='target.files_to_run.executable.path' | tail -n1)
test -x "$BIN_SP" || { echo "ERROR: bench_syspath binary not executable: $BIN_SP"; exit 1; }
RUNFILES_DIR="$PWD/$BIN_SP.runfiles" "$BIN_SP" "$GITHUB_WORKSPACE/pr-syspath.json"
# ── Compare ─────────────────────────────────────────────────────────────
- name: Compare startup results
id: compare
continue-on-error: true
run: |
set -euo pipefail
python3 rules_py_pr/benchmark/startup/compare.py \
--output-table startup-table.txt \
bcr.json main.json pr.json
- name: Save PR number
if: github.event_name == 'pull_request'
run: echo "${{ github.event.pull_request.number }}" > pr-number.txt
- name: Upload startup artifacts
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: startup-benchmark-results
path: |
startup-table.txt
pr-number.txt
if-no-files-found: warn
- name: Fail on regression
if: steps.compare.outcome == 'failure'
run: exit 1
analysis:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout PR
uses: actions/checkout@v6
with:
fetch-depth: 0
path: rules_py_pr
- name: Checkout HEAD main
uses: actions/checkout@v6
with:
ref: main
path: rules_py_main
- name: Install hyperfine
run: |
set -euo pipefail
HYPERFINE_VERSION="1.18.0"
DEB="hyperfine_${HYPERFINE_VERSION}_amd64.deb"
URL="https://github.com/sharkdp/hyperfine/releases/download/v${HYPERFINE_VERSION}/${DEB}"
wget -qO "$DEB" "$URL"
sudo dpkg -i "$DEB"
rm -f "$DEB"
hyperfine --version
- name: Generate workspace
run: |
set -euo pipefail
cd rules_py_pr/benchmark/analysis
python3 workspace/generate_workspace.py --root workspace --packages 50
# ── BCR baseline ────────────────────────────────────────────────────────
- name: Benchmark BCR ${{ env.ANALYSIS_BCR_VERSION }}
run: |
set -euo pipefail
cd rules_py_pr/benchmark/analysis
python3 generate_module.py bcr --version "${ANALYSIS_BCR_VERSION}"
OUT_BASE="/tmp/bazel-bcr"
rm -rf "$OUT_BASE"
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc fetch //workspace/...
hyperfine --warmup 1 --runs 10 \
--prepare 'rm -rf /tmp/bazel-bcr-analysis' \
--export-json "${GITHUB_WORKSPACE}/bcr.json" \
'bazel --output_base=/tmp/bazel-bcr-analysis --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= --nobuild //workspace/...'
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... --output=package > /tmp/bcr-packages.txt
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... > /tmp/bcr-targets.txt
echo "{\"packages\": $(wc -l < /tmp/bcr-packages.txt | tr -d ' '), \"targets\": $(wc -l < /tmp/bcr-targets.txt | tr -d ' ')}" > "${GITHUB_WORKSPACE}/bcr-aux.json"
# ── HEAD main ───────────────────────────────────────────────────────────
- name: Benchmark HEAD main
run: |
set -euo pipefail
cd rules_py_pr/benchmark/analysis
python3 generate_module.py local --path "$GITHUB_WORKSPACE/rules_py_main"
OUT_BASE="/tmp/bazel-main"
rm -rf "$OUT_BASE"
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc fetch //workspace/...
hyperfine --warmup 1 --runs 10 \
--prepare 'rm -rf /tmp/bazel-main-analysis' \
--export-json "${GITHUB_WORKSPACE}/main.json" \
'bazel --output_base=/tmp/bazel-main-analysis --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= --nobuild //workspace/...'
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... --output=package > /tmp/main-packages.txt
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... > /tmp/main-targets.txt
echo "{\"packages\": $(wc -l < /tmp/main-packages.txt | tr -d ' '), \"targets\": $(wc -l < /tmp/main-targets.txt | tr -d ' ')}" > "${GITHUB_WORKSPACE}/main-aux.json"
# ── Current commit (PR) ─────────────────────────────────────────────────
- name: Benchmark current PR
run: |
set -euo pipefail
cd rules_py_pr/benchmark/analysis
python3 generate_module.py local --path "$GITHUB_WORKSPACE/rules_py_pr"
OUT_BASE="/tmp/bazel-pr"
rm -rf "$OUT_BASE"
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc fetch //workspace/...
hyperfine --warmup 1 --runs 10 \
--prepare 'rm -rf /tmp/bazel-pr-analysis' \
--export-json "${GITHUB_WORKSPACE}/pr.json" \
'bazel --output_base=/tmp/bazel-pr-analysis --bazelrc=../../.github/workflows/ci.bazelrc build --disk_cache= --nobuild //workspace/...'
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... --output=package > /tmp/pr-packages.txt
bazel --output_base="$OUT_BASE" --bazelrc=../../.github/workflows/ci.bazelrc query //workspace/... > /tmp/pr-targets.txt
echo "{\"packages\": $(wc -l < /tmp/pr-packages.txt | tr -d ' '), \"targets\": $(wc -l < /tmp/pr-targets.txt | tr -d ' ')}" > "${GITHUB_WORKSPACE}/pr-aux.json"
# ── Compare ─────────────────────────────────────────────────────────────
- name: Compare analysis results
id: compare
continue-on-error: true
run: |
set -euo pipefail
python3 rules_py_pr/benchmark/analysis/compare.py \
--output-table analysis-table.txt \
bcr.json main.json pr.json
- name: Upload analysis artifacts
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: analysis-benchmark-results
path: |
analysis-table.txt
if-no-files-found: warn
- name: Fail on regression
if: steps.compare.outcome == 'failure'
run: exit 1
comment:
runs-on: ubuntu-latest
needs: [startup, analysis]
if: always() && github.event_name == 'pull_request' && (needs.startup.result == 'success' || needs.startup.result == 'failure') && (needs.analysis.result == 'success' || needs.analysis.result == 'failure')
permissions:
pull-requests: write
steps:
- name: Download startup artifacts
uses: actions/download-artifact@v4
with:
name: startup-benchmark-results
- name: Download analysis artifacts
uses: actions/download-artifact@v4
with:
name: analysis-benchmark-results
- name: Post combined benchmark comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const startup = fs.readFileSync('startup-table.txt', 'utf8').trim();
const analysis = fs.readFileSync('analysis-table.txt', 'utf8').trim();
const prNumber = parseInt(fs.readFileSync('pr-number.txt', 'utf8').trim());
const header = '<!-- performance-benchmark -->';
const body = `${header}\n\n${startup}\n\n${analysis}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body && c.body.includes(header));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body,
});
console.log(`Updated comment ${existing.id}`);
} else {
const { data: created } = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body,
});
console.log(`Created comment ${created.id}`);
}
- name: Fail if any benchmark regressed
if: needs.startup.result == 'failure' || needs.analysis.result == 'failure'
run: exit 1