Skip to content

Commit d94ba23

Browse files
authored
Use yaml anchors for workflows (#10574)
Github added support for YAML anchors in workflow files. They don't support key-merge / overrides but it's at least a start. - https://github.blog/changelog/2025-09-18-actions-yaml-anchors-and-non-public-workflow-templates/ - https://docs.github.com/en/actions/reference/workflows-and-actions/reusing-workflow-configurations#yaml-anchors-and-aliases - Good overview over the yaml anchors syntax: https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/
1 parent e694467 commit d94ba23

File tree

6 files changed

+53
-112
lines changed

6 files changed

+53
-112
lines changed

.github/workflows/changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
run: |
5353
python -m venv venv
5454
. venv/bin/activate
55-
python -m pip install --upgrade pip setuptools wheel
55+
python -m pip install --upgrade pip
5656
pip install --upgrade --requirement requirements_test.txt --requirement doc/requirements.txt
5757
- name: Emit warning if news fragment is missing
5858
env:

.github/workflows/checks.yaml

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ jobs:
3333
python-key: ${{ steps.generate-python-key.outputs.key }}
3434
pre-commit-key: ${{ steps.generate-pre-commit-key.outputs.key }}
3535
steps:
36-
- name: Check out code from GitHub
36+
- &checkout
37+
name: Check out code from GitHub
3738
uses: actions/[email protected]
38-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
39+
- &setup-python
40+
name: Set up Python ${{ env.DEFAULT_PYTHON }}
3941
id: python
4042
uses: actions/[email protected]
4143
with:
@@ -61,7 +63,7 @@ jobs:
6163
run: |
6264
python -m venv venv
6365
. venv/bin/activate
64-
python -m pip install --upgrade pip setuptools wheel
66+
python -m pip install --upgrade pip
6567
pip install --upgrade --requirement requirements_test.txt --requirement doc/requirements.txt
6668
pip install pre-commit
6769
- name: Generate pre-commit restore key
@@ -86,17 +88,12 @@ jobs:
8688
name: pylint
8789
runs-on: ubuntu-latest
8890
timeout-minutes: 10
89-
needs: prepare-base
91+
needs: [prepare-base]
9092
steps:
91-
- name: Check out code from GitHub
92-
uses: actions/[email protected]
93-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
94-
id: python
95-
uses: actions/[email protected]
96-
with:
97-
python-version: ${{ env.DEFAULT_PYTHON }}
98-
check-latest: true
99-
- name: Restore Python virtual environment
93+
- *checkout
94+
- *setup-python
95+
- &cache-restore-python
96+
name: Restore Python virtual environment
10097
id: cache-venv
10198
uses: actions/cache/[email protected]
10299
with:
@@ -127,25 +124,11 @@ jobs:
127124
name: spelling tests
128125
runs-on: ubuntu-latest
129126
timeout-minutes: 5
130-
needs: prepare-base
127+
needs: [prepare-base]
131128
steps:
132-
- name: Check out code from GitHub
133-
uses: actions/[email protected]
134-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
135-
id: python
136-
uses: actions/[email protected]
137-
with:
138-
python-version: ${{ env.DEFAULT_PYTHON }}
139-
check-latest: true
140-
- name: Restore Python virtual environment
141-
id: cache-venv
142-
uses: actions/cache/[email protected]
143-
with:
144-
path: venv
145-
fail-on-cache-miss: true
146-
key:
147-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
148-
needs.prepare-base.outputs.python-key }}
129+
- *checkout
130+
- *setup-python
131+
- *cache-restore-python
149132
- name: Run spelling checks
150133
run: |
151134
. venv/bin/activate
@@ -156,25 +139,11 @@ jobs:
156139
name: documentation
157140
runs-on: ubuntu-latest
158141
timeout-minutes: 20
159-
needs: prepare-base
142+
needs: [prepare-base]
160143
steps:
161-
- name: Check out code from GitHub
162-
uses: actions/[email protected]
163-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
164-
id: python
165-
uses: actions/[email protected]
166-
with:
167-
python-version: ${{ env.DEFAULT_PYTHON }}
168-
check-latest: true
169-
- name: Restore Python virtual environment
170-
id: cache-venv
171-
uses: actions/cache/[email protected]
172-
with:
173-
path: venv
174-
fail-on-cache-miss: true
175-
key:
176-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
177-
needs.prepare-base.outputs.python-key }}
144+
- *checkout
145+
- *setup-python
146+
- *cache-restore-python
178147
- name: Run checks on documentation code examples
179148
run: |
180149
. venv/bin/activate

.github/workflows/primer-test.yaml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,20 @@ jobs:
3030
timeout-minutes: 5
3131
strategy:
3232
matrix:
33-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14-dev"]
33+
python-version: &matrix-python-version ["3.10", "3.11", "3.12", "3.13", "3.14"]
3434
outputs:
3535
python-key: ${{ steps.generate-python-key.outputs.key }}
3636
steps:
37-
- name: Check out code from GitHub
37+
- &checkout
38+
name: Check out code from GitHub
3839
uses: actions/[email protected]
39-
- name: Set up Python ${{ matrix.python-version }}
40+
- &setup-python
41+
name: Set up Python ${{ matrix.python-version }}
4042
id: python
4143
uses: actions/[email protected]
4244
with:
4345
python-version: ${{ matrix.python-version }}
46+
allow-prereleases: true
4447
check-latest: true
4548
- name: Generate partial Python venv restore key
4649
id: generate-python-key
@@ -62,7 +65,7 @@ jobs:
6265
run: |
6366
python -m venv venv
6467
. venv/bin/activate
65-
python -m pip install --upgrade pip setuptools wheel
68+
python -m pip install --upgrade pip
6669
pip install --upgrade --requirement requirements_test.txt
6770
6871
pytest-primer-stdlib:
@@ -72,16 +75,10 @@ jobs:
7275
needs: prepare-tests-linux
7376
strategy:
7477
matrix:
75-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14-dev"]
78+
python-version: *matrix-python-version
7679
steps:
77-
- name: Check out code from GitHub
78-
uses: actions/[email protected]
79-
- name: Set up Python ${{ matrix.python-version }}
80-
id: python
81-
uses: actions/[email protected]
82-
with:
83-
python-version: ${{ matrix.python-version }}
84-
check-latest: true
80+
- *checkout
81+
- *setup-python
8582
- name: Restore Python virtual environment
8683
id: cache-venv
8784
uses: actions/cache/[email protected]

.github/workflows/primer_run_main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
run: |
5959
python -m venv venv
6060
. venv/bin/activate
61-
python -m pip install --upgrade pip setuptools wheel
61+
python -m pip install --upgrade pip
6262
pip install --upgrade --requirement requirements_test.txt
6363
# Save cached Python environment (explicit because cancel-in-progress: true)
6464
- name: Save Python virtual environment to cache

.github/workflows/primer_run_pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
run: |
7171
python -m venv venv
7272
. venv/bin/activate
73-
python -m pip install --upgrade pip setuptools wheel
73+
python -m pip install --upgrade pip
7474
pip install --upgrade --requirement requirements_test.txt
7575
# Save cached Python environment (explicit because cancel-in-progress: true)
7676
- name: Save Python virtual environment

