mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-03 18:38:21 +00:00
Add documentation for caching the uv cache in GHA (#5663)
Related to https://github.com/astral-sh/uv/issues/5409
This commit is contained in:
parent
d05f2b258b
commit
ef84380954
1 changed files with 40 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue