Skip to content

Commit

Permalink
Add documentation for caching the uv cache in GHA (#5663)
Browse files Browse the repository at this point in the history
Related to #5409
  • Loading branch information
zanieb committed Jul 31, 2024
1 parent d05f2b2 commit ef84380
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion docs/guides/integration/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,48 @@ steps:
- name: Run tests
# For example, using `pytest`
run: uv run -- pytest tests
run: uv run pytest tests
```
## Caching
It may improve CI times to store uv's cache across workflow runs.
The cache can be saved and restored with the official GitHub `cache` action:

```yaml title="example.yml"
jobs:
install_job:
env:
# Configure a constant location for the uv cache
UV_CACHE_DIR: /tmp/.uv-cache
steps:
# ... setup up Python and uv ...
- name: Restore uv cache
uses: actions/cache@v4
with:
path: /tmp/.uv-cache
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
restore-keys: |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
uv-${{ runner.os }}
# ... install packages, run tests, etc ...
- name: Minimize uv cache
run: uv cache prune --ci
```

The `uv cache prune --ci` command is used to reduce the size of the cache and is optimized for CI.
Its effect on performance is dependent on the packages being installed.

!!! tip

If using `uv pip`, use `requirements.txt` instead of `uv.lock` in the cache key.

## Using `uv pip`

If using the `uv pip` interface instead of the uv project interface, uv requires a virtual
Expand Down

0 comments on commit ef84380

Please sign in to comment.