diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml index ae187338..5fca25fb 100644 --- a/.github/workflows/version-check.yml +++ b/.github/workflows/version-check.yml @@ -31,21 +31,24 @@ jobs: # Get version from current PR PR_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'") - echo "PR_VERSION=$PR_VERSION" >> $GITHUB_ENV + echo "PR_VERSION=$PR_VERSION" >> "$GITHUB_ENV" # Get version from main branch MAIN_VERSION=$(git show origin/main:socketsecurity/__init__.py | grep -o "__version__.*" | awk '{print $3}' | tr -d "'") - echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV + echo "MAIN_VERSION=$MAIN_VERSION" >> "$GITHUB_ENV" export PR_VERSION export MAIN_VERSION # Compare against the latest published PyPI release. python3 <<'PY' + import http.client import json import os import subprocess + import time import tomllib + import urllib.error import urllib.request from packaging import version @@ -72,8 +75,47 @@ jobs: ) raise SystemExit(1) - with urllib.request.urlopen("https://pypi.org/pypi/socketsecurity/json") as response: - pypi_data = json.load(response) + # This is a required check, so a dropped connection to PyPI would + # otherwise block the merge until someone reruns the job. Retry + # network errors, timeouts and 5xx responses, and if PyPI still can't + # be read, say so instead of failing with a bare traceback that looks + # like a version problem. OSError covers URLError, timeouts and SSL + # errors; HTTPException covers a response cut off mid-read, which + # urllib doesn't wrap in URLError. + pypi_url = "https://pypi.org/pypi/socketsecurity/json" + attempts = 4 + pypi_data = None + for attempt in range(1, attempts + 1): + try: + with urllib.request.urlopen(pypi_url, timeout=15) as response: + pypi_data = json.load(response) + break + except urllib.error.HTTPError as exc: + if exc.code < 500: + print( + f"❌ PyPI returned HTTP {exc.code} for {pypi_url}, so the " + f"latest published version couldn't be read. This is " + f"not a problem with the version in this PR." + ) + raise SystemExit(1) + error = exc + except (OSError, http.client.HTTPException) as exc: + error = exc + if attempt < attempts: + delay = 2 ** attempt + print( + f"⚠️ PyPI request failed (attempt {attempt}/{attempts}): " + f"{error!r}. Retrying in {delay}s." + ) + time.sleep(delay) + + if pypi_data is None: + print( + f"❌ Couldn't reach PyPI ({pypi_url}) after {attempts} attempts; " + f"last error: {error!r}. This is a network problem, not a " + f"problem with the version in this PR. Rerun the job." + ) + raise SystemExit(1) published_versions = [] for raw in pypi_data.get("releases", {}).keys(): diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c9860fe..9b8ab334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 2.15.2 + +### Changed: retry the PyPI lookup in the version check + +- The `check_version` CI job now retries the PyPI request on connection + errors, timeouts and HTTP 5xx, and says when a failure is PyPI's rather + than the PR's version. No change to the CLI itself. + ## 2.15.1 ### Changed: bump pinned Coana CLI to 15.15.3 diff --git a/pyproject.toml b/pyproject.toml index a087a973..e0e26547 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.15.1" +version = "2.15.2" requires-python = ">= 3.11" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 828d3ccb..a4353933 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,4 +1,4 @@ __author__ = 'socket.dev' -__version__ = '2.15.1' +__version__ = '2.15.2' USER_AGENT_NAME = 'socket-python-cli' USER_AGENT = f'{USER_AGENT_NAME}/{__version__}' diff --git a/uv.lock b/uv.lock index cef0b651..2f60a6ee 100644 --- a/uv.lock +++ b/uv.lock @@ -1334,7 +1334,7 @@ wheels = [ [[package]] name = "socketsecurity" -version = "2.15.1" +version = "2.15.2" source = { editable = "." } dependencies = [ { name = "beautifulsoup4" },