|
59 | 59 | # accidentally spending huge amounts of CI time.
|
60 | 60 | ALLOW_MANY_EXTENSIVE_DIRECTIVE = "ci: allow-many-extensive"
|
61 | 61 | MANY_EXTENSIVE_THRESHOLD = 20
|
| 62 | +# Require tests for `libm` |
| 63 | +TEST_LIBM_DIRECTIVE = "ci: test-libm" |
62 | 64 |
|
63 | 65 | # Don't run exhaustive tests if these files change, even if they contaiin a function
|
64 | 66 | # definition.
|
@@ -90,8 +92,17 @@ class PrInfo:
|
90 | 92 | number: int
|
91 | 93 |
|
92 | 94 | @classmethod
|
93 |
| - def load(cls, pr_number: int | str) -> Self: |
94 |
| - """For a given PR number, query the body and commit list""" |
| 95 | + def from_env(cls) -> Self | None: |
| 96 | + """Create a PR object from the PR_NUMBER environment if set, `None` otherwise.""" |
| 97 | + pr_env = os.environ.get("PR_NUMBER") |
| 98 | + if pr_env is not None and len(pr_env) > 0: |
| 99 | + return cls.from_pr(pr_env) |
| 100 | + |
| 101 | + return None |
| 102 | + |
| 103 | + @classmethod |
| 104 | + def from_pr(cls, pr_number: int | str) -> Self: |
| 105 | + """For a given PR number, query the body and commit list.""" |
95 | 106 | pr_info = sp.check_output(
|
96 | 107 | [
|
97 | 108 | "gh",
|
@@ -207,22 +218,31 @@ def may_skip_libm_ci(self) -> bool:
|
207 | 218 | """If this is a PR and no libm files were changed, allow skipping libm
|
208 | 219 | jobs."""
|
209 | 220 |
|
210 |
| - if self.is_pr(): |
211 |
| - return all(not re.match(TRIGGER_LIBM_PR_CI, str(f)) for f in self.changed) |
| 221 | + # Always run on merge CI |
| 222 | + if not self.is_pr(): |
| 223 | + return False |
| 224 | + |
| 225 | + pr = PrInfo.from_env() |
| 226 | + if pr is None: |
| 227 | + eprint("Is a PR but couldn't load PrInfo") |
| 228 | + exit(1) |
| 229 | + |
| 230 | + # Allow opting in to libm tests |
| 231 | + if pr.contains_directive(TEST_LIBM_DIRECTIVE): |
| 232 | + return True |
212 | 233 |
|
213 |
| - return False |
| 234 | + return all(not re.match(TRIGGER_LIBM_PR_CI, str(f)) for f in self.changed) |
214 | 235 |
|
215 | 236 | def emit_workflow_output(self):
|
216 | 237 | """Create a JSON object a list items for each type's changed files, if any
|
217 | 238 | did change, and the routines that were affected by the change.
|
218 | 239 | """
|
219 | 240 |
|
220 |
| - pr_number = os.environ.get("PR_NUMBER") |
221 | 241 | skip_tests = False
|
222 | 242 | error_on_many_tests = False
|
223 | 243 |
|
224 |
| - if pr_number is not None and len(pr_number) > 0: |
225 |
| - pr = PrInfo.load(pr_number) |
| 244 | + pr = PrInfo.from_env() |
| 245 | + if pr is not None: |
226 | 246 | skip_tests = pr.contains_directive(SKIP_EXTENSIVE_DIRECTIVE)
|
227 | 247 | error_on_many_tests = not pr.contains_directive(
|
228 | 248 | ALLOW_MANY_EXTENSIVE_DIRECTIVE
|
@@ -371,7 +391,7 @@ def handle_bench_regressions(args: list[str]):
|
371 | 391 | eprint(USAGE)
|
372 | 392 | exit(1)
|
373 | 393 |
|
374 |
| - pr = PrInfo.load(pr_number) |
| 394 | + pr = PrInfo.from_pr(pr_number) |
375 | 395 | if pr.contains_directive(REGRESSION_DIRECTIVE):
|
376 | 396 | eprint("PR allows regressions")
|
377 | 397 | return
|
|
0 commit comments