.github/workflows/tests.yaml

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
fail-fast: false
3333
matrix:
3434
os: [ubuntu-latest]
35-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
35+
python-version: &matrix-python-version ["3.10", "3.11", "3.12", "3.13", "3.14"]
3636
include:
3737
- os: macos-latest
3838
python-version: "3.10"
@@ -44,9 +44,11 @@ jobs:
4444
outputs:
4545
python-key: ${{ steps.generate-python-key.outputs.key }}
4646
steps:
47-
- name: Check out code from GitHub
47+
- &checkout
48+
name: Check out code from GitHub
4849
uses: actions/[email protected]
49-
- name: Set up Python ${{ matrix.python-version }}
50+
- &setup-python
51+
name: Set up Python ${{ matrix.python-version }}
5052
id: python
5153
uses: actions/[email protected]
5254
with:
@@ -60,7 +62,8 @@ jobs:
6062
hashFiles('pyproject.toml', 'requirements_test.txt',
6163
'requirements_test_min.txt', 'requirements_test_pre_commit.txt') }}" >>
6264
$GITHUB_OUTPUT
63-
- name: Restore Python virtual environment
65+
- &cache-python
66+
name: Restore Python virtual environment
6467
id: cache-venv
6568
uses: actions/[email protected]
6669
with:
@@ -73,7 +76,7 @@ jobs:
7376
run: |
7477
python -m venv venv
7578
. venv/bin/activate
76-
python -m pip install --upgrade pip setuptools wheel
79+
python -m pip install --upgrade pip
7780
pip install --upgrade --requirement requirements_test.txt
7881
- name: Run pytest
7982
run: |
@@ -98,17 +101,17 @@ jobs:
98101
name: process / coverage
99102
runs-on: ubuntu-latest
100103
timeout-minutes: 5
101-
needs: tests
104+
needs: [tests]
102105
steps:
103-
- name: Check out code from GitHub
104-
uses: actions/[email protected]
106+
- *checkout
105107
- name: Set up Python 3.13
106108
id: python
107109
uses: actions/[email protected]
108110
with:
109111
python-version: "3.13"
110112
check-latest: true
111-
- name: Restore Python virtual environment
113+
- &cache-restore-python
114+
name: Restore Python virtual environment
112115
id: cache-venv
113116
uses: actions/cache/[email protected]
114117
with:
@@ -134,29 +137,15 @@ jobs:
134137
name: run benchmark / ${{ matrix.python-version }} / Linux
135138
runs-on: ubuntu-latest
136139
timeout-minutes: 10
137-
needs: tests
140+
needs: [tests]
138141
strategy:
139142
fail-fast: false
140143
matrix:
141144
python-version: ["3.13"]
142145
steps:
143-
- name: Check out code from GitHub
144-
uses: actions/[email protected]
145-
- name: Set up Python ${{ matrix.python-version }}
146-
id: python
147-
uses: actions/[email protected]
148-
with:
149-
python-version: ${{ matrix.python-version }}
150-
check-latest: true
151-
- name: Restore Python virtual environment
152-
id: cache-venv
153-
uses: actions/cache/[email protected]
154-
with:
155-
path: venv
156-
fail-on-cache-miss: true
157-
key:
158-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
159-
needs.tests.outputs.python-key }}
146+
- *checkout
147+
- *setup-python
148+
- *cache-restore-python
160149
- name: Run pytest
161150
run: |
162151
. venv/bin/activate
@@ -185,45 +174,31 @@ jobs:
185174
name: run / ${{ matrix.python-version }} / Windows
186175
runs-on: windows-latest
187176
timeout-minutes: 25
188-
needs: tests
177+
needs: [tests]
189178
strategy:
190179
fail-fast: false
191180
matrix:
192-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
181+
python-version: *matrix-python-version
193182
steps:
194183
- name: Set temp directory
195184
run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
196185
# Workaround to set correct temp directory on Windows
197186
# https://github.com/actions/virtual-environments/issues/712
198-
- name: Check out code from GitHub
199-
uses: actions/[email protected]
200-
- name: Set up Python ${{ matrix.python-version }}
201-
id: python
202-
uses: actions/[email protected]
203-
with:
204-
python-version: ${{ matrix.python-version }}
205-
check-latest: true
206-
allow-prereleases: true
187+
- *checkout
188+
- *setup-python
207189
- name: Generate partial Python venv restore key
208190
id: generate-python-key
209191
run: >-
210192
echo "key=venv-${{ env.CACHE_VERSION }}-${{
211193
hashFiles('pyproject.toml', 'requirements_test_min.txt')
212194
}}" >> $env:GITHUB_OUTPUT
213-
- name: Restore Python virtual environment
214-
id: cache-venv
215-
uses: actions/[email protected]
216-
with:
217-
path: venv
218-
key: >-
219-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
220-
steps.generate-python-key.outputs.key }}
195+
- *cache-python
221196
- name: Create Python virtual environment
222197
if: steps.cache-venv.outputs.cache-hit != 'true'
223198
run: |
224199
python -m venv venv
225200
. venv\\Scripts\\activate
226-
python -m pip install --upgrade pip setuptools wheel
201+
python -m pip install --upgrade pip
227202
pip install --upgrade --requirement requirements_test_min.txt
228203
- name: Run pytest
229204
run: |

0 commit comments

Comments
 (0)