How to Cache the uv Cache in GitHub Actions
Cache uv's global cache directory keyed on uv.lock so uv sync reuses already-downloaded wheels.
uv keeps a global cache of downloaded and built wheels. The astral-sh/setup-uv action can enable caching directly, or you can cache the directory from uv cache dir yourself keyed on uv.lock.
Steps
- Install uv with
astral-sh/setup-uvand setenable-cache: true, or cache manually. - For a manual cache, resolve the path with
uv cache dir. - Key the cache on
hashFiles('**/uv.lock'). - Run
uv sync --frozen.
Workflow
.github/workflows/ci.yml
steps:
- uses: actions/checkout@v4
- id: uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "dir=$(uv cache dir)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: ${{ steps.uv.outputs.dir }}
key: uv-${{ runner.os }}-${{ hashFiles('**/uv.lock') }}
restore-keys: |
uv-${{ runner.os }}-
- run: uv sync --frozenGotchas
- The
astral-sh/setup-uvaction withenable-cache: truehandles the cache path and key for you. - Use
uv sync --frozenso CI fails on lockfile drift rather than silently re-resolving.
Related guides
How to Cache pip Downloads in GitHub ActionsCache the pip download cache in GitHub Actions by resolving pip cache dir and keying the cache on requirement…
How to Cache a Poetry Virtualenv in GitHub ActionsCache the Poetry-managed virtualenv in GitHub Actions by setting virtualenvs-in-project and caching .venv key…