Skip to content

Commit bee382f

Browse files
committed
build: experimental python env and pip caching
1 parent 7aa5f77 commit bee382f

File tree

1 file changed

+105
-3
lines changed

1 file changed

+105
-3
lines changed

.github/workflows/python-package.yml

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,41 @@ jobs:
2222
- uses: actions/checkout@v4
2323
- name: Install uv
2424
uses: astral-sh/setup-uv@v3
25-
- uses: actions/setup-python@v5
25+
- id: setup-python
26+
uses: actions/setup-python@v5
27+
28+
# PYTHON CACHING:
29+
- id: python-cache
30+
uses: actions/cache@v4
31+
with:
32+
path: |
33+
${{ env.pythonLocation }}/lib
34+
${{ env.pythonLocation }}/bin
35+
key: >
36+
os${{ runner.os }}-
37+
py${{ steps.setup-python.outputs.python-version }}-
38+
req${{ hashFiles('setup.cfg') }}
39+
- id: get-uv-cache
40+
if: steps.python-cache.outputs.cache-hit != 'true'
41+
run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT}
42+
- name: "Cache uv"
43+
if: steps.python-cache.outputs.cache-hit != 'true'
44+
uses: actions/cache@v4
45+
with:
46+
path: ${{steps.get-uv-cache.outputs.uv-cache-dir}}
47+
key: >
48+
os${{ runner.os }}-
49+
py${{ steps.setup-python.outputs.python-version }}-
50+
req${{ hashFiles('setup.cfg') }}
51+
restore-keys: "\
52+
os${{ runner.os }}-\
53+
py${{ steps.setup-python.outputs.python-version }}-
54+
55+
os${{ runner.os }}-
56+
57+
"
58+
# END PYTHON CACHING
59+
2660
- name: Build wheel distribution
2761
run: uv build --wheel
2862
- name: Upload wheel for other jobs
@@ -118,10 +152,44 @@ jobs:
118152
with:
119153
fetch-depth: 0
120154
# need full history since Pytest runs Darker itself below
121-
- name: Set up Python ${{ matrix.python-version }}
155+
- id: setup-python
156+
name: Set up Python ${{ matrix.python-version }}
122157
uses: actions/setup-python@v5
123158
with:
124159
python-version: ${{ matrix.python-version }}
160+
161+
# PYTHON CACHING:
162+
- id: python-cache
163+
uses: actions/cache@v4
164+
with:
165+
path: |
166+
${{ env.pythonLocation }}/lib
167+
${{ env.pythonLocation }}/bin
168+
key: >
169+
os${{ runner.os }}-
170+
py${{ steps.setup-python.outputs.python-version }}-
171+
req${{ hashFiles('setup.cfg') }}
172+
- id: get-uv-cache
173+
if: steps.python-cache.outputs.cache-hit != 'true'
174+
run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT}
175+
- name: "Cache uv"
176+
if: steps.python-cache.outputs.cache-hit != 'true'
177+
uses: actions/cache@v4
178+
with:
179+
path: ${{steps.get-uv-cache.outputs.uv-cache-dir}}
180+
key: >
181+
os${{ runner.os }}-
182+
py${{ steps.setup-python.outputs.python-version }}-
183+
req${{ hashFiles('setup.cfg') }}
184+
restore-keys: "\
185+
os${{ runner.os }}-\
186+
py${{ steps.setup-python.outputs.python-version }}-
187+
188+
os${{ runner.os }}-
189+
190+
"
191+
# END PYTHON CACHING
192+
125193
- name: Download wheel uploaded by the build-wheel job
126194
uses: actions/download-artifact@v4
127195
- name: Install Darker and its dependencies from the wheel built earlier
@@ -147,7 +215,41 @@ jobs:
147215
- uses: actions/checkout@v4
148216
- name: Install uv
149217
uses: astral-sh/setup-uv@v3
150-
- uses: actions/setup-python@v5
218+
- id: setup-python
219+
uses: actions/setup-python@v5
220+
221+
# PYTHON CACHING:
222+
- id: python-cache
223+
uses: actions/cache@v4
224+
with:
225+
path: |
226+
${{ env.pythonLocation }}/lib
227+
${{ env.pythonLocation }}/bin
228+
key: >
229+
os${{ runner.os }}-
230+
py${{ steps.setup-python.outputs.python-version }}-
231+
req${{ hashFiles('setup.cfg') }}
232+
- id: get-uv-cache
233+
if: steps.python-cache.outputs.cache-hit != 'true'
234+
run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT}
235+
- name: "Cache uv"
236+
if: steps.python-cache.outputs.cache-hit != 'true'
237+
uses: actions/cache@v4
238+
with:
239+
path: ${{steps.get-uv-cache.outputs.uv-cache-dir}}
240+
key: >
241+
os${{ runner.os }}-
242+
py${{ steps.setup-python.outputs.python-version }}-
243+
req${{ hashFiles('setup.cfg') }}
244+
restore-keys: "\
245+
os${{ runner.os }}-\
246+
py${{ steps.setup-python.outputs.python-version }}-
247+
248+
os${{ runner.os }}-
249+
250+
"
251+
# END PYTHON CACHING
252+
151253
- name: Download wheel uploaded by the build-wheel job
152254
uses: actions/download-artifact@v4
153255
- name: Build source distribution

0 commit comments

Comments
 (0)