Skip to content

Commit 9a877ca

Browse files
authored
Use yaml anchors for workflow (#2824)
* Use yaml anchors for workflow * Don't pre-install setuptools and wheel in CI envs
1 parent 7b83121 commit 9a877ca

File tree

1 file changed

+28
-59
lines changed

1 file changed

+28
-59
lines changed

.github/workflows/ci.yaml

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ jobs:
2424
runs-on: ubuntu-latest
2525
timeout-minutes: 20
2626
steps:
27-
- name: Check out code from GitHub
27+
- &checkout
28+
name: Check out code from GitHub
2829
uses: actions/[email protected]
29-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
30+
- &setup-python-default
31+
name: Set up Python ${{ env.DEFAULT_PYTHON }}
3032
id: python
3133
uses: actions/[email protected]
3234
with:
@@ -38,7 +40,8 @@ jobs:
3840
echo "key=base-venv-${{ env.CACHE_VERSION }}-${{
3941
hashFiles('pyproject.toml', 'requirements_dev.txt',
4042
'requirements_full.txt', 'requirements_minimal.txt') }}" >> $GITHUB_OUTPUT
41-
- name: Restore Python virtual environment
43+
- &cache-python
44+
name: Restore Python virtual environment
4245
id: cache-venv
4346
uses: actions/[email protected]
4447
with:
@@ -51,7 +54,7 @@ jobs:
5154
run: |
5255
python -m venv venv
5356
. venv/bin/activate
54-
python -m pip install -U pip setuptools wheel
57+
python -m pip install -U pip
5558
pip install -U -r requirements_full.txt
5659
- name: Generate pre-commit restore key
5760
id: generate-pre-commit-key
@@ -82,12 +85,11 @@ jobs:
8285
strategy:
8386
fail-fast: false
8487
matrix:
85-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
88+
python-version: &matrix-python-version ["3.10", "3.11", "3.12", "3.13", "3.14"]
8689
outputs:
8790
python-key: ${{ steps.generate-python-key.outputs.key }}
8891
steps:
89-
- name: Check out code from GitHub
90-
uses: actions/[email protected]
92+
- *checkout
9193
- name: Set up Python ${{ matrix.python-version }}
9294
id: python
9395
uses: actions/[email protected]
@@ -106,14 +108,7 @@ jobs:
106108
echo "key=${{ env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{
107109
hashFiles('pyproject.toml', 'requirements_dev.txt',
108110
'requirements_full.txt', 'requirements_minimal.txt') }}" >> $GITHUB_OUTPUT
109-
- name: Restore Python virtual environment
110-
id: cache-venv
111-
uses: actions/[email protected]
112-
with:
113-
path: venv
114-
key: >-
115-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
116-
steps.generate-python-key.outputs.key }}
111+
- *cache-python
117112
- name: Create Python virtual environment
118113
if: steps.cache-venv.outputs.cache-hit != 'true'
119114
run: |
@@ -127,7 +122,7 @@ jobs:
127122
. venv/bin/activate
128123
pytest --cov
129124
- name: Upload coverage artifact
130-
uses: actions/[email protected]
125+
uses: &actions-upload-artifact actions/[email protected]
131126
with:
132127
name: coverage-linux-${{ matrix.python-version }}
133128
path: .coverage
@@ -137,7 +132,7 @@ jobs:
137132
name: tests / run / ${{ matrix.python-version }} / Windows
138133
runs-on: windows-latest
139134
timeout-minutes: 20
140-
needs: tests-linux
135+
needs: [tests-linux]
141136
strategy:
142137
fail-fast: false
143138
matrix:
@@ -147,9 +142,9 @@ jobs:
147142
run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
148143
# Workaround to set correct temp directory on Windows
149144
# https://github.com/actions/virtual-environments/issues/712
150-
- name: Check out code from GitHub
151-
uses: actions/[email protected]
152-
- name: Set up Python ${{ matrix.python-version }}
145+
- *checkout
146+
- &setup-python-matrix
147+
name: Set up Python ${{ matrix.python-version }}
153148
id: python
154149
uses: actions/[email protected]
155150
with:
@@ -162,28 +157,21 @@ jobs:
162157
echo "key=${{ env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{
163158
hashFiles('pyproject.toml', 'requirements_dev.txt',
164159
'requirements_full.txt', 'requirements_minimal.txt') }}" >> $GITHUB_OUTPUT
165-
- name: Restore Python virtual environment
166-
id: cache-venv
167-
uses: actions/[email protected]
168-
with:
169-
path: venv
170-
key: >-
171-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
172-
steps.generate-python-key.outputs.key }}
160+
- *cache-python
173161
- name: Create Python virtual environment
174162
if: steps.cache-venv.outputs.cache-hit != 'true'
175163
run: |
176164
python -m venv venv
177165
. venv\\Scripts\\activate
178-
python -m pip install -U pip setuptools wheel
166+
python -m pip install -U pip
179167
pip install -U -r requirements_full.txt
180168
pip install -e .
181169
- name: Run pytest
182170
run: |
183171
. venv\\Scripts\\activate
184172
pytest --cov
185173
- name: Upload coverage artifact
186-
uses: actions/upload-artifact@v4.6.2
174+
uses: *actions-upload-artifact
187175
with:
188176
name: coverage-windows-${{ matrix.python-version }}
189177
path: .coverage
@@ -199,42 +187,29 @@ jobs:
199187
# We only test on the lowest and highest supported PyPy versions
200188
python-version: ["pypy3.10"]
201189
steps:
202-
- name: Check out code from GitHub
203-
uses: actions/[email protected]
204-
- name: Set up Python ${{ matrix.python-version }}
205-
id: python
206-
uses: actions/[email protected]
207-
with:
208-
python-version: ${{ matrix.python-version }}
209-
check-latest: true
190+
- *checkout
191+
- *setup-python-matrix
210192
- name: Generate partial Python venv restore key
211193
id: generate-python-key
212194
run: >-
213195
echo "key=${{ env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{
214196
hashFiles('pyproject.toml', 'requirements_minimal.txt')
215197
}}" >> $GITHUB_OUTPUT
216-
- name: Restore Python virtual environment
217-
id: cache-venv
218-
uses: actions/[email protected]
219-
with:
220-
path: venv
221-
key: >-
222-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
223-
steps.generate-python-key.outputs.key }}
198+
- *cache-python
224199
- name: Create Python virtual environment
225200
if: steps.cache-venv.outputs.cache-hit != 'true'
226201
run: |
227202
python -m venv venv
228203
. venv/bin/activate
229-
python -m pip install -U pip setuptools wheel
204+
python -m pip install -U pip
230205
pip install -U -r requirements_minimal.txt
231206
pip install -e .
232207
- name: Run pytest
233208
run: |
234209
. venv/bin/activate
235210
pytest --cov
236211
- name: Upload coverage artifact
237-
uses: actions/upload-artifact@v4.6.2
212+
uses: *actions-upload-artifact
238213
with:
239214
name: coverage-pypy-${{ matrix.python-version }}
240215
path: .coverage
@@ -246,14 +221,8 @@ jobs:
246221
timeout-minutes: 10
247222
needs: ["tests-linux", "tests-windows", "tests-pypy"]
248223
steps:
249-
- name: Check out code from GitHub
250-
uses: actions/[email protected]
251-
- name: Set up Python 3.13
252-
id: python
253-
uses: actions/[email protected]
254-
with:
255-
python-version: "3.13"
256-
check-latest: true
224+
- *checkout
225+
- *setup-python-default
257226
- name: Install dependencies
258227
run: pip install -U -r requirements_minimal.txt
259228
- name: Download all coverage artifacts
@@ -262,7 +231,7 @@ jobs:
262231
run: |
263232
coverage combine coverage-linux*/.coverage
264233
coverage xml -o coverage-linux.xml
265-
- uses: codecov/codecov-action@v5
234+
- uses: &actions-codecov codecov/codecov-action@v5
266235
with:
267236
token: ${{ secrets.CODECOV_TOKEN }}
268237
fail_ci_if_error: true
@@ -273,7 +242,7 @@ jobs:
273242
run: |
274243
coverage combine coverage-windows*/.coverage
275244
coverage xml -o coverage-windows.xml
276-
- uses: codecov/codecov-action@v5
245+
- uses: *actions-codecov
277246
with:
278247
token: ${{ secrets.CODECOV_TOKEN }}
279248
fail_ci_if_error: true
@@ -284,7 +253,7 @@ jobs:
284253
run: |
285254
coverage combine coverage-pypy*/.coverage
286255
coverage xml -o coverage-pypy.xml
287-
- uses: codecov/codecov-action@v5
256+
- uses: *actions-codecov
288257
with:
289258
token: ${{ secrets.CODECOV_TOKEN }}
290259
fail_ci_if_error: true

0 commit comments

Comments
 (0)