Skip to content

Commit 20e9efd

Browse files
committed
Add code coverage script.
1 parent a10f3c8 commit 20e9efd

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#
2+
# Copyright (c) 2026 Sam Darwin
3+
# Copyright (c) 2026 Alexander Grund
4+
#
5+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
6+
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
#
8+
9+
# Instructions
10+
#
11+
# After running this workflow successfully, go to https://github.com/ORGANIZATION/REPO/settings/pages
12+
# and enable github pages on the code-coverage branch.
13+
# The pages will be hosted at https://ORGANIZATION.github.io/REPO
14+
#
15+
16+
name: Code Coverage
17+
18+
on:
19+
push:
20+
branches:
21+
- master
22+
- develop
23+
paths:
24+
- 'src/**'
25+
- 'include/**'
26+
- '.github/workflows/code-coverage.yml'
27+
workflow_dispatch:
28+
29+
concurrency:
30+
group: code-coverage-pages
31+
cancel-in-progress: false
32+
33+
env:
34+
GIT_FETCH_JOBS: 8
35+
NET_RETRY_COUNT: 5
36+
# Commit title of the automatically created commits
37+
GCOVR_COMMIT_MSG: "Update coverage data"
38+
# Should branch coverage be reported? Default to no.
39+
BOOST_BRANCH_COVERAGE: 0
40+
# Dependencies:
41+
# EXTRA_BOOST_LIBRARIES: "myorg/myrepo other/repo3"
42+
43+
jobs:
44+
build:
45+
defaults:
46+
run:
47+
shell: bash
48+
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
include:
53+
- runs-on: "ubuntu-24.04"
54+
name: Coverage
55+
cxxstd: "20"
56+
gcovr_script: './ci-automation/scripts/lcov-jenkins-gcc-13.sh --only-gcovr'
57+
58+
name: ${{ matrix.name }}
59+
runs-on: ${{ matrix.runs-on }}
60+
timeout-minutes: 120
61+
62+
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@v6
65+
66+
- name: Check for code-coverage Branch
67+
run: |
68+
set -xe
69+
git config --global user.name cppalliance-bot
70+
git config --global user.email cppalliance-bot@example.com
71+
git fetch origin
72+
if git branch -r | grep origin/code-coverage; then
73+
echo "The code-coverage branch exists. Continuing."
74+
else
75+
echo "The code-coverage branch does not exist. Creating it."
76+
git switch --orphan code-coverage
77+
git commit --allow-empty -m "$GCOVR_COMMIT_MSG"
78+
git push origin code-coverage
79+
git checkout "$GITHUB_REF_NAME"
80+
fi
81+
82+
- name: Install Python
83+
uses: actions/setup-python@v6
84+
with:
85+
python-version: '3.13'
86+
87+
- name: Install Python packages
88+
run: pip install gcovr
89+
90+
- name: Checkout ci-automation
91+
uses: actions/checkout@v6
92+
with:
93+
repository: cppalliance/ci-automation
94+
path: ci-automation
95+
96+
- name: Build and run tests & collect coverage data
97+
run: |
98+
set -xe
99+
ls -al
100+
export ORGANIZATION=${GITHUB_REPOSITORY_OWNER}
101+
export REPONAME=$(basename ${GITHUB_REPOSITORY})
102+
export B2_CXXSTD=${{matrix.cxxstd}}
103+
${{matrix.gcovr_script}}
104+
105+
- name: Checkout GitHub pages branch
106+
uses: actions/checkout@v6
107+
with:
108+
ref: code-coverage
109+
path: gh_pages_dir
110+
111+
- name: Copy gcovr results
112+
run: |
113+
set -xe
114+
pwd
115+
ls -al
116+
touch gh_pages_dir/.nojekyll # Prevent GH pages from treating these files as Jekyll pages.
117+
mkdir -p gh_pages_dir/develop
118+
mkdir -p gh_pages_dir/master
119+
rm -rf "gh_pages_dir/${GITHUB_REF_NAME}/gcovr"
120+
cp -rp gcovr "gh_pages_dir/${GITHUB_REF_NAME}/"
121+
echo -e "<html>\n<head>\n</head>\n<body>\n<a href=\"develop/index.html\">develop</a><br>\n<a href=\"master/index.html\">master</a><br>\n</body>\n</html>\n" > gh_pages_dir/index.html
122+
# In the future: echo -e "<html>\n<head>\n</head>\n<body>\n<a href=gcovr/index.html>gcovr</a><br>\n</body>\n</html>\n" > gh_pages_dir/develop/index.html
123+
echo -e "<html>\n<head>\n<meta http-equiv=\"refresh\" content=\"0; url=./gcovr/index.html\">\n</head>\n<body>\n</body>\n</html>\n" > gh_pages_dir/develop/index.html
124+
cp gh_pages_dir/develop/index.html gh_pages_dir/master/index.html
125+
cd gh_pages_dir
126+
git add .
127+
git commit --amend -m "$GCOVR_COMMIT_MSG"
128+
git push -f origin code-coverage

0 commit comments

Comments
 (0)