-
Notifications
You must be signed in to change notification settings - Fork 138
300 lines (259 loc) · 9.88 KB
/
lint-test.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
300
# SPDX-License-Identifier: MIT
name: Lint & Test
on: [push, pull_request]
permissions:
read-all
defaults:
run:
shell: bash
jobs:
lint:
# Thanks to black for this rule
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up environment
uses: ./.github/actions/setup-env
with:
python-version: 3.8
nox-setup: "dev tools"
- name: Run pre-commit
id: pre-commit
uses: pre-commit/[email protected]
env:
SKIP: 'flake8'
# Run flake8 and have it format the linting errors in the format of
# the GitHub Workflow command to register error annotations. This
# means that our flake8 output is automatically added as an error
# annotation to both the run result and in the "Files" tab of a
# pull request.
#
# Format used:
# ::error file={filename},line={line},col={col}::{message}
- name: Run flake8
id: flake8
if: always() && (steps.pre-commit.outcome == 'success' || steps.pre-commit.outcome == 'failure')
run: "flake8 \
--format='::error file=%(path)s,line=%(row)d,col=%(col)d::\
[flake8] %(code)s: %(text)s'"
docs:
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
# unlike the other workflows, we are using version 20.04 here as
# readthedocs uses 20.04 for building our docs, and we want to be explicit
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Set up environment
uses: ./.github/actions/setup-env
with:
python-version: 3.8
nox-setup: "docs"
- name: Run sphinx-build
run: nox -s docs -- --keep-going -W -w $GITHUB_STEP_SUMMARY
pyright:
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
continue-on-error: ${{ matrix.experimental }}
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
experimental: [false]
include:
- python-version: '3.11.0-alpha - 3.11'
experimental: true
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Set up environment
id: setup-env
uses: ./.github/actions/setup-env
with:
python-version: ${{ matrix.python-version }}
nox-setup: "*"
- name: Set pyright version
run: |
PYRIGHT_VERSION="$(python -c 'import pyright; print(pyright.__pyright_version__)')"
echo "PYRIGHT_VERSION=$PYRIGHT_VERSION" >> $GITHUB_ENV
- name: Run pyright (Linux)
uses: jakebailey/[email protected]
with:
version: ${{ env.PYRIGHT_VERSION }}
python-version: ${{ steps.setup-env.outputs.python-version }}
python-platform: "Linux"
no-comments: ${{ matrix.python-version != '3.8' }} # only add comments for one version
warnings: true
- name: Run pyright (Windows)
uses: jakebailey/[email protected]
if: ${{ success() || failure() }} # run regardless of previous step's result
with:
version: ${{ env.PYRIGHT_VERSION }}
python-version: ${{ steps.setup-env.outputs.python-version }}
python-platform: "Windows"
no-comments: true # only add comments for one platform (see above)
warnings: true
misc:
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up environment
id: setup
uses: ./.github/actions/setup-env
with:
python-version: 3.8
nox-setup: tools
- name: Run slotscheck
if: (success() || failure()) && steps.setup.outcome == 'success'
run: nox -s slotscheck
- name: Run check-manifest
if: (success() || failure()) && steps.setup.outcome == 'success'
run: nox -s check-manifest
# This only runs if the previous steps were successful, no point in running it otherwise
- name: Build package
run: |
pip install -U build
python -m build
# run the libcst parsers and check for changes
- name: libcst codemod
env:
LIBCST_PARSER_TYPE: "native"
run: |
nox -s codemod -- run-all
if [ -n "$(git status --porcelain disnake/)" ]; then
echo "::error::Please run 'nox -s codemod -- run-all' locally and commit the changes." >&2;
exit 1;
else
exit 0;
fi
pytest:
# Thanks to black for this rule
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
continue-on-error: ${{ matrix.experimental }}
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
os: ["windows-latest", "ubuntu-latest", "macos-latest"]
experimental: [false]
include:
- python-version: '3.11.0-alpha - 3.11'
os: "ubuntu-latest"
experimental: true
- python-version: '3.11.0-alpha - 3.11'
os: "macos-latest"
experimental: true
- python-version: '3.11.0-alpha - 3.11'
os: "windows-latest"
experimental: true
fail-fast: true
runs-on: ${{ matrix.os }}
env:
GITHUB_STEP_SUMMARY_HEADER: "<details><summary>#name#</summary>\n<pre>"
GITHUB_STEP_SUMMARY_FOOTER: "</pre></details>\n"
steps:
- uses: actions/checkout@v3
- name: Set up environment
id: setup-env
uses: ./.github/actions/setup-env
with:
python-version: ${{ matrix.python-version }}
dependencies: nox coveralls==3.3.1 coverage[toml]~=6.3.2
- name: Test package install
run: |
python -m pip install .
- name: Run pytest
id: run_tests
# use non-utc timezone, to test time/date-dependent features properly
env:
TZ: "America/New_York"
run: |
echo "$GITHUB_STEP_SUMMARY_HEADER" | sed "s/#name#/Test Summary/" >> $GITHUB_STEP_SUMMARY
nox --force-python ${{ steps.setup-env.outputs.python-version }} -s test -- --color=no --cov-report= | tee -a $GITHUB_STEP_SUMMARY
echo "$GITHUB_STEP_SUMMARY_FOOTER" >> $GITHUB_STEP_SUMMARY
- name: Print Coverage Output
if: always() && (steps.run_tests.outcome == 'success' || steps.run_tests.outcome == 'failure')
run: |
echo "$GITHUB_STEP_SUMMARY_HEADER" | sed "s/#name#/Coverage Summary/" >> $GITHUB_STEP_SUMMARY
python -m coverage report | tee -a $GITHUB_STEP_SUMMARY
echo "$GITHUB_STEP_SUMMARY_FOOTER" >> $GITHUB_STEP_SUMMARY
# This step will publish the coverage reports to coveralls.io and
# print a "job" link in the output of the GitHub Action
- name: Publish coverage report to coveralls.io
# upload coverage even if a test run failed
# this is a test, and may be removed in the future
if: always() && (steps.run_tests.outcome == 'success' || steps.run_tests.outcome == 'failure')
# important that we don't fail the workflow when coveralls is down
continue-on-error: true
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: coverage-${{ runner.os }}-python-${{ matrix.python-version }}
COVERALLS_PARALLEL: true
COVERALLS_SERVICE_NAME: github
run: python -m coveralls
coveralls-finish:
name: Indicate completion to coveralls.io
runs-on: ubuntu-latest
needs: pytest
# we don't want to fail the workflow when coveralls is down
continue-on-error: true
# as long as the tests were ran, we want to send a finish to coveralls
if: success() || failure()
steps:
- uses: actions/checkout@v3
- name: Set up environment
uses: ./.github/actions/setup-env
with:
python-version: 3.8
cache-dependency-path: |
.github/workflows/lint-test.yml
dependencies: coveralls==3.3.1
- name: Coveralls Finished
continue-on-error: true
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
run: |
python3 -m coveralls --finish
# thanks to aiohttp for this part of the workflow
check: # This job does nothing and is only used for the branch protection
if:
always() &&
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
needs:
- lint
- docs
- pyright
- misc
- pytest
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/[email protected]
with:
jobs: ${{ toJSON(needs) }}