-
-
Notifications
You must be signed in to change notification settings - Fork 340
376 lines (355 loc) · 14.2 KB
/
test-and-lint-code.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
## This workflow runs all tests, audits, and linters for Mathesar's source code.
## It's set up to run for every pull request change, as well as when a pull
## request is added to the merge queue. This, combined with our branch
## protections requiring pull requests and a merge queue for `develop` and
## `master` ensures that no code is merged into those branches without
## appropriate tests having run.
name: Test and Lint Code
on: [pull_request, merge_group]
jobs:
################################################################################
## FILE CHANGE CHECKERS ##
## ##
## These jobs check which files have changed so that we can call appropriate ##
## testing, auditing, and linting jobs. Jobs in this section should check for ##
## file changes that would indicate whether we need to run some particular ##
## test suite, then they should output 'true' if such file changes are found. ##
## ##
################################################################################
python_tests_required:
name: Check for file changes requiring python tests
runs-on: ubuntu-latest
outputs:
tests_should_run: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v41
with:
files: |
*.py
mathesar/**
db/**
python_lint_required:
name: Check for file changes requiring python linter
runs-on: ubuntu-latest
outputs:
lint_should_run: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v41
with:
files: '**.py'
sql_tests_required:
name: Check for file changes requiring SQL tests
runs-on: ubuntu-latest
outputs:
tests_should_run: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: echo
run: echo "${{needs.all_tests_required.outputs.tests_should_run}}"
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v41
with:
files: '**.sql'
front_end_checks_required:
name: Check for file changes requiring front end checks
runs-on: ubuntu-latest
outputs:
checks_should_run: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v41
with:
files: 'mathesar_ui/**'
all_be_tests_required:
name: Check for file changes requiring all backend tests
runs-on: ubuntu-latest
outputs:
tests_should_run: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v41
with:
files: |
**.yml
**.sh
Dockerfile*
################################################################################
## BACK END TEST/LINT RUNNERS ##
## ##
## These jobs run tests and linters. Each job in this section should be ##
## dependent on one of the FILE CHANGE CHECKERS above, and should only run if ##
## appropriate files have changed. You can see this by using a `needs:` block ##
## to make the job dependent on the relevant file checker, and an `if:` block ##
## to ensure that the file checker returned 'true' before running the actual ##
## job. Job IDs in this section must be namespaced (so `python_tests` ##
## instead of just `tests`). ##
## ##
################################################################################
python_tests:
name: Run Python tests
runs-on: ubuntu-latest
needs: [python_tests_required, all_be_tests_required]
if: needs.python_tests_required.outputs.tests_should_run == 'true' ||
needs.all_be_tests_required.outputs.tests_should_run
strategy:
matrix:
py-version: [3.9-bookworm, 3.10-bookworm, 3.11-bookworm, 3.12-bookworm, 3.13-bookworm]
pg-version: [13, 14, 15, 16, 17]
steps:
- uses: actions/checkout@v4
- name: Copy env file
run: cp .env.example .env
# The code is checked out under uid 1001 - reset this to 1000 for the
# container to run tests successfully
- name: Fix permissions
run: sudo chown -R 1000:1000 .
- name: Build the stack
run: docker compose -f docker-compose.dev.yml up --build -d test-service
env:
PYTHON_VERSION: ${{ matrix.py-version }}
PG_VERSION: ${{ matrix.pg-version }}
- name: Run tests with pytest
run: docker exec mathesar_service_test ./run_pytest.sh
sql_tests:
name: Run SQL tests
runs-on: ubuntu-latest
needs: [sql_tests_required, all_be_tests_required]
if: needs.sql_tests_required.outputs.tests_should_run == 'true' ||
needs.all_be_tests_required.outputs.tests_should_run
strategy:
matrix:
pg-version: [13, 14, 15, 16, 17]
steps:
- uses: actions/checkout@v4
- name: Copy env file
run: cp .env.example .env
# The code is checked out under uid 1001 - reset this to 1000 for the
# container to run tests successfully
- name: Fix permissions
run: sudo chown -R 1000:1000 .
- name: Build the test DB
run: docker compose -f docker-compose.dev.yml up --build -d dev-db
env:
PG_VERSION: ${{ matrix.pg-version }}
- name: Run tests with pg_prove
run: docker exec mathesar_dev_db /bin/bash /sql/run_tests.sh
api_tests:
name: Run API scenario tests
runs-on: ubuntu-latest
needs: [python_tests_required, all_be_tests_required]
if: needs.python_tests_required.outputs.tests_should_run == 'true' ||
needs.all_be_tests_required.outputs.tests_should_run
strategy:
matrix:
py-version: [3.9-bookworm, 3.10-bookworm, 3.11-bookworm, 3.12-bookworm, 3.13-bookworm]
pg-version: [13, 14, 15, 16, 17]
steps:
- uses: actions/checkout@v4
- name: Copy env file
run: cp .env.example .env
# The code is checked out under uid 1001 - reset this to 1000 for the
# container to run tests successfully
- name: Fix permissions
run: sudo chown -R 1000:1000 .
- name: Run tests
run: sh run_api_tests.sh
env:
PYTHON_VERSION: ${{ matrix.py-version }}
PG_VERSION: ${{ matrix.pg-version }}
python_lint:
name: Run Python linter
runs-on: ubuntu-latest
needs: [python_lint_required, all_be_tests_required]
if: needs.python_lint_required.outputs.lint_should_run == 'true' ||
needs.all_be_tests_required.outputs.tests_should_run
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Run flake8
uses: julianwachholz/flake8-action@main
with:
checkName: "flake8"
path: "."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
vulture:
name: Find unused code
runs-on: ubuntu-latest
needs: [python_lint_required, all_be_tests_required]
if: needs.python_lint_required.outputs.lint_should_run == 'true' ||
needs.all_be_tests_required.outputs.tests_should_run
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Install Vulture
run: pip3 install vulture
- name: Run Vulture
run: vulture .
################################################################################
## FRONT END CHECK RUNNERS ##
## ##
## These jobs run front end checks. Each job in this section should be ##
## dependent on one of the FILE CHANGE CHECKERS above (currently only ##
## front_end_checks_required), and should only run if appropriate files have ##
## changed. You can see this by using a `needs:` block to make the job ##
## dependent on the relevant file checker, and an `if:` block to ensure that ##
## the file checker returned 'true' before running the actual job. `lint` and ##
## `tests` Job IDs in this section must be namespaced (`front_end_tests` ##
## rather than `tests`). ##
## ##
################################################################################
front_end_format:
name: Check front end code format
runs-on: ubuntu-latest
needs: front_end_checks_required
if: needs.front_end_checks_required.outputs.checks_should_run == 'true'
defaults:
run:
working-directory: ./mathesar_ui
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- id: npm-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v3
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- run: npm ci --no-audit --prefer-offline
- run: npm run check-format
front_end_lint:
name: Run front end linter
runs-on: ubuntu-latest
needs: front_end_checks_required
if: needs.front_end_checks_required.outputs.checks_should_run == 'true'
defaults:
run:
working-directory: ./mathesar_ui
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- id: npm-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v3
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- run: npm ci --no-audit --prefer-offline
- run: npm run lint
front_end_typecheck:
name: Check front end types
runs-on: ubuntu-latest
needs: front_end_checks_required
if: needs.front_end_checks_required.outputs.checks_should_run == 'true'
defaults:
run:
working-directory: ./mathesar_ui
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- id: npm-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v3
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- run: npm ci --no-audit --prefer-offline
- run: npm run typecheck
front_end_audit:
name: Audit front end code
runs-on: ubuntu-latest
needs: front_end_checks_required
if: needs.front_end_checks_required.outputs.checks_should_run == 'true'
defaults:
run:
working-directory: ./mathesar_ui
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- id: npm-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v3
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- run: npm ci
- uses: oke-py/npm-audit-action@v1.8.2
with:
audit_level: moderate
github_token: ${{ secrets.GITHUB_TOKEN }}
create_pr_comments: false
dedupe_issues: true
working_directory: './mathesar_ui'
issue_labels: 'restricted: maintainers,type: bug,work: frontend,needs: triage'
production_flag: true
continue-on-error: true
front_end_tests:
name: Run front end tests
runs-on: ubuntu-latest
needs: front_end_checks_required
if: needs.front_end_checks_required.outputs.checks_should_run == 'true'
defaults:
run:
working-directory: ./mathesar_ui
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- id: npm-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v3
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- run: npm ci --no-audit --prefer-offline
- run: npm test
################################################################################
## REQUIRED TEST/LINT COLLECTORS ##
## Jobs in this section collect outputs from matrix-strategy testing jobs, ##
## since these are otherwise impossible to capture for branch protection ##
## purposes. At the moment, they only need to have each required check as a ##
## dependency. Required checks should skip themselves if no relevant files ##
## have changed. ##
## ##
################################################################################
matrix_tests:
runs-on: ubuntu-latest
needs: [python_tests, sql_tests]
steps:
- name: Report success
run: echo "All tests succeeded or skipped!"