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
4649DEFAULT_BRANCH = "master"
4750WORKFLOW_NAME = "CI" # Workflow that generates the benchmark artifacts
4851ARTIFACT_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
294337def 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