Skip to content

Commit dc3a403

Browse files
committed
Use yaml anchors in ci workflow
1 parent 85ccc98 commit dc3a403

File tree

1 file changed

+30
-62
lines changed

1 file changed

+30
-62
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ env:
1717
jobs:
1818
prepare-base:
1919
name: Prepare base dependencies
20-
runs-on: ubuntu-latest
20+
runs-on: &runs-on-ubuntu ubuntu-latest
2121
outputs:
2222
python-key: ${{ steps.generate-python-key.outputs.key }}
2323
pre-commit-key: ${{ steps.generate-pre-commit-key.outputs.key }}
2424
steps:
25-
- name: Check out code from GitHub
25+
- &checkout
26+
name: Check out code from GitHub
2627
uses: actions/[email protected]
27-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
28+
- &setup-python-default
29+
name: Set up Python ${{ env.DEFAULT_PYTHON }}
2830
id: python
29-
uses: actions/[email protected]
31+
uses: &actions-setup-python actions/[email protected]
3032
with:
3133
python-version: ${{ env.DEFAULT_PYTHON }}
3234
check-latest: true
@@ -38,7 +40,7 @@ jobs:
3840
'requirements_test_pre_commit.txt') }}" >> $GITHUB_OUTPUT
3941
- name: Restore Python virtual environment
4042
id: cache-venv
41-
uses: actions/[email protected]
43+
uses: &actions-cache actions/[email protected]
4244
with:
4345
path: venv
4446
key: >-
@@ -60,7 +62,7 @@ jobs:
6062
hashFiles('.pre-commit-config.yaml') }}" >> $GITHUB_OUTPUT
6163
- name: Restore pre-commit environment
6264
id: cache-precommit
63-
uses: actions/cache@v4.2.4
65+
uses: *actions-cache
6466
with:
6567
path: ${{ env.PRE_COMMIT_CACHE }}
6668
key: >-
@@ -86,20 +88,15 @@ jobs:
8688

8789
formatting:
8890
name: Run pre-commit checks
89-
runs-on: ubuntu-latest
90-
needs: prepare-base
91+
runs-on: *runs-on-ubuntu
92+
needs: &needs-base [prepare-base]
9193
steps:
92-
- name: Check out code from GitHub
93-
uses: actions/[email protected]
94-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
95-
id: python
96-
uses: actions/[email protected]
97-
with:
98-
python-version: ${{ env.DEFAULT_PYTHON }}
99-
check-latest: true
100-
- name: Restore Python virtual environment
94+
- *checkout
95+
- *setup-python-default
96+
- &cache-restore-python-base
97+
name: Restore Python virtual environment
10198
id: cache-venv
102-
uses: actions/cache/[email protected]
99+
uses: &actions-cache-restore actions/cache/[email protected]
103100
with:
104101
fail-on-cache-miss: true
105102
path: venv
@@ -108,7 +105,7 @@ jobs:
108105
needs.prepare-base.outputs.python-key }}
109106
- name: Restore pre-commit environment
110107
id: cache-precommit
111-
uses: actions/cache/restore@v4.2.4
108+
uses: *actions-cache-restore
112109
with:
113110
fail-on-cache-miss: true
114111
path: ${{ env.PRE_COMMIT_CACHE }}
@@ -122,53 +119,25 @@ jobs:
122119
123120
pylint:
124121
name: Check pylint
125-
runs-on: ubuntu-latest
126-
needs: prepare-base
122+
runs-on: *runs-on-ubuntu
123+
needs: *needs-base
127124
steps:
128-
- name: Check out code from GitHub
129-
uses: actions/[email protected]
130-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
131-
id: python
132-
uses: actions/[email protected]
133-
with:
134-
python-version: ${{ env.DEFAULT_PYTHON }}
135-
check-latest: true
136-
- name: Restore Python virtual environment
137-
id: cache-venv
138-
uses: actions/cache/[email protected]
139-
with:
140-
fail-on-cache-miss: true
141-
path: venv
142-
key: ${{ runner.os }}-${{ runner.arch }}-${{
143-
steps.python.outputs.python-version }}-${{
144-
needs.prepare-base.outputs.python-key }}
125+
- *checkout
126+
- *setup-python-default
127+
- *cache-restore-python-base
145128
- name: Run pylint
146129
run: |
147130
. venv/bin/activate
148131
pylint ${{ env.LIB_FOLDER }} tests
149132
150133
mypy:
151134
name: Check mypy
152-
runs-on: ubuntu-latest
153-
needs: prepare-base
135+
runs-on: *runs-on-ubuntu
136+
needs: *needs-base
154137
steps:
155-
- name: Check out code from GitHub
156-
uses: actions/[email protected]
157-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
158-
id: python
159-
uses: actions/[email protected]
160-
with:
161-
python-version: ${{ env.DEFAULT_PYTHON }}
162-
check-latest: true
163-
- name: Restore Python virtual environment
164-
id: cache-venv
165-
uses: actions/cache/[email protected]
166-
with:
167-
fail-on-cache-miss: true
168-
path: venv
169-
key: ${{ runner.os }}-${{ runner.arch }}-${{
170-
steps.python.outputs.python-version }}-${{
171-
needs.prepare-base.outputs.python-key }}
138+
- *checkout
139+
- *setup-python-default
140+
- *cache-restore-python-base
172141
- name: Run mypy
173142
run: |
174143
. venv/bin/activate
@@ -177,18 +146,17 @@ jobs:
177146
178147
pytest-linux:
179148
name: Run tests Python ${{ matrix.python-version }} (Linux)
180-
runs-on: ubuntu-latest
149+
runs-on: *runs-on-ubuntu
181150
strategy:
182151
matrix:
183152
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
184153
outputs:
185154
python-key: ${{ steps.generate-python-key.outputs.key }}
186155
steps:
187-
- name: Check out code from GitHub
188-
uses: actions/[email protected]
156+
- *checkout
189157
- name: Set up Python ${{ matrix.python-version }}
190158
id: python
191-
uses: actions/setup-python@v6.0.0
159+
uses: *actions-setup-python
192160
with:
193161
python-version: ${{ matrix.python-version }}
194162
allow-prereleases: true
@@ -201,7 +169,7 @@ jobs:
201169
'requirements_test_pre_commit.txt') }}" >> $GITHUB_OUTPUT
202170
- name: Restore Python virtual environment
203171
id: cache-venv
204-
uses: actions/cache@v4.2.4
172+
uses: *actions-cache
205173
with:
206174
path: venv
207175
key: >-

0 commit comments

Comments
 (0)