diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml index b0ab2917..47c3fb6a 100644 --- a/.github/actions/setup-python/action.yml +++ b/.github/actions/setup-python/action.yml @@ -6,12 +6,6 @@ inputs: python-version: description: "Python version (e.g. '3.7', '3.8.13', '3.11.0-alpha.1', '3.x')." required: true - install-seed-packages: - description: > - Set to 'true' to install and/or upgrade seed packages (pip, setuptools, and wheel) - before installing other packages. - required: false - default: "false" requirements: description: "Optional list of arguments passed to `uv pip install` (e.g. 'numpy==1.19.5', '-r requirements.txt')." required: false @@ -23,37 +17,19 @@ runs: with: python-version: "${{ inputs.python-version }}" + # Install uv and enable its built-in cache. The cache key takes the + # platform, the uv version, and a hash of the files below into account. + # See https://docs.astral.sh/uv/guides/integration/github/ for details. + # NOTE: setup-uv publishes immutable releases only (no + # floating major tags), so we pin the full version - name: Install uv - shell: bash - run: pip install --upgrade uv - - # >>>>>>>> Caching uv packages >>>>>>>> - - - name: Get uv cache dir - id: uv-cache - shell: bash - run: echo "dir=$(uv cache dir)" >> $GITHUB_OUTPUT - - - name: Get the current date in format YYYYWW (year and week-of-year) - id: get-date - shell: bash - run: echo "date=$(/bin/date -u "+%Y%U")" >> $GITHUB_OUTPUT - - - name: uv cache - uses: actions/cache@v4 + uses: astral-sh/setup-uv@v9.0.0 with: - path: ${{ steps.uv-cache.outputs.dir }} - # The cache's TTL is 7 days (one week) - key: uv-${{ runner.os }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.date }} - # Fall back to the previous week's cache - restore-keys: uv-${{ runner.os }}-${{ inputs.python-version }}- - - # <<<<<<<< Caching uv packages <<<<<<<< - - - name: Install and/or upgrade seed packages - if: ${{ inputs.install-seed-packages == 'true' }} - shell: bash - run: uv pip install --verbose --system --upgrade pip setuptools wheel + enable-cache: true + cache-suffix: "py${{ inputs.python-version }}" + cache-dependency-glob: | + pyproject.toml + requirements/*.txt - name: Install requirements if: ${{ inputs.requirements != '' }} diff --git a/docs/reference/changelog.md b/docs/reference/changelog.md index 869812eb..1b98a25c 100644 --- a/docs/reference/changelog.md +++ b/docs/reference/changelog.md @@ -16,6 +16,7 @@ Unreleased changes - Bump codecov/codecov-action from 5 to 6 ({gh-pr}`371`) - Bump actions/github-script from 8 to 9 ({gh-pr}`373`) - pre-commit autoupdate ({gh-pr}`374`) +- Use the official `astral-sh/setup-uv` action to install and cache `uv` in CI ({gh-pr}`386`) ---