forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
346 lines (327 loc) · 11.1 KB
/
ci-tests.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
#############################
## GitHub Actions CI Tests ##
#############################
#
# This can be kicked off manually in the Actions tab of GitHub
# It will also run nightly at 2pm
# It will run on any pull request, except non-code changes
# (images, markdown files, )
#
name: CI
on:
workflow_dispatch:
schedule:
# 2am each night
- cron: '00 2 * * *'
# Don't use pull_request_target here. See:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
pull_request:
push:
branches:
- main
merge_group:
# Merge Queue checks requested. This feature is still in beta
# from Github and so may need updating later.
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#merge_group
types: [checks_requested]
jobs:
linting:
runs-on: ubuntu-latest
strategy:
matrix:
jobs: [ 'linting', 'doclinting', 'docbuild', 'yamllint', 'mypy', 'doctests' ]
name: ${{ matrix.jobs }} tests
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: pip install tox
- name: Run the tests
run: tox -e ${{ matrix.jobs }}
# Test with coverage tracking on most recent python (py12).
python-version-tests:
name: Python Tests
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
include:
# Default to test without coverage tracking on older python versions.
# This saves time, as testing without coverage tracking is faster.
- coverage: false
# Override coverage to be true for most recent python version.
- python-version: "3.12"
coverage: true
permissions:
contents: read
pull-requests: write
uses: ./.github/workflows/ci-test-python.yml
with:
python-version: ${{ matrix.python-version }}
coverage: ${{ matrix.coverage }}
secrets:
gh_token: ${{ secrets.github_token }}
dbt-tests:
name: dbt Plugin Tests
strategy:
matrix:
dbt-version: [ dbt110, dbt120, dbt130, dbt140, dbt150, dbt160, dbt170, dbt180 ]
include:
# Default to python 3.11 for dbt tests. dbt doesn't support py 3.12 yet.
- python-version: "3.11"
# For the two oldest dbt versions, override to python 3.9.
- dbt-version: dbt110
python-version: "3.9"
- dbt-version: dbt120
python-version: "3.9"
# For dbt 1.3 override to python 3.10
- dbt-version: dbt130
python-version: "3.10"
permissions:
contents: read
pull-requests: write
uses: ./.github/workflows/ci-test-dbt.yml
with:
python-version: ${{ matrix.python-version }}
dbt-version: ${{ matrix.dbt-version }}
coverage: true
secrets:
gh_token: ${{ secrets.github_token }}
dialect-tests:
name: Dialect ${{ matrix.marks }}
strategy:
matrix:
include:
# This runs the bulk of the dialect _parsing_ tests.
#
# It's run as a separate job as takes longer than the CI jobs and allows
# them to be rerun separately if GitHub Actions or Coverage is experiencing
# issues.
- marks: "parse_suite"
# We test coverage here for some parsing routines.
coverage: true
# This lints all our dialect fixtures to check rules can handle a variety
# of SQL and don't error out badly.
#
# It's run as a separate job as takes longer than the CI jobs and allows
# them to be rerun separately if GitHub Actions or Coverage is experiencing
# issues.
- marks: "fix_suite"
coverage: false
# This lints all our rules fixtures to check rules.
#
# It's run as a separate job as takes longer than the CI jobs and allows
# them to be rerun separately if GitHub Actions or Coverage is experiencing
# issues.
- marks: "rules_suite"
coverage: true
permissions:
contents: read
pull-requests: write
uses: ./.github/workflows/ci-test-python.yml
with:
python-version: "3.12"
marks: ${{ matrix.marks }}
coverage: ${{ matrix.coverage }}
secrets:
gh_token: ${{ secrets.github_token }}
ymlchecks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install -r requirements_dev.txt
pip install -e .
- name: Generate the YAML files
run: |
python test/generate_parse_fixture_yml.py
- name: Test the generated YAML files
run: |
if [ -n "$(git status --porcelain)" ]; then
git diff
echo "Generated YAML files do not match branch."
echo "Please run the following command to generate these:"
echo " python test/generate_parse_fixture_yml.py"
exit 1
fi
examples:
runs-on: ubuntu-latest
name: example tests
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install -e .
pip install tqdm
- name: Test the example files
run: |
for file in examples/*
do
echo "Running $file"
python "$file"
done
python-windows-tests:
runs-on: windows-latest
name: Python 3.12 Windows tests
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: List Env
shell: bash
run: |
env | sort
- name: Install dependencies
shell: bash
run: pip install tox
- name: Run the tests
shell: bash
# Set python temp dir in working dir as on GitHub Actions Windows
# machine often has system temp dir (which tox uses) on C drive and
# working dir on D drive which causes problems.
run: |
mkdir temp_pytest
python -m tox -e winpy -- --cov=sqlfluff -n 2 test -m "not integration"
- name: Upload coverage data (github)
uses: actions/upload-artifact@v4
with:
name: coverage-data-winpy3.12
path: ".coverage.*"
if-no-files-found: ignore
python-windows-dbt-tests:
runs-on: windows-latest
name: dbt Plugin Python 3.11 Windows tests
steps:
- name: Start PostgreSQL on Windows
run: |
$pgService = Get-Service -Name postgresql*
Set-Service -InputObject $pgService -Status running -StartupType automatic
Start-Process -FilePath "$env:PGBIN\pg_isready" -Wait -PassThru
- name: Set postgres user password
run: |
& $env:PGBIN\psql --command="ALTER USER postgres PASSWORD 'password';" --command="\du"
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
# dbt doesn't support py 3.12 yet.
python-version: "3.11"
- name: Install dependencies
shell: bash
run: pip install tox
- name: Run the tests
shell: bash
# Do not set explicitly temp dir for dbt as causes problems
# None of these test need temp dir set
run: |
python -m tox -e dbt150-winpy -- plugins/sqlfluff-templater-dbt
pip-test-pull-request:
# Test that using pip install works as we've missed
# some dependencies in the past - see #1842
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
name: pip install tests
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: actions/checkout@v4
- name: Install dependencies
run: |
pip install .
- name: Run the version test
run: |
sqlfluff --version
- name: Run a simple select parse test via stdin
run: |
echo "select 1" | sqlfluff parse --dialect=ansi -
- name: Run a simple select lint test via stdin
run: |
echo "select 1" | sqlfluff lint --dialect=ansi -
- name: Run a simple select parse test via file
run: |
sqlfluff parse --dialect=ansi <(echo "select 1")
- name: Run a simple select lint test via file
run: |
sqlfluff lint --dialect=ansi <(echo "select 1")
coveralls_finish:
name: Finalise coveralls.
needs: [python-version-tests, dbt-tests, python-windows-tests, dialect-tests]
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
coverage_check:
name: Combine & check 100% coverage.
runs-on: ubuntu-latest
needs: [python-version-tests, dbt-tests, python-windows-tests, dialect-tests]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: python -m pip install --upgrade coverage[toml]
- name: Download coverage data.
uses: actions/download-artifact@v4
with:
pattern: coverage-data-*
merge-multiple: true
- name: Combine coverage & fail if it's <100%.
id: report_coverage
# NOTE: Setting the pipefail option here means that even when
# piping the output to `tee`, we still get the exit code of the
# `coverage report` command.
run: |
set -o pipefail
python -m coverage combine
python -m coverage html --skip-covered --skip-empty
python -m coverage report --fail-under=100 --skip-covered --skip-empty -m | tee coverage-report.txt
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
if: failure() && github.event_name == 'pull_request'
- name: Stash PR Number.
if: always() && github.event_name == 'pull_request'
# NOTE: We do this so we know what PR to comment on when we pick up the report.
run: |
echo ${{ github.event.number }} > ./pr-number.txt
echo ${{ steps.report_coverage.outcome }} > ./outcome.txt
- name: Upload TXT report always (to add as comment to PR).
# NOTE: We don't actually comment on the PR from here, we'll do that in
# a more secure way by triggering a more secure workflow.
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
uses: actions/upload-artifact@v4
with:
name: txt-report
path: |
coverage-report.txt
pr-number.txt
outcome.txt
if: always() && github.event_name == 'pull_request'