-
Notifications
You must be signed in to change notification settings - Fork 5
314 lines (285 loc) · 10.1 KB
/
Copy pathci.yml
File metadata and controls
314 lines (285 loc) · 10.1 KB
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: CI
on:
push:
branches: [main]
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
FORCE_COLOR: "3"
UVX_CONSTRAINT: requirements/lock/uvx-tools.txt
UVX_COMMAND: uvx -crequirements/lock/uvx-tools.txt
NOX_COMMAND: uvx -crequirements/lock/uvx-tools.txt nox
EXTRA_PYTHON_VERSIONS: "pypy-3.11"
permissions: {}
jobs:
pre_job:
# continue-on-error: true # Uncomment once integration is finished
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- name: Don't run CI on draft PR
if:
github.event_name == 'pull_request' && github.event.pull_request.draft
== true
run: exit 1
- id: skip_check
uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5.3.1
with:
paths_ignore: '[".cruft.json", ".copier.yml"]'
build-package:
name: Build & verify package
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: hynek/build-and-inspect-python-package@fe0a0fb1925ca263d076ca4f2c13e93a6e92a33e # v2.17.0
id: baipp
- name: Set python version parameters
id: versions
shell: python
env:
python_classifiers:
${{ steps.baipp.outputs.supported_python_classifiers_json_array }}
run: |
import os
import json
from pathlib import Path
default_python_version = Path(".python-version").read_text().strip()
python_versions = json.loads(os.getenv("python_classifiers"))
extra_python_versions = [_.strip() for _ in os.getenv("EXTRA_PYTHON_VERSIONS", "").split(",") if _]
min_python_version = python_versions[0]
max_python_version = python_versions[-1]
minmax_python_versions = [min_python_version, max_python_version, *extra_python_versions]
minmax_default_python_versions = list({*minmax_python_versions, default_python_version})
all_python_versions = list({*python_versions, *extra_python_versions})
print("{default_python_version=:s}")
print("{min_python_version=:s}")
print("{max_python_version=:s}")
print("{minmax_python_versions=}")
print("{minmax_default_python_versions=}")
print("{all_python_version=}")
with open(os.getenv("GITHUB_OUTPUT"), "a") as f:
f.write(f"{default_python_version=:s}\n")
f.write(f"{min_python_version=:s}\n")
f.write(f"{max_python_version=:s}\n")
f.write(f"minmax_python_versions={json.dumps(minmax_python_versions)}\n")
f.write(f"minmax_default_python_versions={json.dumps(minmax_default_python_versions)}\n")
f.write(f"all_python_versions={json.dumps(all_python_versions)}\n")
outputs:
default-python-version:
${{ steps.versions.outputs.default_python_version }}
min-python-version: ${{ steps.versions.outputs.min_python_version }}
max-python-version: ${{ steps.versions.outputs.max_python_version }}
minmax-python-versions:
${{ steps.versions.outputs.minmax_python_versions }}
minmax-default-python-versions:
${{ steps.versions.outputs.minmax_default_python_versions }}
all-python-version: ${{ steps.versions.outputs.all_python_versions }}
lint:
# only run checks not covered by pre-commit.ci
name: Lint package
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
# Not always needed but some hooks use it...
- uses: ./.github/actions/setup-cached-uv-and-python
with:
python-version-file: ".python-version"
cache-dependency-path: uv.lock
- name: Get prek version
shell: bash
run: |
prek_version=$(grep prek "$UVX_CONSTRAINT" | cut -d " " -f1 | sed "s/prek==//")
echo "prek_version: ${prek_version}"
echo "prek_version=${prek_version}" >> "$GITHUB_ENV"
- name: Setup prek
uses: j178/prek-action@53276d8b0d10f8b6672aa85b4588c6921d0370cc # v2.0.1
with:
prek-version: ${{ env.prek_version }}
install-only: true
- name: Run prek
env:
SKIP: "typecheck"
run: >-
prek run --show-diff-on-failure --color=always --all-files
--hook-stage=manual -v
pinact:
name: Pin actions
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Pin actions
uses: suzuki-shunsuke/pinact-action@cf51507d80d4d6522a07348e3d58790290eaf0b6 # v2.0.0
with:
skip_push: "true"
typecheck:
name: Typecheck package
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
# - windows-latest
session:
- typecheck
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: ./.github/actions/setup-cached-uv-and-python
with:
python-version-file: ".python-version"
cache-dependency-path: uv.lock
- name: Get python version
id: python_version
run: |
python_version=$(cat .python-version)
echo "python_version=${python_version}" >> "$GITHUB_OUTPUT"
shell: bash
- name: typecheck
env:
python_version: ${{ steps.python_version.outputs.python_version }}
session: ${{ matrix.session }}
run: $NOX_COMMAND -s "${session}-${python_version}"
shell: bash
test:
name: Test package across pythons
needs:
- pre_job
- build-package
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
python-version:
${{
fromJson(needs.build-package.outputs.minmax-default-python-versions)
}}
session:
- test
include:
- os: windows-latest
python-version:
${{ needs.build-package.outputs.default-python-version }}
session: test
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: Packages
path: dist
- uses: ./.github/actions/setup-cached-uv-and-python
with:
python-version: ${{ matrix.python-version }}
cache-dependency-path: uv.lock
- name: Test with nox
env:
python_version: ${{ matrix.python-version }}
options: "++installpkg dist/*.whl"
session: ${{ matrix.session }}
run: |
# shellcheck disable=SC2086
$NOX_COMMAND -s "${session}-${python_version}" -- $options
shell: bash -euxo pipefail {0}
- name: Upload coverage data
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name:
coverage-data-${{ matrix.os }}-${{ matrix.python-version }}-${{
matrix.session }}
path: .nox/test-*/tmp/.coverage*
include-hidden-files: true
if-no-files-found: ignore
coverage:
name: Combine coverage
needs:
- pre_job
- test
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Download individual coverage reports
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: coverage-data-*
path: .nox
merge-multiple: true
- name: Display structure of downloaded files
run: ls -aR
- uses: ./.github/actions/setup-cached-uv-and-python
with:
python-version-file: ".python-version"
cache-dependency-path: requirements/lock/uvx-tools.txt
- name: Run coverage
run: |
$NOX_COMMAND -s coverage -- ++coverage combine html markdown
cat coverage.md
cat coverage.md >> "$GITHUB_STEP_SUMMARY"
# fail if under 100%
$NOX_COMMAND -s coverage -- ++coverage report ++coverage-options --fail-under=100
shell: bash
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: html-report
path: htmlcov
if: ${{ failure() }}
docs:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
permissions:
contents: write
uses: ./.github/workflows/docs.yml
with:
deploy: false
# Ensure everything required is passing for branch protection.
required-checks-pass:
if: always()
needs:
- pre_job
- lint
- pinact
- typecheck
- test
- coverage
- docs
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
with:
allowed-skips: "lint,pinact,typecheck,test,coverage,docs"
jobs: ${{ toJSON(needs) }}