-
Notifications
You must be signed in to change notification settings - Fork 122
299 lines (246 loc) · 7.47 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
name: CI
on:
push:
branches: [ trunk ]
tags: [ "**" ]
pull_request:
workflow_dispatch:
defaults:
run:
shell: bash
jobs:
build:
name: ${{ matrix.task.name}} - ${{ matrix.os.name }} ${{ matrix.python.name }}
runs-on: ${{ matrix.os.runs-on }}
strategy:
fail-fast: false
matrix:
os:
- name: Linux
runs-on: ubuntu-latest
python:
- name: CPython 3.9
action: 3.9
task:
- name: Build
nox: build
steps:
- uses: actions/checkout@v3
- uses: hynek/build-and-inspect-python-package@54d50a852d960c25f25f7f1874d3d969ecbe4eb0
- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.action }}
- name: Install dependencies
run: python -m pip install --upgrade pip nox
- uses: twisted/python-info-action@v1
- run: nox -e ${{ matrix.task.nox }}
- name: Publish
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
test-linux:
name: ${{ matrix.task.name}} - Linux ${{ matrix.python.name }}
runs-on: ubuntu-latest
needs:
- build
strategy:
fail-fast: false
matrix:
# Keep list in-sync with noxfile/tests & pyproject.toml.
python:
- name: CPython 3.8
action: 3.8
- name: CPython 3.9
action: 3.9
- name: CPython 3.10
action: '3.10'
- name: CPython 3.11
action: '3.11'
- name: CPython 3.12
action: '3.12'
- name: PyPy 3.8
action: pypy3.8
task:
- name: Test
nox: tests
steps:
- uses: actions/checkout@v3
- name: Download package files
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.action }}
allow-prereleases: true
cache: pip
- name: Install dependencies
run: python -m pip install --upgrade pip nox
- uses: twisted/python-info-action@v1
- run: nox --python ${{ matrix.python.action }} -e ${{ matrix.task.nox }} -- --use-wheel dist/*.whl
- name: Upload coverage data
uses: actions/upload-artifact@v3
with:
name: coverage-data
path: .coverage.*
if-no-files-found: ignore
test-windows:
name: ${{ matrix.task.name}} - Windows ${{ matrix.python.name }}
runs-on: windows-latest
needs:
- build
strategy:
fail-fast: false
matrix:
python:
- name: CPython 3.9
action: '3.9'
task:
- name: Test
nox: tests
steps:
- uses: actions/checkout@v3
- name: Download package files
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.action }}
- name: Install dependencies
run: python -m pip install --upgrade pip nox
- uses: twisted/python-info-action@v1
- run: nox --python ${{ matrix.python.action }} -e ${{ matrix.task.nox }} -- --use-wheel dist/*.whl
check:
name: ${{ matrix.task.name}} - ${{ matrix.python.name }}
runs-on: ubuntu-latest
needs:
- build
strategy:
fail-fast: false
matrix:
python:
# Use a recent version to avoid having common disconnects between
# local development setups and CI.
- name: CPython 3.11
python-version: '3.11'
task:
- name: Check Newsfragment
run: |
nox -e check_newsfragment
nox -e draft_newsfragment >> $GITHUB_STEP_SUMMARY
run-if: ${{ github.head_ref != 'pre-commit-ci-update-config' }}
- name: Check mypy
run: nox -e typecheck
run-if: true
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download package files
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.python-version }}
- name: Install dependencies
run: python -m pip install --upgrade pip nox
- uses: twisted/python-info-action@v1
- name: Check
run: |
${{ matrix.task.run }}
if: ${{ matrix.task.run-if }}
pypi-publish:
name: Check tag and publish
# Only trigger this for tag changes.
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
needs:
- build
- test-linux
- test-windows
steps:
- uses: actions/checkout@v3
- name: Download package files
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install pep517
- name: Display structure of files to be pushed
run: ls --recursive dist/
- name: Check matched tag version and branch version - on tag
run: python admin/check_tag_version_match.py "${{ github.ref }}"
- name: Publish to PyPI - on tag
uses: pypa/gh-action-pypi-publish@a56da0b891b3dc519c7ee3284aff1fad93cc8598
coverage:
name: Combine & check coverage.
needs: test-linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
# Use latest Python, so it understands all syntax.
python-version: 3.11
- run: python -Im pip install --upgrade coverage[toml]
- uses: actions/download-artifact@v3
with:
name: coverage-data
- name: Combine coverage & fail if it's <100%.
run: |
python -Im coverage combine
python -Im coverage html --skip-covered --skip-empty
# Report and write to summary.
python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
# Report again and fail if under 100%.
python -Im coverage report --fail-under=100
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v3
with:
name: html-report
path: htmlcov
if: ${{ failure() }}
# This is a meta-job to simplify PR CI enforcement configuration in GitHub.
# Inside the GitHub config UI you only configure this job as required.
# All the extra requirements are defined "as code" as part of the `needs`
# list for this job.
all:
name: All success
runs-on: ubuntu-latest
# The always() part is very important.
# If not set, the job will be skipped on failing dependencies.
if: always()
needs:
# This is the list of CI job that we are interested to be green before
# a merge.
# pypi-publish is skipped since this is only executed for a tag.
- build
- test-linux
- test-windows
- coverage
- check
steps:
- name: Require all successes
uses: re-actors/alls-green@3a2de129f0713010a71314c74e33c0e3ef90e696
with:
jobs: ${{ toJSON(needs) }}