-
Notifications
You must be signed in to change notification settings - Fork 1
194 lines (174 loc) · 6.17 KB
/
Copy pathtest.yml
File metadata and controls
194 lines (174 loc) · 6.17 KB
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
name: Test Workflow with Coverage
on:
push:
branches:
- main
- dev
paths:
- 'src/backend-api/**/*.py'
- 'src/backend-api/pyproject.toml'
- 'src/backend-api/uv.lock'
- 'src/backend-api/pytest.ini'
- 'src/processor/**/*.py'
- 'src/processor/pyproject.toml'
- 'src/processor/uv.lock'
- '.github/workflows/test.yml'
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
branches:
- main
- dev
paths:
- 'src/backend-api/**/*.py'
- 'src/backend-api/pyproject.toml'
- 'src/backend-api/uv.lock'
- 'src/backend-api/pytest.ini'
- 'src/processor/**/*.py'
- 'src/processor/pyproject.toml'
- 'src/processor/uv.lock'
- '.github/workflows/test.yml'
permissions:
contents: read
actions: read
pull-requests: write
jobs:
backend_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install Backend Dependencies
run: |
python -m pip install --upgrade pip
cd src/backend-api
pip install -e .
pip install pytest pytest-cov pytest-asyncio
- name: Check if Backend Test Files Exist
id: check_backend_tests
run: |
if [ -z "$(find src/backend-api/src/tests -type f -name 'test_*.py' 2>/dev/null)" ]; then
echo "No backend test files found, skipping backend tests."
echo "skip_backend_tests=true" >> $GITHUB_ENV
else
echo "Backend test files found, running tests."
echo "skip_backend_tests=false" >> $GITHUB_ENV
fi
- name: Run Backend Tests with Coverage
if: env.skip_backend_tests == 'false'
run: |
cd src/backend-api
PYTHONPATH=src/app pytest src/tests \
-c /dev/null \
--rootdir=. \
--cov=src/app \
--cov-report=term-missing \
--cov-report=xml:reports/coverage.xml \
--cov-fail-under=82 \
--junitxml=pytest.xml \
-v
- name: Prefix coverage XML filenames with repo-root path
if: env.skip_backend_tests == 'false'
run: |
python <<'PY'
import xml.etree.ElementTree as ET
path = "src/backend-api/reports/coverage.xml"
prefix = "src/backend-api/src/app/"
tree = ET.parse(path)
root = tree.getroot()
for cls in root.iter("class"):
fname = cls.attrib.get("filename", "")
if fname and not fname.startswith(prefix):
cls.attrib["filename"] = prefix + fname
tree.write(path, xml_declaration=True, encoding="utf-8")
PY
- name: Pytest Coverage Comment
if: |
always() &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork == false &&
env.skip_backend_tests == 'false'
uses: MishaKav/pytest-coverage-comment@26f986d2599c288bb62f623d29c2da98609e9cd4 # v1.6.0
with:
pytest-xml-coverage-path: src/backend-api/reports/coverage.xml
junitxml-path: src/backend-api/pytest.xml
report-only-changed-files: true
- name: Skip Backend Tests
if: env.skip_backend_tests == 'true'
run: |
echo "Skipping backend tests because no test files were found."
processor_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install Processor Dependencies
run: |
python -m pip install --upgrade pip
cd src/processor
pip install -e .
pip install pytest pytest-cov pytest-asyncio
- name: Check if Processor Test Files Exist
id: check_processor_tests
run: |
if [ -z "$(find src/processor/src/tests -type f -name 'test_*.py' 2>/dev/null)" ]; then
echo "No processor test files found, skipping processor tests."
echo "skip_processor_tests=true" >> $GITHUB_ENV
else
echo "Processor test files found, running tests."
echo "skip_processor_tests=false" >> $GITHUB_ENV
fi
- name: Run Processor Tests with Coverage
if: env.skip_processor_tests == 'false'
run: |
cd src/processor
pytest src/tests \
--cov=src \
--cov-report=term-missing \
--cov-report=xml:reports/coverage.xml \
--cov-fail-under=82 \
--junitxml=pytest.xml \
-v
- name: Prefix coverage XML filenames with repo-root path
if: env.skip_processor_tests == 'false'
run: |
python <<'PY'
import xml.etree.ElementTree as ET
path = "src/processor/reports/coverage.xml"
prefix = "src/processor/src/"
tree = ET.parse(path)
root = tree.getroot()
for cls in root.iter("class"):
fname = cls.attrib.get("filename", "")
if fname and not fname.startswith(prefix):
cls.attrib["filename"] = prefix + fname
tree.write(path, xml_declaration=True, encoding="utf-8")
PY
- name: Pytest Coverage Comment (Processor)
if: |
always() &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork == false &&
env.skip_processor_tests == 'false'
uses: MishaKav/pytest-coverage-comment@26f986d2599c288bb62f623d29c2da98609e9cd4 # v1.6.0
with:
pytest-xml-coverage-path: src/processor/reports/coverage.xml
junitxml-path: src/processor/pytest.xml
title: Processor Coverage Report
unique-id-for-comment: processor
report-only-changed-files: true
- name: Skip Processor Tests
if: env.skip_processor_tests == 'true'
run: |
echo "Skipping processor tests because no test files were found."