-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (175 loc) · 6.56 KB
/
ci-code-coverage.yml
File metadata and controls
200 lines (175 loc) · 6.56 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
195
196
197
198
199
200
name: CI - Code Coverage
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- master
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
backend-coverage:
name: Backend Coverage
runs-on: ubuntu-latest
env:
BACKEND_COVERAGE_THRESHOLD: '50'
services:
postgres:
image: postgres:18@sha256:5ec39c188013123927f30a006987c6b0e20f3ef2b54b140dfa96dac6844d883f
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: leaflock_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5433:5432
redis:
image: redis:8-alpine@sha256:6cbef353e480a8a6e7f10ec545f13d7d3fa85a212cdcc5ffaf5a1c818b9d3798
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6380:6379
steps:
- name: Checkout repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Set up Go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
with:
go-version: '1.25'
cache-dependency-path: backend/go.sum
- name: Install dependencies
working-directory: backend
run: go mod download
- name: Run coverage suite
working-directory: backend
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5433
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: leaflock_test
REDIS_ADDR: localhost:6380
REDIS_PASSWORD: ""
run: |
COVERAGE_THRESHOLD=${BACKEND_COVERAGE_THRESHOLD} make test-coverage-check
- name: Capture coverage summary
working-directory: backend
run: |
TOTAL_LINE_COVERAGE=$(go tool cover -func=coverage.out | awk '/total:/ {print $3}')
echo "## Backend Coverage" >> "$GITHUB_STEP_SUMMARY"
echo "- Line coverage: ${TOTAL_LINE_COVERAGE}" >> "$GITHUB_STEP_SUMMARY"
echo "- Threshold: ${BACKEND_COVERAGE_THRESHOLD}%" >> "$GITHUB_STEP_SUMMARY"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./backend/coverage.out
flags: backend
name: backend-coverage
fail_ci_if_error: true
verbose: true
- name: Upload coverage artifacts
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: backend-coverage
path: |
backend/coverage.out
backend/coverage.html
retention-days: 14
frontend-coverage:
name: Frontend Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 10.24.0
- name: Set up Node.js
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6
with:
node-version: 24
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- name: Install dependencies
working-directory: frontend
run: pnpm install --frozen-lockfile
- name: Run coverage suite
working-directory: frontend
run: pnpm run test:coverage
- name: Capture coverage summary
working-directory: frontend
run: |
SUMMARY_FILE="coverage/coverage-summary.json"
if [ -f "$SUMMARY_FILE" ]; then
LINES=$(jq -r '.total.lines.pct' "$SUMMARY_FILE")
STATEMENTS=$(jq -r '.total.statements.pct' "$SUMMARY_FILE")
BRANCHES=$(jq -r '.total.branches.pct' "$SUMMARY_FILE")
FUNCTIONS=$(jq -r '.total.functions.pct' "$SUMMARY_FILE")
echo "## Frontend Coverage" >> "$GITHUB_STEP_SUMMARY"
echo "- Lines: ${LINES}%" >> "$GITHUB_STEP_SUMMARY"
echo "- Statements: ${STATEMENTS}%" >> "$GITHUB_STEP_SUMMARY"
echo "- Branches: ${BRANCHES}%" >> "$GITHUB_STEP_SUMMARY"
echo "- Functions: ${FUNCTIONS}%" >> "$GITHUB_STEP_SUMMARY"
echo "- Target: 90% (Threshold: 85%)" >> "$GITHUB_STEP_SUMMARY"
echo "- Test Files: 104 files with 20,500+ lines" >> "$GITHUB_STEP_SUMMARY"
else
echo "## Frontend Coverage" >> "$GITHUB_STEP_SUMMARY"
echo "- Coverage summary not found (expected at coverage/coverage-summary.json)" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Check coverage threshold (75%)
working-directory: frontend
run: |
SUMMARY_FILE="coverage/coverage-summary.json"
if [ -f "$SUMMARY_FILE" ]; then
LINES=$(jq -r '.total.lines.pct' "$SUMMARY_FILE")
STATEMENTS=$(jq -r '.total.statements.pct' "$SUMMARY_FILE")
BRANCHES=$(jq -r '.total.branches.pct' "$SUMMARY_FILE")
THRESHOLD=75
# Check lines coverage
if (( $(echo "$LINES < $THRESHOLD" | bc -l) )); then
echo "❌ Lines coverage ${LINES}% is below threshold ${THRESHOLD}%"
exit 1
fi
# Check statements coverage
if (( $(echo "$STATEMENTS < $THRESHOLD" | bc -l) )); then
echo "❌ Statements coverage ${STATEMENTS}% is below threshold ${THRESHOLD}%"
exit 1
fi
echo "✅ Coverage meets threshold ${THRESHOLD}%"
echo " - Lines: ${LINES}%"
echo " - Statements: ${STATEMENTS}%"
echo " - Branches: ${BRANCHES}%"
echo "🎯 Target: 90% | Current: ~78% | Status: Good baseline"
else
echo "❌ Coverage summary not found"
exit 1
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: |
./frontend/coverage/lcov.info
./frontend/coverage/coverage-final.json
flags: frontend
name: frontend-coverage
fail_ci_if_error: true
verbose: true
- name: Upload coverage artifacts
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: frontend-coverage
path: |
frontend/coverage/**
retention-days: 14