uv
uv copied to clipboard
Best practices for using uv's cache in CI / Github Actions?
Wondering if there's any advice or best practices starting to develop around how to (re)use and share the uv cache across multiple Github Actions runners?
We repeat the same Python installations across multiple runners / OSes and Python versions. Previously we were taking advantage of Github Actions' caching to save us from redownloading packages, but not any more with uv as it it isn't clear how best to reuse the cache or to what extent that helps.
There is an issue on GitHub Action setup-python discussing this: https://github.com/actions/setup-python/issues/822. They argue that the benefit of caching uv .cache folder depends.
See also previous discussion at https://github.com/astral-sh/uv/issues/1386
I made a composite action that sets up uv with optional caching, after piecing together all of the information in the various places about how to get things to work.
https://github.com/drivendataorg/setup-python-uv-action
It supports:
- no caching
- caching the uv packages cache
- caching the virtual environment directory itself
I'm reasonably confident all options should work across the different OS runners.
Your mileage may vary on what actually saves time, depending on what your dependencies are. uv resolution and installation is so fast, that I've found the network speed to be the limiting factor in a lot of cases. Downloading from PyPI is often just as fast as loading a cache. Windows runners seem to have particularly bad cache performance so sometimes the cache is actually slower on Windows than downloading from PyPI.
I've been playing with replacing pip with uv in our Gitlab CI pipeline, and it massively speeds up installing packages when you've got the cache. However, I've noticed that the uv cache is notably larger than the pip one (along with significantly more files), and the increase in Gitlab's cache time almost outweighs the shift to uv. Anyone else run into this?
I recently just noticed that there's a 40GB uv cache sitting on my HD, too.
(Can always uv cache clean or uv cache prune.)