uv
uv copied to clipboard
Use action/cache in GitHub Actions docs
These docs currently suggest: https://docs.astral.sh/uv/guides/integration/github/
steps:
- uses: actions/checkout@v4
- name: Set up uv
# Install a specific uv version using the installer
run: curl -LsSf https://astral.sh/uv/0.3.0/install.sh | sh
I’m not a fan of that pattern without caching - it feels wasteful to download from outside the GitHub network on every run, plus an astral.sh outage would break my builds.
It would be nice if this example used action/cache to avoid duplicate downloads where possible.
Alternatively this recipe could use this URL instead:
https://github.com/astral-sh/uv/releases/download/0.3.0/uv-installer.sh
Which would at least keep all network traffic within GitHub.
I think we'll probably provide a setup-uv action in the future that manages installation, presumably that could handle caching. I'm pretty hesitant to complicate the integration guide here, but am willing to consider using action/cache in a subsequent example if you want to share how you would do it.
setup-uv action would be fantastic - or even getting uv into the default runner, but that's GitHub's call.
I messed around with caching a bit and got this to work:
name: uv example
on:
workflow_dispatch:
jobs:
uv-example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: cache-cargo-bin
uses: actions/cache@v4
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-bin
- id: cache-uv-python
uses: actions/cache@v4
with:
path: ~/.local/share/uv
key: ${{ runner.os }}-uv-python
- name: Install uv
if: steps.cache-cargo-bin.outputs.cache-hit != 'true'
run: |
curl -LsSf https://astral.sh/uv/0.3.0/install.sh | sh
- name: Run uv
run: |
python -c 'import sys; print("Before:", sys.version)'
uv python install
uv run python -c 'import sys; print(sys.version)'
The second time I ran that the output looked like this, showing the cache working:
There may be ways to make this shorter and tighter.
I have been using https://github.com/hynek/setup-cached-uv, and it's been working well for me. :)
Note that setup-cached-uv is different in that it persists the uv cache to GitHub.
An official Astral version of that reusable Action would be really neat. My interest is primarily in avoiding hitting external network resources for repeat runs of my CI builds.
I’m not a fan of that pattern without caching - it feels wasteful to download from outside the GitHub network on every run, plus an astral.sh outage would break my builds.
Given Github Actions track record I'd honestly be more wary of github cache outage in this case. :-D
But more seriously, I am curious if measured any speed difference between these approaches?
uv seems to download and install in ~1 second
Resolved by #7056