-
Notifications
You must be signed in to change notification settings - Fork 6
311 lines (269 loc) · 9.74 KB
/
Copy pathcode-coverage.yml
File metadata and controls
311 lines (269 loc) · 9.74 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#
# Copyright (c) 2026 Sam Darwin
# Copyright (c) 2026 Alexander Grund
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Official repository: https://github.com/cppalliance/burl/
#
# Instructions
#
# After running this workflow successfully, go to https://github.com/cppalliance/burl/settings/pages
# and enable github pages on the code-coverage branch.
# The coverage will be hosted at https://cppalliance.org/burl
#
name: Code Coverage
on:
push:
branches:
- master
- develop
paths:
- 'src/**'
- 'include/**'
- 'test/**'
- '.github/workflows/code-coverage.yml'
workflow_dispatch:
concurrency:
group: code-coverage-pages
cancel-in-progress: false
env:
GIT_FETCH_JOBS: 8
NET_RETRY_COUNT: 5
GCOVR_COMMIT_MSG: "Update coverage data"
jobs:
build-linux:
defaults:
run:
shell: bash
name: Coverage (Linux)
runs-on: ubuntu-24.04
timeout-minutes: 120
steps:
- name: Clone Boost.Burl
uses: actions/checkout@v6
with:
path: burl-root
- name: Setup C++
uses: alandefreitas/cpp-actions/setup-cpp@v1.9.4
id: setup-cpp
with:
compiler: gcc
version: 13
check-latest: true
- name: Install packages
uses: alandefreitas/cpp-actions/package-install@v1.9.4
with:
apt-get: >-
build-essential libssl-dev zlib1g-dev libbrotli-dev
lcov
- name: Clone Boost
uses: alandefreitas/cpp-actions/boost-clone@v1.9.4
id: boost-clone
with:
branch: ${{ (github.ref_name == 'master' && github.ref_name) || 'develop' }}
boost-dir: boost-source
scan-modules-dir: burl-root
patches: >
https://github.com/cppalliance/capy
https://github.com/cppalliance/corosio
https://github.com/cppalliance/http
- name: ASLR Fix
run: sysctl vm.mmap_rnd_bits=28
- name: Patch Boost
id: patch
run: |
set -xe
# Identify boost module being tested
module=${GITHUB_REPOSITORY#*/}
echo "module=$module" >> $GITHUB_OUTPUT
# Identify GitHub workspace root
workspace_root=$(echo "$GITHUB_WORKSPACE" | sed 's/\\/\//g')
echo -E "workspace_root=$workspace_root" >> $GITHUB_OUTPUT
# Remove module from boost-source
rm -r "boost-source/libs/$module" || true
# Copy cached boost-source to an isolated boost-root
cp -r boost-source boost-root
# Set boost-root output
cd boost-root
boost_root="$(pwd)"
boost_root=$(echo "$boost_root" | sed 's/\\/\//g')
echo -E "boost_root=$boost_root" >> $GITHUB_OUTPUT
cd ..
# Patch boost-root with workspace module
cp -r "$workspace_root"/burl-root "boost-root/libs/$module"
- name: Build with coverage
uses: alandefreitas/cpp-actions/cmake-workflow@v1.9.4
with:
source-dir: boost-root
build-dir: __build_cmake_test__
build-type: Debug
build-target: tests
run-tests: true
install-prefix: .local
cxxstd: '20'
cc: ${{ steps.setup-cpp.outputs.cc || 'gcc-13' }}
cxx: ${{ steps.setup-cpp.outputs.cxx || 'g++-13' }}
cxxflags: '--coverage -fprofile-arcs -ftest-coverage'
ccflags: '--coverage -fprofile-arcs -ftest-coverage'
shared: false
cmake-version: '>=3.20'
extra-args: |
-D Boost_VERBOSE=ON
-D BOOST_INCLUDE_LIBRARIES="${{ steps.patch.outputs.module }}"
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON
package: false
package-artifact: false
ref-source-dir: boost-root/libs/burl
- name: Install Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install Python packages
run: pip install gcovr
- name: Checkout ci-automation
uses: actions/checkout@v6
with:
repository: cppalliance/ci-automation
path: ci-automation
- name: Generate gcovr report
run: |
set -xe
module=$(basename ${GITHUB_REPOSITORY})
gcov_tool="gcov-${{ steps.setup-cpp.outputs.version-major }}"
command -v "$gcov_tool" >/dev/null 2>&1 || gcov_tool="gcov"
mkdir -p gcovr
# First pass: collect raw coverage data into JSON
gcovr \
--root boost-root \
--gcov-executable "$gcov_tool" \
--merge-mode-functions separate \
--sort uncovered-percent \
--html-title "${module}" \
--merge-lines \
--exclude-unreachable-branches \
--exclude-throw-branches \
--exclude '.*/example/.*' \
--exclude '.*/examples/.*' \
--filter ".*/${module}/.*" \
--html --output gcovr/index.html \
--json-summary-pretty --json-summary gcovr/summary.json \
--json gcovr/coverage-raw.json \
boost-root/__build_cmake_test__
# Fix paths for repo-relative display
python3 ci-automation/scripts/fix_paths.py \
gcovr/coverage-raw.json \
gcovr/coverage-fixed.json \
--repo "${module}"
# Create symlinks so gcovr can find source files at repo-relative paths
ln -sfn "boost-root/libs/${module}/include" include 2>/dev/null || true
ln -sfn "boost-root/libs/${module}/src" src 2>/dev/null || true
# Second pass: generate nested HTML from fixed JSON with custom templates
gcovr \
-a gcovr/coverage-fixed.json \
--merge-mode-functions separate \
--sort uncovered-percent \
--html-nested \
--html-template-dir=ci-automation/gcovr-templates/html \
--html-title "${module}" \
--merge-lines \
--exclude-unreachable-branches \
--exclude-throw-branches \
--exclude '(^|.*/)test/.*' \
--exclude '.*/example/.*' \
--exclude '.*/examples/.*' \
--html --output gcovr/index.html \
--json-summary-pretty --json-summary gcovr/summary.json
- name: Generate sidebar navigation
run: python3 ci-automation/scripts/gcovr_build_tree.py gcovr
- name: Generate badges
run: python3 ci-automation/scripts/generate_badges.py gcovr --json gcovr/summary.json
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: coverage-linux
path: gcovr/
deploy:
needs: [build-linux]
if: ${{ !cancelled() }}
defaults:
run:
shell: bash
name: Deploy Coverage
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Check for code-coverage Branch
run: |
set -xe
git config --global user.name cppalliance-bot
git config --global user.email cppalliance-bot@example.com
git fetch origin
if git branch -r | grep origin/code-coverage; then
echo "The code-coverage branch exists. Continuing."
else
echo "The code-coverage branch does not exist. Creating it."
git switch --orphan code-coverage
git commit --allow-empty -m "$GCOVR_COMMIT_MSG"
git push origin code-coverage
git checkout $GITHUB_REF_NAME
fi
- name: Checkout GitHub pages branch
uses: actions/checkout@v6
with:
ref: code-coverage
path: gh_pages_dir
- name: Download coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-*
path: coverage-artifacts/
- name: Copy coverage results
run: |
set -xe
touch gh_pages_dir/.nojekyll
mkdir -p "gh_pages_dir/develop"
mkdir -p "gh_pages_dir/master"
# Remove old single-directory layout (migration from gcovr/ to gcovr-linux/)
rm -rf "gh_pages_dir/${GITHUB_REF_NAME}/gcovr"
# Copy each platform's results (only if artifact exists)
for platform in linux; do
if [ -d "coverage-artifacts/coverage-${platform}" ]; then
rm -rf "gh_pages_dir/${GITHUB_REF_NAME}/gcovr-${platform}"
cp -rp "coverage-artifacts/coverage-${platform}" \
"gh_pages_dir/${GITHUB_REF_NAME}/gcovr-${platform}"
fi
done
# Generate branch index pages
for branch in develop master; do
cat > "gh_pages_dir/${branch}/index.html" << 'HTMLEOF'
<html>
<head><title>Code Coverage</title></head>
<body>
<h2>Code Coverage Reports</h2>
<ul>
<li><a href="gcovr-linux/index.html">Linux (GCC)</a></li>
</ul>
</body>
</html>
HTMLEOF
done
# Root index
cat > gh_pages_dir/index.html << 'HTMLEOF'
<html>
<head></head>
<body>
<a href="develop/index.html">develop</a><br>
<a href="master/index.html">master</a><br>
</body>
</html>
HTMLEOF
cd gh_pages_dir
git config --global user.name cppalliance-bot
git config --global user.email cppalliance-bot@example.com
git add .
git commit --amend -m "$GCOVR_COMMIT_MSG"
git push -f origin code-coverage