diff --git a/.github/workflows/bandit.yml b/.github/workflows/bandit.yml index a711e80..898de53 100644 --- a/.github/workflows/bandit.yml +++ b/.github/workflows/bandit.yml @@ -13,6 +13,7 @@ jobs: bandit: name: Bandit runs-on: ubuntu-26.04 + timeout-minutes: 10 steps: - name: Checkout uses: actions/checkout@v7 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8aec4bc..7517c22 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -13,6 +13,7 @@ jobs: analyze: name: CodeQL runs-on: ubuntu-26.04 + timeout-minutes: 10 strategy: fail-fast: false matrix: diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index dd30fb8..ebba61b 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -25,6 +25,7 @@ jobs: # Move it to 26.04 once CodSpeed supports it; nothing here will notice when # that happens, so it is worth trying on a branch now and then. runs-on: ubuntu-24.04 + timeout-minutes: 25 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/.github/workflows/docker-build-check.yml b/.github/workflows/docker-build-check.yml index 6e9db84..85fbd2a 100644 --- a/.github/workflows/docker-build-check.yml +++ b/.github/workflows/docker-build-check.yml @@ -20,6 +20,7 @@ permissions: jobs: build: runs-on: ubuntu-26.04 + timeout-minutes: 10 steps: - name: Checkout uses: actions/checkout@v7 diff --git a/.github/workflows/docker-scout.yml b/.github/workflows/docker-scout.yml index 239dee5..a92171a 100644 --- a/.github/workflows/docker-scout.yml +++ b/.github/workflows/docker-scout.yml @@ -24,6 +24,7 @@ jobs: # After a push that failed, Docker Hub still has the old image: nothing to rescan. if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-26.04 + timeout-minutes: 10 steps: - name: Checkout uses: actions/checkout@v7 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 341502e..434fab4 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -16,6 +16,7 @@ permissions: jobs: docker: runs-on: ubuntu-26.04 + timeout-minutes: 20 steps: # The tag being built, not the default branch. The image is built from this # checkout now, so a dispatched rebuild of an older version has to stand on diff --git a/.github/workflows/licenses.yml b/.github/workflows/licenses.yml index 7aac636..d6207b6 100644 --- a/.github/workflows/licenses.yml +++ b/.github/workflows/licenses.yml @@ -10,6 +10,7 @@ jobs: licenses: name: License Check runs-on: ubuntu-26.04 + timeout-minutes: 10 steps: - name: Checkout uses: actions/checkout@v7 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 43e49d9..7d0b171 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,6 +8,7 @@ jobs: build-and-publish: name: Build and publish to PyPI runs-on: ubuntu-26.04 + timeout-minutes: 30 environment: name: pypi url: https://pypi.org/p/patchradar diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index ee73bc8..843cdfa 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -13,6 +13,7 @@ jobs: # same answer four times. name: Quality runs-on: ubuntu-26.04 + timeout-minutes: 10 steps: - uses: actions/checkout@v7 - name: Set up Python diff --git a/.github/workflows/sbom.yml b/.github/workflows/sbom.yml index fe6455c..6cc377c 100644 --- a/.github/workflows/sbom.yml +++ b/.github/workflows/sbom.yml @@ -50,6 +50,7 @@ jobs: (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'release') runs-on: ubuntu-26.04 + timeout-minutes: 10 env: TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.event.workflow_run.head_branch }} IMAGE: maksimtech/patchradar diff --git a/.github/workflows/security-posture.yml b/.github/workflows/security-posture.yml index c3d6738..c6ed116 100644 --- a/.github/workflows/security-posture.yml +++ b/.github/workflows/security-posture.yml @@ -43,6 +43,7 @@ jobs: # is rerun and succeeds, or on the next push or schedule. if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-26.04 + timeout-minutes: 40 steps: - name: Checkout uses: actions/checkout@v7 diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index aa40e83..6b62a27 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -13,6 +13,7 @@ jobs: sonarcloud: name: SonarCloud runs-on: ubuntu-26.04 + timeout-minutes: 10 # GitHub passes no Actions secrets to Dependabot or fork PRs: there the # token is empty and the scan fails with "Not authorized". A step's `if:` # cannot read `secrets`, so the job publishes only whether it exists; the diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 023f70b..3ac47fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,7 @@ permissions: jobs: test: runs-on: ubuntu-26.04 + timeout-minutes: 10 strategy: fail-fast: false matrix: @@ -83,6 +84,7 @@ jobs: needs: [test] if: always() runs-on: ubuntu-26.04 + timeout-minutes: 10 steps: - name: All test jobs succeeded env: diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 8ffbf15..b62d96b 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -15,6 +15,7 @@ permissions: jobs: trivy: runs-on: ubuntu-26.04 + timeout-minutes: 10 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -42,6 +43,7 @@ jobs: image: name: Trivy image runs-on: ubuntu-26.04 + timeout-minutes: 10 steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dfeb9e..84d61d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,18 @@ what has already shipped, and for nothing else. See `RELEASING.md`. ## [Unreleased] +### Changed + +- **Every job has a time limit, so a hung job no longer holds a pull request for six hours.** No job + but mutmut set `timeout-minutes`, and GitHub's default is 360 minutes; on a required check the pull + request, and the auto-merge this repository allows, waited that long. Each limit is about three + times the job's longest run in its last 40 (ten minutes at least): 25 for the benchmarks, 20 for the + published image, 10 for the rest. Two jobs wait on purpose and get more than their runs suggest, so + they still say what they were waiting for: Security Posture 40, past the 20 minutes it waits for the + scanners and three times its longest run, and publishing 30, past the 15 minutes it waits for PyPI to + show and install the new version; the test reads both waits from the workflows + (`tests/test_job_timeouts.py`, maksimtech/apkradar#113). + ### Security - **CVE-2026-124709 (OpenSSL, QUIC) stays accepted now that Trivy reports it too.** Debian moved trixie diff --git a/tests/test_job_timeouts.py b/tests/test_job_timeouts.py new file mode 100644 index 0000000..e502bd8 --- /dev/null +++ b/tests/test_job_timeouts.py @@ -0,0 +1,72 @@ +"""Every job says how long it may run, so a hung job cannot hold a pull request for six hours. + +Without `timeout-minutes` a job runs for GitHub's default of 360 minutes. When it is a +required check the pull request waits that long, and so would an auto-merge +(maksimtech/apkradar#113). + +The limits are about three times the longest run of the job in its last 40 runs +(2026-11-21), and never under ten minutes: a short job is mostly installs and image pulls, +which are slow on a bad day without being stuck. + +A job that waits on purpose gets more than its runs suggest: its limit has to outlast its +own wait, or GitHub kills it before it can say what it was waiting for. The tests below +read those waits from the workflows, so a longer wait cannot outgrow its limit unseen. +""" +from __future__ import annotations + +import re +from pathlib import Path + +import yaml + +WORKFLOWS = Path(__file__).resolve().parents[1] / ".github" / "workflows" +GITHUB_DEFAULT = 360 + + +def jobs(): + for path in sorted(WORKFLOWS.glob("*.yml")): + workflow = yaml.safe_load(path.read_text(encoding="utf-8")) + for name, job in (workflow.get("jobs") or {}).items(): + yield f"{path.name}:{name}", job + + +def script(job: dict) -> str: + return "\n".join(step.get("run", "") for step in job.get("steps", [])) + + +def test_there_are_jobs_to_look_at(): + assert len(list(jobs())) > 10 + + +def test_every_job_declares_a_timeout_below_the_default(): + # A job that calls a reusable workflow cannot take `timeout-minutes`; the jobs of the + # workflow it calls are held here like any other. + wrong = {name: job.get("timeout-minutes") for name, job in jobs() + if "uses" not in job + and not (isinstance(job.get("timeout-minutes"), int) and 0 < job["timeout-minutes"] < GITHUB_DEFAULT)} + assert wrong == {}, f"jobs without a timeout under {GITHUB_DEFAULT} minutes: {wrong}" + + +def test_security_posture_outlives_its_own_wait(): + # The gate waits for the scanners up to a deadline of its own and then says they did not + # finish. A job timeout shorter than that would kill it first, with no such message. + job = dict(jobs())["security-posture.yml:posture"] + wait = int(re.search(r"deadline=\$\(\( SECONDS \+ (\d+) \)\)", script(job)).group(1)) + assert job["timeout-minutes"] * 60 >= wait + 5 * 60 + + +def test_publishing_outlives_its_waits_for_pypi(): + # After the upload the job installs the new version, asking again while the index + # catches up (install_from_pypi.sh: attempts x interval), and in the Radars that call it, + # first waits for the index to show it (wait_for_pypi.sh: attempts x interval, then a + # grace). A limit under those would end the job before either could say the version is + # not there. Ten more minutes for what the job does besides sleeping. + job = dict(jobs())["publish.yml:build-and-publish"] + run = script(job) + install = re.search(r'install_from_pypi\.sh \S+ \S+ "\$VERSION" (\d+) (\d+)', run) + assert install, "publish.yml no longer calls install_from_pypi.sh as this test reads it" + seconds = int(install[1]) * int(install[2]) + wait = re.search(r'wait_for_pypi\.sh \S+ "\$VERSION" (\d+) (\d+)(?: (\d+))?', run) + if wait: + seconds += int(wait[1]) * int(wait[2]) + int(wait[3] or 45) + assert job["timeout-minutes"] * 60 >= seconds + 10 * 60