mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-12-15 11:07:14 +00:00
Cache python installs (#621)
This pull request introduces support for caching Python installs in the GitHub Action, allowing users to cache not only dependencies but also the Python interpreter itself. This works by setting the `UV_PYTHON_INSTALL_DIR` to a subdirectory of the dependency cache path so that Python installs are directed there. Fixes #135 --------- Co-authored-by: Kevin Stillhammer <kevin.stillhammer@gmail.com>
This commit is contained in:
84
.github/workflows/test.yml
vendored
84
.github/workflows/test.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Actionlint
|
||||
uses: eifinger/actionlint-action@23c85443d840cd73bbecb9cddfc933cc21649a38 # v1.9.1
|
||||
uses: eifinger/actionlint-action@23c85443d840cd73bbecb9cddfc933cc21649a38 # v1.9.1
|
||||
- name: Run zizmor
|
||||
uses: zizmorcore/zizmor-action@e673c3917a1aef3c65c972347ed84ccd013ecda4 # v0.2.0
|
||||
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
|
||||
@@ -269,13 +269,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
[
|
||||
ubuntu-latest,
|
||||
macos-latest,
|
||||
macos-14,
|
||||
windows-latest,
|
||||
]
|
||||
os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
@@ -334,7 +328,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
@@ -371,8 +365,8 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
enable-cache: [ "true", "false", "auto" ]
|
||||
os: [ "ubuntu-latest", "selfhosted-ubuntu-arm64", "windows-latest" ]
|
||||
enable-cache: ["true", "false", "auto"]
|
||||
os: ["ubuntu-latest", "selfhosted-ubuntu-arm64", "windows-latest"]
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
@@ -389,8 +383,8 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
enable-cache: [ "true", "false", "auto" ]
|
||||
os: [ "ubuntu-latest", "selfhosted-ubuntu-arm64", "windows-latest" ]
|
||||
enable-cache: ["true", "false", "auto"]
|
||||
os: ["ubuntu-latest", "selfhosted-ubuntu-arm64", "windows-latest"]
|
||||
needs: test-setup-cache
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -836,6 +830,68 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
test-cache-python-installs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Verify Python install dir is not populated
|
||||
run: |
|
||||
if [ -d ~/.local/share/uv/python ]; then
|
||||
echo "Python install dir should not exist"
|
||||
exit 1
|
||||
fi
|
||||
- name: Setup uv with cache
|
||||
uses: ./
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-python: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-python-installs
|
||||
- run: uv sync --managed-python
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
- name: Verify Python install dir exists
|
||||
run: |
|
||||
if [ ! -d ~/.local/share/uv/python ]; then
|
||||
echo "Python install dir should exist"
|
||||
exit 1
|
||||
fi
|
||||
test-restore-python-installs:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test-cache-python-installs
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Verify Python install dir does not exist
|
||||
run: |
|
||||
if [ -d ~/.local/share/uv/python ]; then
|
||||
echo "Python install dir should not exist"
|
||||
exit 1
|
||||
fi
|
||||
- name: Restore with cache
|
||||
id: restore
|
||||
uses: ./
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-python: true
|
||||
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-cache-python-installs
|
||||
- name: Verify Python install dir exists
|
||||
run: |
|
||||
if [ ! -d ~/.local/share/uv/python ]; then
|
||||
echo "Python install dir should exist"
|
||||
exit 1
|
||||
fi
|
||||
- name: Cache was hit
|
||||
run: |
|
||||
if [ "$CACHE_HIT" != "true" ]; then
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
|
||||
- run: uv sync --managed-python
|
||||
working-directory: __tests__/fixtures/uv-project
|
||||
|
||||
all-tests-passed:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
@@ -878,6 +934,8 @@ jobs:
|
||||
- test-relative-path
|
||||
- test-cache-prune-force
|
||||
- test-cache-dir-from-file
|
||||
- test-cache-python-installs
|
||||
- test-restore-python-installs
|
||||
if: always()
|
||||
steps:
|
||||
- name: All tests passed
|
||||
|
||||
Reference in New Issue
Block a user