-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (81 loc) · 2.93 KB
/
sql-linter.yaml
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
name: SQLFluff
on:
- pull_request
jobs:
lint-models:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: Install Python
uses: "actions/setup-python@v2"
with:
python-version: "3.10"
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: '1.7.1'
- name: Setup a local virtual environment (if no poetry.toml file)
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- name: Install the project dependencies
run: poetry install --no-interaction
- name: Add Poetry virtualenv to PATH
run: |
echo "$(poetry env info --path)/bin" >> $GITHUB_PATH
- name: Install DBT Dependencies
run: "dbt deps"
- name: Get changed files
id: get_file_changes
uses: trilom/file-changes-action@v1.2.4
with:
output: ' '
- name: Display changed files
run: |
echo "Modified files: ${{ steps.get_file_changes.outputs.files_modified }}"
echo "Added files: ${{ steps.get_file_changes.outputs.files_added }}"
- name: Get changed .sql files in /models to lint
id: get_files_to_lint
shell: bash -l {0}
run: |
# Set the command in the $() brackets as an output to use in later steps
echo "::set-output name=lintees::$(
# Issue where grep regular expressions don't work as expected on the
# Github Actions shell, check models/ folder
echo \
$(echo ${{ steps.get_file_changes.outputs.files_modified }} |
tr -s ' ' '\n' |
grep -E '^models.*[.]sql$' |
tr -s '\n' ' ') \
$(echo ${{ steps.get_file_changes.outputs.files_added }} |
tr -s ' ' '\n' |
grep -E '^models.*[.]sql$' |
tr -s '\n' ' ')
)"
- name: Lint each SQL file individually
run: |
# Loop through each changed SQL file and lint them individually
for file in ${{ steps.get_file_changes.outputs.files_modified }} ${{ steps.get_file_changes.outputs.files_added }}; do
if [[ $file == *.sql ]]; then
echo "Linting $file"
sqlfluff lint failure $file || exit_code=$?
fi
done
shell: bash
- name: Fail if any file had a linting error
run: |
if [[ -n "$exit_code" ]]; then
exit $exit_code
fi
- name: Lint dbt models
id: sqlfluff_json
if: steps.get_files_to_lint.outputs.lintees != ''
shell: bash -l {0}
run: sqlfluff lint ./models/ > annotations.json
- name: Annotate
uses: yuzutech/annotations-action@v0.3.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
title: "SQLFluff Lint"
input: "./annotations.json"