Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 3905821

Browse files
committed
ci: Require ci: allow-many-extensive if a threshold is exceeded
Error out when too many extensive tests would be run unless `ci: allow-many-extensive` is in the PR description. This allows us to set a much higher CI timeout with less risk that a 4+ hour job gets started by accident.
1 parent b0fc77c commit 3905821

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

ci/ci-util.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
REGRESSION_DIRECTIVE = "ci: allow-regressions"
5555
# Place this in a PR body to skip extensive tests
5656
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
5762

5863
# Don't run exhaustive tests if these files change, even if they contaiin a function
5964
# definition.
@@ -198,28 +203,45 @@ def make_workflow_output(self) -> str:
198203

199204
pr_number = os.environ.get("PR_NUMBER")
200205
skip_tests = False
206+
error_on_many_tests = False
201207

202208
if pr_number is not None:
203209
pr = PrInfo.load(pr_number)
204210
skip_tests = pr.contains_directive(SKIP_EXTENSIVE_DIRECTIVE)
211+
error_on_many_tests = not pr.contains_directive(
212+
ALLOW_MANY_EXTENSIVE_DIRECTIVE
213+
)
205214

206215
if skip_tests:
207216
eprint("Skipping all extensive tests")
208217

209218
changed = self.changed_routines()
210219
ret = []
220+
total_to_test = 0
221+
211222
for ty in TYPES:
212223
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)
214226

215227
item = {
216228
"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),
219231
}
232+
220233
ret.append(item)
221234
output = json.dumps({"matrix": ret}, separators=(",", ":"))
222235
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+
223245
return output
224246

225247

0 commit comments

Comments
 (0)