summaryrefslogtreecommitdiff
path: root/.github/scripts/validate-workflow-timeouts.py
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /.github/scripts/validate-workflow-timeouts.py
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to '.github/scripts/validate-workflow-timeouts.py')
-rwxr-xr-x.github/scripts/validate-workflow-timeouts.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/.github/scripts/validate-workflow-timeouts.py b/.github/scripts/validate-workflow-timeouts.py
new file mode 100755
index 00000000..256f5782
--- /dev/null
+++ b/.github/scripts/validate-workflow-timeouts.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+from pathlib import Path
+
+
+JOB_PATTERN = re.compile(
+ r"^ (?P<quote>[\"']?)(?P<name>[A-Za-z_][A-Za-z0-9_-]*)(?P=quote):"
+ r"(?:\s+&[A-Za-z_][A-Za-z0-9_-]*)?(?:\s*#.*)?$"
+)
+
+
+def unbounded_jobs(path: Path) -> list[str]:
+ failures: list[str] = []
+ in_jobs = False
+ job_name: str | None = None
+ job_line = 0
+ has_runner = False
+ has_timeout = False
+
+ def finish_job() -> None:
+ if job_name is not None and has_runner and not has_timeout:
+ failures.append(f"{path}:{job_line}: job '{job_name}' has runs-on but no timeout-minutes")
+
+ for line_number, line in enumerate(path.read_text().splitlines(), start=1):
+ if line == "jobs:":
+ in_jobs = True
+ continue
+ if not in_jobs:
+ continue
+ if line and not line[0].isspace() and not line.startswith("#"):
+ finish_job()
+ break
+
+ match = JOB_PATTERN.match(line)
+ if match:
+ finish_job()
+ job_name = match.group("name")
+ job_line = line_number
+ has_runner = False
+ has_timeout = False
+ elif (
+ line.startswith(" ")
+ and not line.startswith(" ")
+ and line.strip()
+ and not line.lstrip().startswith("#")
+ ):
+ finish_job()
+ failures.append(f"{path}:{line_number}: unsupported job declaration; timeout cannot be verified")
+ job_name = None
+ has_runner = False
+ has_timeout = False
+ elif job_name is not None:
+ has_runner = has_runner or line.startswith(" runs-on:")
+ has_timeout = has_timeout or line.startswith(" timeout-minutes:")
+ else:
+ finish_job()
+
+ return failures
+
+
+def main() -> int:
+ workflow_dir = Path(".github/workflows")
+ workflows = sorted((*workflow_dir.glob("*.yml"), *workflow_dir.glob("*.yaml")))
+ failures = [failure for path in workflows for failure in unbounded_jobs(path)]
+ if failures:
+ print("Every runner-backed GitHub Actions job must define timeout-minutes:", file=sys.stderr)
+ print("\n".join(failures), file=sys.stderr)
+ return 1
+ print(f"Validated explicit timeouts for runner-backed jobs in {len(workflows)} workflows")
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())