-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (137 loc) · 5.58 KB
/
coverage.yml
File metadata and controls
155 lines (137 loc) · 5.58 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
name: Code Coverage
on:
push:
branches: [ main, phase-* ]
pull_request:
branches: [ main ]
jobs:
coverage:
name: Coverage Analysis
runs-on: ubuntu-24.04
steps:
- name: Checkout database_system
uses: actions/checkout@v4
with:
submodules: recursive
- name: Checkout common_system
uses: actions/checkout@v4
with:
repository: kcenon/common_system
path: common_system
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: |
sudo apt-get update
# Use GCC 13 for full C++20 std::format support
sudo apt-get install -y cmake ninja-build g++-13 libgtest-dev libgmock-dev lcov pkg-config
- name: Build and install common_system
run: |
cd common_system
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DUSE_UNIT_TEST=OFF \
-DCMAKE_C_COMPILER=gcc-13 -DCMAKE_CXX_COMPILER=g++-13
cmake --build build --config Release
sudo cmake --install build --prefix /usr/local
- name: Configure CMake with coverage
run: |
cmake -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER=gcc-13 \
-DCMAKE_CXX_COMPILER=g++-13 \
-DCMAKE_CXX_FLAGS="--coverage -fprofile-arcs -ftest-coverage" \
-DCMAKE_C_FLAGS="--coverage -fprofile-arcs -ftest-coverage" \
-DALLOW_BUILD_WITHOUT_NETWORK_SYSTEM=ON \
-DUSE_UNIT_TEST=ON \
-DBUILD_DATABASE_SAMPLES=ON \
-DDATABASE_BUILD_INTEGRATION_TESTS=OFF \
-DUSE_POSTGRESQL=OFF
- name: Build with coverage
run: cmake --build build --config Debug
- name: Run tests
timeout-minutes: 5
run: |
cd build
# Run tests with timeout to prevent hanging
ctest -C Debug --output-on-failure --timeout 30 || true
- name: Generate coverage report
run: |
cd build
# Capture coverage data
# Ubuntu 22.04 lcov 1.14 only supports --ignore-errors source
lcov --directory . --capture --output-file coverage.info --ignore-errors source --rc lcov_branch_coverage=0 2>/dev/null || \
lcov --directory . --capture --output-file coverage.info 2>/dev/null || true
# Filter out system headers and test files
if [ -f coverage.info ]; then
lcov --remove coverage.info '/usr/*' '*/test/*' '*/tests/*' '*/examples/*' '*/samples/*' '*/googletest/*' \
--output-file coverage_filtered.info --ignore-errors source 2>/dev/null || true
# Generate HTML report
if [ -f coverage_filtered.info ]; then
genhtml coverage_filtered.info --output-directory coverage_html --ignore-errors source 2>/dev/null || \
echo "⚠️ HTML coverage report generation skipped"
# Print summary
lcov --list coverage_filtered.info --ignore-errors source 2>/dev/null || \
echo "⚠️ Coverage summary generation skipped"
fi
else
echo "⚠️ Coverage data file not created"
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./build/coverage_filtered.info
flags: unittests
name: database_system-coverage
fail_ci_if_error: false
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
build/coverage.info
build/coverage_filtered.info
build/coverage_html/
retention-days: 7
- name: Check coverage threshold (80%)
id: coverage-check
run: |
if [ -f build/coverage_filtered.info ]; then
# Extract line coverage percentage
COVERAGE=$(lcov --summary build/coverage_filtered.info 2>&1 | grep "lines" | grep -oP '\d+\.\d+%' | head -1 | tr -d '%')
echo "Line coverage: ${COVERAGE}%"
echo "coverage=${COVERAGE}" >> $GITHUB_OUTPUT
# Check if coverage meets threshold (80%)
if (( $(echo "$COVERAGE >= 80" | bc -l) )); then
echo "Coverage check PASSED: ${COVERAGE}% >= 80%"
echo "status=passed" >> $GITHUB_OUTPUT
else
echo "::warning::Coverage check FAILED: ${COVERAGE}% < 80%"
echo "status=failed" >> $GITHUB_OUTPUT
# Don't fail the build yet - just warn
fi
else
echo "status=skipped" >> $GITHUB_OUTPUT
echo "::warning::Coverage data not available"
fi
- name: Coverage summary
if: always()
run: |
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f build/coverage_filtered.info ]; then
echo "Coverage data collected successfully." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Value |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Line Coverage | ${{ steps.coverage-check.outputs.coverage }}% |" >> $GITHUB_STEP_SUMMARY
echo "| Threshold | 80% |" >> $GITHUB_STEP_SUMMARY
echo "| Status | ${{ steps.coverage-check.outputs.status }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.coverage-check.outputs.status }}" = "failed" ]; then
echo "**Warning:** Coverage is below the 80% threshold." >> $GITHUB_STEP_SUMMARY
fi
else
echo "No coverage data generated." >> $GITHUB_STEP_SUMMARY
fi