-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Short version
Add a cross-platform way to find out the uv cache directory (like pip has) for use on GitHub Actions.
Long version
If we want to cache things installed by uv pip install on GitHub Actions, we need to do something like this:
- uses: actions/cache@v4
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/uv
key: ${{ runner.os }}-uv-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-uv-
- uses: actions/cache@v4
if: startsWith(runner.os, 'macOS')
with:
path: ~/Library/Caches/uv
key: ${{ runner.os }}-uv-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-uv-
- uses: actions/cache@v4
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\uv\Cache
key: ${{ runner.os }}-uv-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-uv-Adapted from https://github.com/actions/cache/blob/main/examples.md#multiple-oss-in-a-workflow
Or:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
path: ~/.cache/uv
- os: macos-latest
path: ~/Library/Caches/uv
- os: windows-latest
path: ~\AppData\Local\uv\Cache
steps:
- uses: actions/cache@v4
with:
path: ${{ matrix.path }}
key: ${{ runner.os }}-uv-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-uv-Adapted from https://github.com/actions/cache/blob/main/examples.md#multiple-oss-in-a-workflow-with-a-matrix
Or we may be able to choose a common directory using the --cache-dir flag or UV_CACHE_DIR environment variable.
Originally we had to do the same thing with pip (hence the examples at actions/cache).
But then pip 20.1 added a pip cache dir command (pypa/pip#7350 / pypa/pip#8095):
❯ pip cache dir
/Users/hugo/Library/Caches/pipIf we add uv pip cache dir, we would similarly be able to simplify the config:
- name: Get uv cache dir
id: uv-cache
run: |
echo "dir=$(uv cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-uv-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-uv-Adapted from https://github.com/actions/cache/blob/main/examples.md#using-pip-to-get-cache-location