|
54 | 54 | REGRESSION_DIRECTIVE = "ci: allow-regressions" |
55 | 55 | # Place this in a PR body to skip extensive tests |
56 | 56 | SKIP_EXTENSIVE_DIRECTIVE = "ci: skip-extensive" |
| 57 | +# Place this in a PR body to allow running a large number of extensive tests. If not |
| 58 | +# set, this script will error out if a threshold is exceeded in order to avoid |
| 59 | +# accidentally spending huge amounts of CI time. |
| 60 | +ALLOW_MANY_EXTENSIVE_DIRECTIVE = "ci: allow-many-extensive" |
| 61 | +MANY_EXTENSIVE_THRESHOLD = 20 |
57 | 62 |
|
58 | 63 | # Don't run exhaustive tests if these files change, even if they contaiin a function |
59 | 64 | # definition. |
@@ -198,28 +203,45 @@ def make_workflow_output(self) -> str: |
198 | 203 |
|
199 | 204 | pr_number = os.environ.get("PR_NUMBER") |
200 | 205 | skip_tests = False |
| 206 | + error_on_many_tests = False |
201 | 207 |
|
202 | 208 | if pr_number is not None: |
203 | 209 | pr = PrInfo.load(pr_number) |
204 | 210 | skip_tests = pr.contains_directive(SKIP_EXTENSIVE_DIRECTIVE) |
| 211 | + error_on_many_tests = not pr.contains_directive( |
| 212 | + ALLOW_MANY_EXTENSIVE_DIRECTIVE |
| 213 | + ) |
205 | 214 |
|
206 | 215 | if skip_tests: |
207 | 216 | eprint("Skipping all extensive tests") |
208 | 217 |
|
209 | 218 | changed = self.changed_routines() |
210 | 219 | ret = [] |
| 220 | + total_to_test = 0 |
| 221 | + |
211 | 222 | for ty in TYPES: |
212 | 223 | ty_changed = changed.get(ty, []) |
213 | | - changed_str = ",".join(ty_changed) |
| 224 | + ty_to_test = [] if skip_tests else ty_changed |
| 225 | + total_to_test += len(ty_to_test) |
214 | 226 |
|
215 | 227 | item = { |
216 | 228 | "ty": ty, |
217 | | - "changed": changed_str, |
218 | | - "to_test": "" if skip_tests else changed_str, |
| 229 | + "changed": ",".join(ty_changed), |
| 230 | + "to_test": ",".join(ty_to_test), |
219 | 231 | } |
| 232 | + |
220 | 233 | ret.append(item) |
221 | 234 | output = json.dumps({"matrix": ret}, separators=(",", ":")) |
222 | 235 | eprint(f"output: {output}") |
| 236 | + eprint(f"total extensive tests: {total_to_test}") |
| 237 | + |
| 238 | + if error_on_many_tests and total_to_test > MANY_EXTENSIVE_THRESHOLD: |
| 239 | + eprint( |
| 240 | + f"More than {MANY_EXTENSIVE_THRESHOLD} tests would be run; add" |
| 241 | + f" `{ALLOW_MANY_EXTENSIVE_DIRECTIVE}` to the PR body if this is intentional" |
| 242 | + ) |
| 243 | + exit(1) |
| 244 | + |
223 | 245 | return output |
224 | 246 |
|
225 | 247 |
|
|
0 commit comments