Skip to content

Commit 6d60428

Browse files
committed
Add a way to ignore benchmark regression checks
Introduce a way to ignore the results of icount regression tests, by specifying `allow-regressions` in the pull request body. This should apply to both pull requests and the merges based on them, since `gh pr view` automatically handles both.
1 parent a7bc185 commit 6d60428

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ jobs:
170170
- name: Run icount benchmarks
171171
env:
172172
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
173+
PR_NUMBER: ${{ github.event.pull_request.number }}
173174
run: ./ci/bench-icount.sh
174175

175176
- name: Upload the benchmark baseline

ci/bench-icount.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ function run_icount_benchmarks() {
4040

4141
# NB: iai-callgrind should exit on error but does not, so we inspect the sumary
4242
# for errors. See https://github.com/iai-callgrind/iai-callgrind/issues/337
43-
./ci/ci-util.py check-regressions --home "$iai_home" || true
43+
if [ -n "${PR_NUMBER:-}" ]; then
44+
# If this is for a pull request, ignore regressions if specified.
45+
./ci/ci-util.py check-regressions --home "$iai_home" --allow-pr-override "$PR_NUMBER"
46+
else
47+
./ci/ci-util.py check-regressions --home "$iai_home" || true
48+
fi
4449
}
4550

4651
# Run once with softfloats, once with arch instructions enabled

ci/ci-util.py

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
3434
Note that `--extract` will overwrite files in `iai-home`.
3535
36-
check-regressions [iai-home]
36+
check-regressions [--home iai-home] [--allow-pr-override pr_number]
3737
Check `iai-home` (or `iai-home` if unspecified) for `summary.json`
3838
files and see if there are any regressions. This is used as a workaround
3939
for `iai-callgrind` not exiting with error status; see
4040
<https://github.com/iai-callgrind/iai-callgrind/issues/337>.
41+
42+
If `--allow-pr-override` is specified, the regression check will not exit
43+
with failure if any line in the PR starts with `allow-regressions`.
4144
"""
4245
)
4346

@@ -46,6 +49,8 @@
4649
DEFAULT_BRANCH = "master"
4750
WORKFLOW_NAME = "CI" # Workflow that generates the benchmark artifacts
4851
ARTIFACT_GLOB = "baseline-icount*"
52+
# Place this in a PR body to skip regression checks (must be at the start of a line).
53+
REGRESSION_DIRECTIVE = "ci: allow-regressions"
4954

5055
# Don't run exhaustive tests if these files change, even if they contaiin a function
5156
# definition.
@@ -256,12 +261,26 @@ def locate_baseline(flags: list[str]) -> None:
256261
eprint("baseline extracted successfully")
257262

258263

259-
def check_iai_regressions(iai_home: str | None | Path):
264+
def check_iai_regressions(args: list[str]):
260265
"""Find regressions in iai summary.json files, exit with failure if any are
261266
found.
262267
"""
263-
if iai_home is None:
264-
iai_home = "iai-home"
268+
269+
iai_home = "iai-home"
270+
pr_number = False
271+
272+
while len(args) > 0:
273+
match args:
274+
case ["--home", home, *rest]:
275+
iai_home = home
276+
args = rest
277+
case ["--allow-pr-override", pr_num, *rest]:
278+
pr_number = pr_num
279+
args = rest
280+
case _:
281+
eprint(USAGE)
282+
exit(1)
283+
265284
iai_home = Path(iai_home)
266285

267286
found_summaries = False
@@ -286,9 +305,33 @@ def check_iai_regressions(iai_home: str | None | Path):
286305
eprint(f"did not find any summary.json files within {iai_home}")
287306
exit(1)
288307

289-
if len(regressions) > 0:
290-
eprint("Found regressions:", json.dumps(regressions, indent=4))
291-
exit(1)
308+
if len(regressions) == 0:
309+
eprint("No regressions found")
310+
return
311+
312+
eprint("Found regressions:", json.dumps(regressions, indent=4))
313+
314+
if pr_number is not None:
315+
pr_info = sp.check_output(
316+
[
317+
"gh",
318+
"pr",
319+
"view",
320+
str(pr_number),
321+
"--json=number,commits,body,createdAt",
322+
"--jq=.commits |= map(.oid)",
323+
],
324+
text=True,
325+
)
326+
pr = json.loads(pr_info)
327+
eprint("PR info:", json.dumps(pr, indent=4))
328+
329+
lines = pr["body"].splitlines()
330+
if any(line.startswith(REGRESSION_DIRECTIVE) for line in lines):
331+
eprint("PR allows regressions, returning")
332+
return
333+
334+
exit(1)
292335

293336

294337
def main():
@@ -299,10 +342,8 @@ def main():
299342
print(f"matrix={output}")
300343
case ["locate-baseline", *flags]:
301344
locate_baseline(flags)
302-
case ["check-regressions"]:
303-
check_iai_regressions(None)
304-
case ["check-regressions", iai_home]:
305-
check_iai_regressions(iai_home)
345+
case ["check-regressions", *args]:
346+
check_iai_regressions(args)
306347
case ["--help" | "-h"]:
307348
print(USAGE)
308349
exit()

0 commit comments

Comments
 (0)