-
-
Notifications
You must be signed in to change notification settings - Fork 338
140 lines (131 loc) · 4.28 KB
/
backend-validation.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
# Since we're using both the "require pull request" and "require merge queue"
# requirements for develop and master branches, there's no reason to run tests
# on every push. Instead, we're using the recommended "merge_group" formulation
# that runs status checks and reports them whenever a PR is added to the merge
# queue.
name: Backend tests and linting
on: [pull_request, merge_group]
jobs:
pytest_required_check:
runs-on: ubuntu-latest
# Here, we capture whether any files have changed to indicate we need to run
# python tests
outputs:
any_changed: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v39
with:
files: |
*.py
mathesar/**
db/**
python_lint_required_check:
runs-on: ubuntu-latest
# Here, we capture whether any files have changed to indicate we need to run
# python linter
outputs:
any_changed: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v39
with:
files: '**.py'
sql_tests_required_check:
runs-on: ubuntu-latest
# Here, we capture whether any files have changed to indicate we need to run
# SQL tests
outputs:
any_changed: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v39
with:
files: '**.sql'
vulture:
runs-on: ubuntu-latest
name: Find unused code
if: needs.python_lint_required_check.outputs.any_changed == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Install Vulture
run: pip3 install vulture
- name: Run Vulture
run: vulture .
python_tests:
name: Run Python tests
runs-on: ubuntu-latest
needs: pytest_required_check
if: needs.pytest_required_check.outputs.any_changed == 'true'
strategy:
matrix:
pg-version: [13, 14, 15]
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.yml -f docker-compose.dev.yml up --build -d test-service
env:
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_check
if: needs.sql_tests_required_check.outputs.any_changed == 'true'
strategy:
matrix:
pg-version: [13, 14, 15]
steps:
- uses: actions/checkout@v4
- name: Copy env file
run: cp .env.example .env
- name: Fix permissions
run: sudo chown -R 1000:1000 .
- name: Build the test DB
run: docker compose -f docker-compose.yml -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
python_lint:
name: Run Python linter
runs-on: ubuntu-latest
needs: flake8_required_check
if: needs.python_lint_required_check.outputs.any_changed == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Run flake8
uses: julianwachholz/flake8-action@main
with:
checkName: "flake8"
path: "."
plugins: flake8-no-types
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tests:
runs-on: ubuntu-latest
needs: [python_tests, sql_tests]
steps:
- name: Report success
run: echo "Backend tests succeeded or skipped!"
lint:
runs-on: ubuntu-latest
needs: python_lint
steps:
- name: Report success
run: echo "Python linter succeeded or skipped!"