diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 96496822..aa46f2ef 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -25,6 +25,7 @@ concurrency: jobs: build: runs-on: ubuntu-latest + timeout-minutes: 10 permissions: contents: read steps: @@ -60,6 +61,7 @@ jobs: # validates and stops, because a fork's build must never reach Pages. if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' runs-on: ubuntu-latest + timeout-minutes: 5 permissions: pages: write id-token: write diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 5bfd5d82..6b6cce1f 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -30,6 +30,7 @@ permissions: jobs: publish: runs-on: ubuntu-latest + timeout-minutes: 5 environment: npm permissions: contents: read # job-level permissions replace the workflow block diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eedc19c3..8c03b3d6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,6 +17,7 @@ permissions: jobs: build: runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 @@ -35,6 +36,7 @@ jobs: publish: needs: build runs-on: ubuntu-latest + timeout-minutes: 5 environment: pypi permissions: id-token: write # OIDC token for Trusted Publishing diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6029807d..7859e0ae 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,6 +19,7 @@ jobs: # tests such as test_era_algotune's reference speedup measured 0.07x there. # Move this deliberately, with the matrix, when 3.9 support is dropped. runs-on: ubuntu-24.04 + timeout-minutes: 60 strategy: fail-fast: false matrix: @@ -49,6 +50,7 @@ jobs: # nothing listens on: the refusal must be logged and contained, never raised # out of `export_run`, and a real export must still return its count. runs-on: ubuntu-24.04 + timeout-minutes: 10 steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 diff --git a/changelog.d/1235-workflow-job-timeouts.md b/changelog.d/1235-workflow-job-timeouts.md new file mode 100644 index 00000000..b876865a --- /dev/null +++ b/changelog.d/1235-workflow-job-timeouts.md @@ -0,0 +1,5 @@ +Fixed +Every workflow job now declares a `timeout-minutes` -- 5 or 10 for the short +report, build and publish jobs, 60 for the five-version `tests` matrix -- so a +stalled deploy, publish or test run fails in minutes instead of holding a +runner for GitHub's 360-minute default (#1235). diff --git a/tests/test_workflow_timeouts.py b/tests/test_workflow_timeouts.py new file mode 100644 index 00000000..469de45b --- /dev/null +++ b/tests/test_workflow_timeouts.py @@ -0,0 +1,76 @@ +"""Every workflow job bounds its own run time. + +A job without ``timeout-minutes`` inherits GitHub's 360-minute default, so a +stalled step -- a Pages deploy waiting on its OIDC exchange, a publish job +holding ``id-token: write``, a test runner blocked on a hung fixture -- reads as +a slow check for six hours instead of a stuck one. + +The bounds are calibrated from this repository's own run history (Actions API, +read 2026-11-23), not from round numbers: + +==================== ================= ===== +job observed minutes bound +==================== ================= ===== +docs build 1.3 - 2.8 10 +docs deploy 0.0 - 0.1 5 +publish build 0.6 - 0.9 10 +publish publish 0.3 - 0.4 5 +publish-npm publish 0.2 - 0.3 5 +tests test (per Py) 15.7 - 29.9 60 +tests otel-wire 1.2 - 1.4 10 +==================== ================= ===== + +``tests`` keeps the largest bound on purpose: a 5- or 10-minute cap on a matrix +job that takes twenty would turn green PRs red, and these caps exist to catch a +hang, not to race a healthy run. +""" + +from __future__ import annotations + +from pathlib import Path + +import yaml + +WORKFLOWS = Path(__file__).resolve().parent.parent / ".github" / "workflows" +MAXIMUM = 60 + + +def _jobs(): + for path in sorted(WORKFLOWS.glob("*.yml")): + wf = yaml.safe_load(path.read_text(encoding="utf-8")) + for name, job in (wf.get("jobs") or {}).items(): + yield path.name, name, job + + +def test_every_job_declares_timeout_minutes(): + missing = [ + f"{wf}:{job}" + for wf, job, spec in _jobs() + if spec.get("timeout-minutes") is None + ] + assert not missing, ( + "a job without `timeout-minutes` inherits GitHub's 360-minute default, " + f"so one stalled step holds the runner for six hours: {missing}" + ) + + +def test_no_job_is_bound_above_the_slowest_observed_suite(): + too_long = [ + (wf, job, spec.get("timeout-minutes")) + for wf, job, spec in _jobs() + if not 1 <= spec.get("timeout-minutes", 0) <= MAXIMUM + ] + assert not too_long, ( + f"keep every job bound at or below {MAXIMUM} minutes, or a hang still " + f"reads as a slow check: {too_long}" + ) + + +def test_the_test_matrix_keeps_headroom_above_its_measured_runtime(): + wf = yaml.safe_load((WORKFLOWS / "tests.yml").read_text(encoding="utf-8")) + limit = wf["jobs"]["test"].get("timeout-minutes") + assert limit is not None and limit >= 45, ( + "the test job runs the whole offline suite across five Pythons and " + "measured 15.7-29.9 minutes per version on 2026-11-23, so a bound " + "under 45 would cut a healthy run instead of catching a hung one" + )