-
-
Notifications
You must be signed in to change notification settings - Fork 251
278 lines (263 loc) · 9.62 KB
/
lint-and-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
name: Linting & tests
on:
push:
branches: [main]
tags: ["*"]
pull_request:
workflow_dispatch:
# Cancel previous runs within same workflow and if within a PR (all branch runs complete)
# (head_ref [branch name] is unique to and only for PRs, otherwise use always-unique run_id)
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read
env:
LINTING_PYTHON_VERSION: 3.8
jobs:
mypy:
runs-on: ubuntu-latest
name: Lint - Type consistency (mypy)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Install with type-checking tools, stubs & minimal test libraries
run: pip install .[typing,testing_minimal]
- name: Run mypy
run: ./tools/run-mypy
ruff:
runs-on: ubuntu-latest
name: Lint - PEP8 & more (ruff)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Install with linting tools
run: pip install .[linting]
- name: Run ruff
run: ruff zulipterminal/ tests/ setup.py `tools/python_tools.py`
isort:
runs-on: ubuntu-latest
name: Lint - Import order (isort)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Install with linting tools & minimal test libraries
# NOTE: Install pytest so that isort recognizes it as a known library
run: pip install .[linting,minimal_testing]
- name: Run isort
run: ./tools/run-isort-check
black:
runs-on: ubuntu-latest
name: Lint - Code format (black)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Install with linting tools
run: pip install .[linting]
- name: Check code & tests meet black standards
run: black --check zulipterminal/ tests/ setup.py `tools/python_tools.py`
spellcheck:
runs-on: ubuntu-latest
name: Lint - Spellcheck (codespell, typos)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Install with linting tools
run: pip install .[linting]
- name: Check spelling
run: ./tools/run-spellcheck
hotkeys:
runs-on: ubuntu-latest
name: Lint - Hotkeys & docs sync (lint-hotkeys)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Minimal install
run: pip install .
- name: Run lint-hotkeys
run: ./tools/lint-hotkeys
docstrings:
runs-on: ubuntu-latest
name: Lint - Docstrings & docs sync (lint-docstring)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Minimal install
run: pip install .
- name: Run lint-docstring
run: ./tools/lint-docstring
gitlint:
runs-on: ubuntu-latest
name: Lint - Commit text format (gitlint)
steps:
- name: 'PR commits +1'
if: github.event_name == 'pull_request'
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
- name: 'Checkout PR branch and all PR commits'
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ env.PR_FETCH_DEPTH }}
- uses: actions/setup-python@v5
if: github.event_name == 'pull_request'
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Install with gitlint
if: github.event_name == 'pull_request'
run: pip install .[gitlint]
- name: Run gitlint
if: github.event_name == 'pull_request'
run:
git fetch https://github.com/zulip/zulip-terminal main;
gitlint --commits FETCH_HEAD..${{ github.event.pull_request.head.sha }}
base_pytest:
runs-on: ubuntu-latest
name: Install & test - CPython 3.7 (ubuntu), codecov
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Python version
uses: actions/setup-python@v5
with:
python-version: 3.7
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Output Python version
run: python --version
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Ensure regular package installs from checkout
run: pip install .
- name: Install test dependencies
run: pip install .[testing]
- name: Run tests with pytest
run: pytest --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
isolated-commits:
runs-on: ubuntu-latest
name: Ensure isolated PR commits
needs:
- mypy
- ruff
- isort
- black
- spellcheck
- hotkeys
- docstrings
- base_pytest
- gitlint
steps:
- uses: actions/checkout@v4
if: github.event_name == 'pull_request'
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: actions/setup-python@v5
if: github.event_name == 'pull_request'
with:
python-version: ${{ env.LINTING_PYTHON_VERSION }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Run check-branch
if: github.event_name == 'pull_request'
# Note that we install at each step since dependencies may change
run:
git fetch https://github.com/zulip/zulip-terminal main;
CHECK="pip install .[linting,testing,typing] && ./tools/lint-all && pytest" ./tools/check-branch FETCH_HEAD
pytest-on-other-platforms:
needs: isolated-commits
strategy:
# Not failing fast allows all matrix jobs to try & finish even if one fails early
fail-fast: false
matrix:
env:
- {PYTHON: 3.8, OS: ubuntu-latest, NAME: "CPython 3.8 (ubuntu)", EXPECT: "Linux"}
- {PYTHON: 3.9, OS: ubuntu-latest, NAME: "CPython 3.9 (ubuntu)", EXPECT: "Linux"}
- {PYTHON: "3.10", OS: ubuntu-latest, NAME: "CPython 3.10 (ubuntu)", EXPECT: "Linux"}
- {PYTHON: "3.11", OS: ubuntu-latest, NAME: "CPython 3.11 (ubuntu)", EXPECT: "Linux"}
- {PYTHON: 'pypy-3.7', OS: ubuntu-latest, NAME: "PyPy 3.7 (ubuntu)", EXPECT: "Linux"}
- {PYTHON: 'pypy-3.8', OS: ubuntu-latest, NAME: "PyPy 3.8 (ubuntu)", EXPECT: "Linux"}
- {PYTHON: 'pypy-3.9', OS: ubuntu-latest, NAME: "PyPy 3.9 (ubuntu)", EXPECT: "Linux"}
- {PYTHON: 'pypy-3.10', OS: ubuntu-latest, NAME: "PyPy 3.10 (ubuntu)", EXPECT: "Linux"}
- {PYTHON: '3.11', OS: macos-latest, NAME: "CPython 3.11 (macos)", EXPECT: "MacOS"}
env:
EXPECT: ${{ matrix.env.EXPECT }}
PYTHON: ${{ matrix.env.PYTHON }}
runs-on: ${{ matrix.env.OS }}
name: Install & test - ${{ matrix.env.NAME}}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Python version ${{ matrix.env.PYTHON }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.env.PYTHON }}
cache: 'pip'
cache-dependency-path: 'setup.py'
- name: Output Python version
run: python --version
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Ensure libxml-related libraries are installed (some pypy versions don't have wheels)
if: startsWith(matrix.env.PYTHON, 'pypy-')
run: sudo apt install libxml2-dev libxslt1-dev
- name: Ensure regular package installs from checkout
run: pip install .
- name: Check we detect the python environment correctly
run: python -c "from zulipterminal.platform_code import detected_python_short; import os; e, d = os.environ['PYTHON'], detected_python_short(); assert d == e, f'{d} != {e}'"
- name: Check we detect the platform correctly
run: python -c "from zulipterminal.platform_code import detected_platform; import os; e, d = os.environ['EXPECT'], detected_platform(); assert d == e, f'{d} != {e}'"
- name: Install test dependencies
run: pip install .[testing]
- name: Run tests with pytest
run: pytest --cov-report=