From 72154ad879e2acebbbf46e27f77a3a4bde3f2ea2 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 9 Jun 2026 18:11:23 +0530 Subject: [PATCH] perf(ci): cache uv + use uv sync in tests workflow Both jobs in tests.yml (`test` matrix and `e2e`) start from a cold uv cache on every run and install deps with `uv pip install -e ".[all,dev]"`, which re-resolves pyproject.toml ranges and rebuilds the editable install each time. Two changes: 1. Enable uv's official CI caching via setup-uv's `enable-cache: true`, keyed on pyproject.toml + uv.lock, plus `uv cache prune --ci` to keep the persisted cache small. Warm runs install from cache instead of re-downloading/building wheels. 2. Replace the manual `uv venv` + `uv pip install -e` with `uv sync --locked --python 3.11 --extra all --extra dev`. sync installs the exact pinned set from uv.lock (and fails if the lock is stale vs pyproject.toml), creating .venv itself. This is reproducible and, with a warm cache, measurably faster than the editable pip install (~3-4x on the steady-state install step locally). Downstream steps keep using `source .venv/bin/activate`; sync writes .venv to the same path. Follows the Astral-recommended pattern for uv in GitHub Actions: https://docs.astral.sh/uv/guides/integration/github/ Co-authored-by: Wesley Simplicio --- .github/workflows/tests.yml | 48 ++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2755641073a..cc7d099fd93 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -55,15 +55,31 @@ jobs: - name: Install uv uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5 + with: + # Persist uv's download/wheel cache (~/.cache/uv) across runs. + # Keyed on the dependency manifests, so the cache is reused until + # pyproject.toml or uv.lock changes. `uv sync` still runs every + # time, but resolves from the warm cache instead of re-downloading + # and re-building wheels. + enable-cache: true + cache-dependency-glob: | + pyproject.toml + uv.lock - name: Set up Python 3.11 run: uv python install 3.11 - name: Install dependencies - run: | - uv venv .venv --python 3.11 - source .venv/bin/activate - uv pip install -e ".[all,dev]" + # `uv sync --locked` installs the exact pinned set from uv.lock (and + # fails if the lock is out of sync with pyproject.toml), giving a + # reproducible env. It also creates .venv itself, so no separate + # `uv venv` step is needed. + run: uv sync --locked --python 3.11 --extra all --extra dev + + - name: Minimize uv cache + # Optimized for CI: prunes pre-built wheels that are cheap to + # re-download, keeping the persisted cache small and fast to restore. + run: uv cache prune --ci - name: Run tests (slice ${{ matrix.slice }}/6) # Per-file isolation via scripts/run_tests_parallel.py: discovers @@ -161,15 +177,31 @@ jobs: - name: Install uv uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5 + with: + # Persist uv's download/wheel cache (~/.cache/uv) across runs. + # Keyed on the dependency manifests, so the cache is reused until + # pyproject.toml or uv.lock changes. `uv sync` still runs every + # time, but resolves from the warm cache instead of re-downloading + # and re-building wheels. + enable-cache: true + cache-dependency-glob: | + pyproject.toml + uv.lock - name: Set up Python 3.11 run: uv python install 3.11 - name: Install dependencies - run: | - uv venv .venv --python 3.11 - source .venv/bin/activate - uv pip install -e ".[all,dev]" + # `uv sync --locked` installs the exact pinned set from uv.lock (and + # fails if the lock is out of sync with pyproject.toml), giving a + # reproducible env. It also creates .venv itself, so no separate + # `uv venv` step is needed. + run: uv sync --locked --python 3.11 --extra all --extra dev + + - name: Minimize uv cache + # Optimized for CI: prunes pre-built wheels that are cheap to + # re-download, keeping the persisted cache small and fast to restore. + run: uv cache prune --ci - name: Packaged-wheel i18n smoke test run: |