From 53746966acfa03ba85e8c8d20c99147a6b0b9c5e Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Thu, 3 Dec 2026 00:19:16 +0100 Subject: [PATCH] Cache `uv` between CI runs All jobs restore built wheels (e.g., `rpy2`) and the Python versions instead of building or fetching them again. Only the "lint" job saves the cache, pruned to what is expensive to rebuild, and only when its key changed; so, five jobs do not compress the same archive in parallel, and unchanged runs skip the 15s of packing. --- .forgejo/actions/setup/action.yaml | 20 ++++++++++++++++++++ .forgejo/workflows/ci.yaml | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/.forgejo/actions/setup/action.yaml b/.forgejo/actions/setup/action.yaml index d7c6e93..c982842 100644 --- a/.forgejo/actions/setup/action.yaml +++ b/.forgejo/actions/setup/action.yaml @@ -17,6 +17,26 @@ runs: r-cran-zoo \ -y + # Built wheels (e.g., `rpy2`) and Python versions + # => A new key whenever the pinned dependencies or Python versions change + # => Only the "lint" job in ci.yaml saves the cache + - name: Restore the `uv` cache + id: uv-cache + uses: actions/cache/restore@v4 + with: + path: | + ~/.cache/uv + ~/.local/share/uv/python + key: uv-${{ runner.os }}-${{ hashFiles('uv.lock', 'pyproject.toml') }} + restore-keys: uv-${{ runner.os }}- + + # Tell the "lint" job in ci.yaml the key and if it must save the cache + - name: Remember the `uv` cache key and if it was restored exactly + shell: bash + run: | + echo "UV_CACHE_KEY=${{ steps.uv-cache.outputs.cache-primary-key }}" >> "$FORGEJO_ENV" + echo "UV_CACHE_HIT=${{ steps.uv-cache.outputs.cache-hit }}" >> "$FORGEJO_ENV" + # All `SUPPORTED_PYTHONS` from the "classifiers" in pyproject.toml # => `nox` would otherwise pick the system's Python without headers - name: Install `uv` and all supported Python versions diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index 6dc4777..15b23d0 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -70,6 +70,21 @@ jobs: env: SKIP: local-format,local-lint,local-test,local-test-docstrings,local-test-types,no-commit-to-branch + # Only this job saves the `uv` cache that ./.forgejo/actions/setup restores + # => Keep only what is expensive to rebuild, not wheels that are cheap to download + - name: Shrink the `uv` cache + if: env.UV_CACHE_HIT != 'true' + run: uv cache prune --ci + + - name: Save the `uv` cache + if: env.UV_CACHE_HIT != 'true' + uses: actions/cache/save@v4 + with: + path: | + ~/.cache/uv + ~/.local/share/uv/python + key: ${{ env.UV_CACHE_KEY }} + tests: name: Tests (${{ matrix.session }})