-
Notifications
You must be signed in to change notification settings - Fork 1
251 lines (248 loc) · 7.35 KB
/
build.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
###
# Build and validate the project.
##
on:
pull_request:
branches: [main]
schedule:
# Run continuous integration on the 15th day of each quarter, to see
# if maintenance is necessary (e.g., updating dependencies).
- cron: "15 10 15 */3 *"
workflow_call:
env:
FORCE_COLOR: true
PIP_NO_INPUT: true
PIP_DISABLE_PIP_VERSION_CHECK: true
permissions: {} # Explicitly set permissions on each job.
jobs:
support:
name: Check support policy.
runs-on: ubuntu-latest
steps:
- name: Clone the repo.
uses: actions/checkout@v4
- name: Install Python.
uses: actions/setup-python@v5
with:
python-version-file: .default-python-version
cache: pip
- name: Check compliance with the support policy.
run: |
python -Im pip install --quiet .[ci]
python -Im nox \
--non-interactive \
--session support
lint:
name: Run lint.
runs-on: ubuntu-latest
steps:
- name: Clone the repo.
uses: actions/checkout@v4
- name: Install Python.
uses: actions/setup-python@v5
with:
python-version-file: .default-python-version
cache: pip
- name: Run the linter.
run: |
python -Im pip install --quiet .[ci]
python -Im nox \
--non-interactive \
--session lint
docs:
name: Build and test docs.
runs-on: ubuntu-latest
steps:
- name: Clone the repo.
uses: actions/checkout@v4
with:
# Fetch all history as the job needs the pull request's full
# branch to check that the changelog has been updated.
fetch-depth: 0
- name: Install Python.
uses: actions/setup-python@v5
with:
python-version-file: .default-python-version
cache: pip
- name: Check the changelog has been updated.
if: |
github.event_name == 'pull_request'
&& github.base_ref == 'main'
&& github.head_ref != 'main'
run: |
if git diff \
--name-only \
origin/main HEAD \
| grep \
--quiet \
--fixed-strings \
--line-regexp \
"CHANGELOG.rst";
then
echo "Success! The pull request updates the changelog."
else
echo "Failure! The pull request doesn't update the changelog."
exit 1
fi
- name: Build and test the documentation.
run: |
python -Im pip install --quiet .[ci]
python -Im nox \
--non-interactive \
--session docs
- name: Upload the GitHub Pages artifact.
uses: actions/upload-pages-artifact@v3
with:
name: docs
path: docs/_build/html/
retention-days: 90
test:
name: Run tests.
runs-on: ubuntu-latest
steps:
- name: Clone the repo.
uses: actions/checkout@v4
- name: Install Python.
uses: actions/setup-python@v5
with:
python-version-file: .default-python-version
cache: pip
- name: Run the tests.
run: |
python -Im pip install --quiet .[ci]
python -Im nox \
--non-interactive \
--session test
package:
name: Package the source.
runs-on: ubuntu-latest
steps:
- name: Clone the repo.
uses: actions/checkout@v4
- name: Install Python.
uses: actions/setup-python@v5
with:
python-version-file: .default-python-version
cache: pip
- name: Build the distribution package.
run: |
python -Im pip install --quiet .[ci]
python -Im nox \
--non-interactive \
--session package
- name: List the packages' contents.
run: |
for build in sdist wheel; do
mkdir "dist/${build}/"
if [[ "${build}" == "sdist" ]]; then
tar -x --directory "dist/${build}/" --file dist/*.tar.gz
elif [[ "${build}" == "wheel" ]]; then
unzip -qq -d "dist/${build}/" dist/*.whl
else
echo "Unrecognized build."
exit 1
fi
echo "${build} files:"
find \
"dist/${build}" \
-type f \
-exec echo {} \; \
| cut -d'/' -f3- \
| sort \
| awk '{ print " " $0 } END { print "" }'
rm -rf "dist/${build}/"
done
- name: Upload the package artifact.
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
if-no-files-found: error
compression-level: 0 # packages are already compressed.
matrix:
name: Compute test matrix.
runs-on: ubuntu-latest
outputs:
python-versions: ${{ steps.get-python-versions.outputs.python-versions }}
steps:
- name: Clone the repo.
uses: actions/checkout@v4
- name: Install Python.
uses: actions/setup-python@v5
with:
python-version-file: .default-python-version
cache: pip
- name: Build the test matrix from available nox sessions.
id: get-python-versions
run: |
python -Im pip install --quiet .[ci]
PYTHON_VERSIONS=$( \
python -Im \
nox \
--session testpackage \
--list \
--json \
| jq \
--raw-output \
'.[].python' \
| sort --version-sort \
| uniq \
| jq \
--raw-input \
--slurp \
--compact-output \
'split("\n")[:-1]' \
)
echo "python-versions=${PYTHON_VERSIONS}" | tee -a "${GITHUB_OUTPUT}"
testpackage:
name: Test package with Python ${{ matrix.python-version }}.
needs:
- package
- matrix
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJson(needs.matrix.outputs.python-versions) }}
runs-on: ubuntu-latest
steps:
- name: Clone the repo.
uses: actions/checkout@v4
- name: Install Python.
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Download the package artifact.
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Run tests on the package with Python ${{ matrix.python-version }}.
env:
PYTHON_VERSION: ${{ matrix.python-version }}
# NOTE: Since the package job builds the wheel from the sdist,
# test the wheel as it should cover both.
run: |
python -Im pip install --quiet .[ci]
python -Im nox \
--non-interactive \
--session "testpackage-${PYTHON_VERSION}" \
-- \
dist/*.whl
verify:
name: Verify all checks passed.
if: always()
needs:
- support
- lint
- docs
- test
- package
- matrix
- testpackage
runs-on: ubuntu-latest
steps:
- name: Verify that all checks passed successfully.
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
with:
jobs: ${{ toJSON(needs) }}