Skip to content

Commit 658306c

Browse files
Merge pull request #386 from tpvasconcelos/219-setup-uv-action
Use astral-sh/setup-uv in the setup-python composite action
2 parents 978b863 + abb6fa8 commit 658306c

2 files changed

Lines changed: 12 additions & 35 deletions

File tree

.github/actions/setup-python/action.yml

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ inputs:
66
python-version:
77
description: "Python version (e.g. '3.7', '3.8.13', '3.11.0-alpha.1', '3.x')."
88
required: true
9-
install-seed-packages:
10-
description: >
11-
Set to 'true' to install and/or upgrade seed packages (pip, setuptools, and wheel)
12-
before installing other packages.
13-
required: false
14-
default: "false"
159
requirements:
1610
description: "Optional list of arguments passed to `uv pip install` (e.g. 'numpy==1.19.5', '-r requirements.txt')."
1711
required: false
@@ -23,37 +17,19 @@ runs:
2317
with:
2418
python-version: "${{ inputs.python-version }}"
2519

20+
# Install uv and enable its built-in cache. The cache key takes the
21+
# platform, the uv version, and a hash of the files below into account.
22+
# See https://docs.astral.sh/uv/guides/integration/github/ for details.
23+
# NOTE: setup-uv publishes immutable releases only (no
24+
# floating major tags), so we pin the full version
2625
- name: Install uv
27-
shell: bash
28-
run: pip install --upgrade uv
29-
30-
# >>>>>>>> Caching uv packages >>>>>>>>
31-
32-
- name: Get uv cache dir
33-
id: uv-cache
34-
shell: bash
35-
run: echo "dir=$(uv cache dir)" >> $GITHUB_OUTPUT
36-
37-
- name: Get the current date in format YYYYWW (year and week-of-year)
38-
id: get-date
39-
shell: bash
40-
run: echo "date=$(/bin/date -u "+%Y%U")" >> $GITHUB_OUTPUT
41-
42-
- name: uv cache
43-
uses: actions/cache@v4
26+
uses: astral-sh/setup-uv@v9.0.0
4427
with:
45-
path: ${{ steps.uv-cache.outputs.dir }}
46-
# The cache's TTL is 7 days (one week)
47-
key: uv-${{ runner.os }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.date }}
48-
# Fall back to the previous week's cache
49-
restore-keys: uv-${{ runner.os }}-${{ inputs.python-version }}-
50-
51-
# <<<<<<<< Caching uv packages <<<<<<<<
52-
53-
- name: Install and/or upgrade seed packages
54-
if: ${{ inputs.install-seed-packages == 'true' }}
55-
shell: bash
56-
run: uv pip install --verbose --system --upgrade pip setuptools wheel
28+
enable-cache: true
29+
cache-suffix: "py${{ inputs.python-version }}"
30+
cache-dependency-glob: |
31+
pyproject.toml
32+
requirements/*.txt
5733
5834
- name: Install requirements
5935
if: ${{ inputs.requirements != '' }}

docs/reference/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Unreleased changes
1616
- Bump codecov/codecov-action from 5 to 6 ({gh-pr}`371`)
1717
- Bump actions/github-script from 8 to 9 ({gh-pr}`373`)
1818
- pre-commit autoupdate ({gh-pr}`374`)
19+
- Use the official `astral-sh/setup-uv` action to install and cache `uv` in CI ({gh-pr}`386`)
1920

2021
---
2122

0 commit comments

Comments
 (0)