Files
computer-playbook/utils/install/github_release.py
T
kevinveenbirkenbachandClaude Opus 4.7 65e2fa82fa fix(install): cap urlopen with explicit timeouts in install-lint helpers
`make install-lint` could hang indefinitely on the actionlint /
markdownlint binary download because the underlying `urlopen` calls
in `utils.install.github_release.resolve_latest_tag` and
`utils.install.primitives.download_file` ran without a timeout
parameter. Slow / dropped TLS handshakes against `github.com` (e.g.
behind an MTU-broken bridge) translated into a frozen install step
with no error.

Adds keyword-only `timeout=` parameters with sensible defaults:
30s for the latest-tag redirect resolve, 60s for the actual binary
download. Either can be lowered per call.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 14:55:10 +02:00

34 lines
1.1 KiB
Python

"""GitHub-release asset helpers (latest-tag resolver + downloader)."""
from __future__ import annotations
from urllib.request import urlopen
from utils.install.primitives import download_file
def resolve_latest_tag(latest_url: str, *, timeout: float = 30.0) -> str:
# GitHub redirects /releases/latest -> /releases/tag/v<version>;
# final-URL last segment minus a leading 'v' is the version.
with urlopen(latest_url, timeout=timeout) as response: # noqa: S310 - trusted github URL
final_url = response.geturl()
final_url = final_url.rstrip("/")
if not final_url:
raise RuntimeError("Failed to resolve latest release URL.")
if final_url == latest_url:
raise RuntimeError("Latest release URL did not resolve to a versioned tag.")
tag = final_url.rsplit("/", 1)[-1]
tag = tag.removeprefix("v")
if not tag or tag in (final_url, "latest"):
raise RuntimeError(f"Failed to determine version from {final_url}.")
return tag
def download_release_asset(url: str, output: str) -> None:
download_file(url, output)
__all__ = ["download_release_asset", "resolve_latest_tag"]