-
Notifications
You must be signed in to change notification settings - Fork 23
111 lines (96 loc) · 3.77 KB
/
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
name: Tests
on:
push:
branches:
- main # Trigger on push to the main branch
pull_request:
branches:
- main # Trigger on pull requests to the main branch
types:
- opened
- ready_for_review
- reopened
- synchronize
jobs:
backend_tests:
name: Backend Tests
runs-on: ubuntu-latest # Use the latest Ubuntu runner
steps:
- uses: actions/checkout@v4 # Checkout the repository
# Set up Python environment for Backend
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11" # Set Python version
- name: Install Backend Dependencies
run: |
python -m pip install -r requirements.txt
python -m pip install coverage pytest-cov
python -m pip install azure-keyvault-secrets
- name: Run Backend Tests with Coverage
run: |
if python -m pytest --cov=. --cov-report=xml --cov-report=html --cov-report=term-missing --junitxml=coverage-junit.xml; then
echo "Tests completed, checking coverage."
# Only fail if coverage does not meet criteria
if [ -f coverage.xml ]; then
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); coverage = root.find('coverage').get('lines').split('%')[0]; print(float(coverage))")
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage is below 80%, failing the job."
exit 1
fi
fi
else
echo "No tests found, skipping coverage check."
fi
- uses: actions/upload-artifact@v4
with:
name: backend-coverage
path: |
coverage.xml # Correct path to backend coverage
coverage-junit.xml # Correct path to backend JUnit report
htmlcov/ # Correct path to backend HTML coverage report
frontend_tests:
name: Frontend Tests
runs-on: ubuntu-latest # Use the latest Ubuntu runner
steps:
- uses: actions/checkout@v4 # Checkout the repository
# Set up Node.js environment for Frontend
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20' # Set the Node.js version
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Navigate to frontend directory
run: cd frontend
- name: Install Frontend Dependencies
run: |
cd frontend # Change to the frontend directory
npm install # Install dependencies from frontend/package.json
- name: Run Frontend Tests with Coverage
run: |
cd frontend # Change to the frontend directory
if npm run test -- --coverage; then
echo "Tests completed, checking coverage."
# Check coverage report and ensure it meets threshold
if [ -f frontend/coverage/lcov-report/index.html ]; then
COVERAGE=$(cat frontend/coverage/lcov-report/index.html | grep -oP 'total: \K[0-9]+(\.[0-9]+)?')
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage is below 80%, failing the job."
exit 1
fi
fi
else
echo "No tests found, skipping coverage check."
fi
- uses: actions/upload-artifact@v4
with:
name: frontend-coverage
path: |
frontend/coverage/ # Correct path to frontend coverage
frontend/coverage/lcov-report/ # Correct path to frontend lcov report