From 0a164aa23a86f9d0326a58654becaec918c20975 Mon Sep 17 00:00:00 2001 From: Edoardo Rosa <6991986+notdodo@users.noreply.github.com> Date: Sun, 15 Nov 2026 12:15:42 +0100 Subject: [PATCH] ci: keep built wheels across lockfile changes and pin the packaging smoke test The packaging test installed the built wheel with `uv run --with`, which resolves the newest releases instead of uv.lock. Setup-uv's cache is keyed on the lockfile with no fallback, so after a lockfile change Python 3.15 compiled pydantic-core, regex, zstandard and others inside that test (about 85s). Install the wheel into a fresh venv constrained to `uv export --locked`, and cache the uv directory together with the venv under one key that falls back to the latest entry for the same Python version. Prune the uv cache with `--ci` so only locally built wheels are kept. --- .github/workflows/python-ci.yml | 14 +++++++++----- tests/package_contract/test_packaging.py | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index a159f81..8dcf5e1 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -19,6 +19,7 @@ jobs: python: ['3.13', '3.14', '3.15'] env: UV_LOCKED: '1' + UV_CACHE_DIR: /home/runner/.cache/uv steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -26,17 +27,18 @@ jobs: - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 with: python-version: ${{ matrix.python }} - enable-cache: true - cache-python: true - cache-suffix: python-${{ matrix.python }} + enable-cache: false + # One cache with a fallback, so a lockfile change keeps the venv and the locally built wheels (Python 3.15 builds several + # dependencies from source) instead of starting over. - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: | .venv .mypy_cache - key: python-${{ matrix.python }}-venv-${{ hashFiles('uv.lock') }} + /home/runner/.cache/uv + key: python-${{ matrix.python }}-deps-${{ hashFiles('uv.lock') }} restore-keys: | - python-${{ matrix.python }}-venv- + python-${{ matrix.python }}-deps- - name: Install Task uses: go-task/setup-task@a00fbb05ce67b35648be3c78cbc9fd85354c757e # v2.2.0 with: @@ -51,6 +53,8 @@ jobs: run: task test - name: Build run: uv build + - name: Prune the uv cache + run: uv cache prune --ci infra-scan: name: Scan with KICS diff --git a/tests/package_contract/test_packaging.py b/tests/package_contract/test_packaging.py index 7f8abfe..951379a 100644 --- a/tests/package_contract/test_packaging.py +++ b/tests/package_contract/test_packaging.py @@ -2,6 +2,7 @@ import shutil import subprocess +import sys from pathlib import Path from zipfile import ZipFile @@ -26,15 +27,21 @@ def test_wheel_contains_py_typed(tmp_path: Path) -> None: with ZipFile(wheels[0]) as wheel: assert "digintlab_langfuse/py.typed" in wheel.namelist() + constraints = tmp_path / "constraints.txt" + venv_dir = tmp_path / "venv" + setup_commands = ( + # Pin the clean install to uv.lock so it reuses cached builds instead of resolving and compiling the newest releases. + [uv, "export", "--locked", "--no-dev", "--no-emit-project", "--no-hashes", "--no-header", "--output-file", str(constraints)], + [uv, "venv", "--python", sys.executable, str(venv_dir)], + [uv, "pip", "install", "--python", str(venv_dir), "--constraint", str(constraints), str(wheels[0])], + ) + for command in setup_commands: + setup_result = subprocess.run(command, cwd=repo_root, text=True, capture_output=True, check=False) # noqa: S603 + assert setup_result.returncode == 0, setup_result.stdout + setup_result.stderr + import_result = subprocess.run( # noqa: S603 [ - uv, - "run", - "--isolated", - "--no-project", - "--with", - str(wheels[0]), - "python", + str(venv_dir / "bin" / "python"), "-c", ( "import digintlab_langfuse\n"