-
Notifications
You must be signed in to change notification settings - Fork 713
97 lines (87 loc) · 2.89 KB
/
Copy pathtest.yml
File metadata and controls
97 lines (87 loc) · 2.89 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
name: Test Workflow with Coverage
on:
push:
branches:
- main
- demo-v4
- dev-v4
paths:
- 'src/backend/**/*.py'
- 'src/tests/**/*.py'
- 'src/mcp_server/**/*.py'
- 'src/**/pyproject.toml'
- 'pytest.ini'
- 'conftest.py'
- 'src/backend/requirements.txt'
- '.github/workflows/test.yml'
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
branches:
- main
- demo-v4
- dev-v4
paths:
- 'src/backend/**/*.py'
- 'src/tests/**/*.py'
- 'src/mcp_server/**/*.py'
- 'pytest.ini'
- 'conftest.py'
- 'src/backend/requirements.txt'
- 'src/**/pyproject.toml'
- '.github/workflows/test.yml'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r src/backend/requirements.txt
- name: Check if test files exist
id: check_tests
run: |
if [ -z "$(find src -type f -name 'test_*.py')" ]; then
echo "No test files found, skipping tests."
echo "skip_tests=true" >> $GITHUB_ENV
else
echo "Test files found, running tests."
echo "skip_tests=false" >> $GITHUB_ENV
fi
- name: Run tests with coverage
if: env.skip_tests == 'false'
env:
PYTHONPATH: src:src/backend
run: |
# Run test_app.py first (isolation required)
python -m pytest src/tests/backend/test_app.py --cov=src/backend --cov-config=.coveragerc -q
# Run remaining backend tests with coverage append
python -m pytest src/tests/backend --cov=src/backend --cov-append --cov-report=term --cov-report=xml --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py
- name: Check coverage threshold
if: env.skip_tests == 'false'
run: |
if [ -f coverage.xml ]; then
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); print(float(root.attrib.get('line-rate', 0)) * 100)")
echo "Overall coverage: $COVERAGE%"
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "::error::Coverage is below 80% threshold. Current: $COVERAGE%"
exit 1
fi
echo "✅ Coverage threshold met: $COVERAGE% >= 80%"
else
echo "::error::coverage.xml not found"
exit 1
fi
- name: Skip coverage report if no tests
if: env.skip_tests == 'true'
run: |
echo "Skipping coverage report because no tests were found."