uv icon indicating copy to clipboard operation
uv copied to clipboard

Use action/cache in GitHub Actions docs

Open simonw opened this issue 1 year ago • 8 comments

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.

simonw avatar Aug 21 '24 00:08 simonw

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.

simonw avatar Aug 21 '24 00:08 simonw

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.

zanieb avatar Aug 21 '24 03:08 zanieb

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:

CleanShot 2024-08-20 at 20 22 53@2x

There may be ways to make this shorter and tighter.

simonw avatar Aug 21 '24 03:08 simonw

I have been using https://github.com/hynek/setup-cached-uv, and it's been working well for me. :)

skshetry avatar Aug 21 '24 03:08 skshetry

Note that setup-cached-uv is different in that it persists the uv cache to GitHub.

zanieb avatar Aug 21 '24 12:08 zanieb

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.

simonw avatar Aug 21 '24 14:08 simonw

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?

danielhollas avatar Aug 21 '24 17:08 danielhollas

uv seems to download and install in ~1 second

zanieb avatar Aug 21 '24 18:08 zanieb

Resolved by #7056

zanieb avatar Sep 05 '24 00:09 zanieb