From 939ad287842129178b2945df4e3951137bc4b382 Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Fri, 20 Feb 2026 15:17:51 -0700 Subject: [PATCH] Add coverage workflow and badge --- .github/workflows/code-coverage.yml | 122 ++++++++++++++++++++++++++++ README.md | 6 +- 2 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/code-coverage.yml diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 00000000..842a0bec --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,122 @@ +# +# 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) +# + +# Instructions +# +# After running this workflow successfully, go to https://github.com/ORGANIZATION/REPO/settings/pages +# and enable github pages on the code-coverage branch. +# The pages will be hosted at https://ORGANIZATION.github.io/REPO +# + +name: Code Coverage + +on: + push: + branches: + - master + - develop + paths: + - 'src/**' + - 'include/**' + - '.github/workflows/code-coverage.yml' + workflow_dispatch: + +env: + GIT_FETCH_JOBS: 8 + NET_RETRY_COUNT: 5 + # Commit title of the automatically created commits + GCOVR_COMMIT_MSG: "Update coverage data" + # Should branch coverage be reported? Default to no. + BOOST_BRANCH_COVERAGE: 0 + +jobs: + build: + defaults: + run: + shell: bash + + strategy: + fail-fast: false + matrix: + include: + - runs-on: "ubuntu-24.04" + name: Coverage + cxxstd: "20" + gcovr_script: './ci-automation/scripts/lcov-jenkins-gcc-13.sh --only-gcovr' + + name: ${{ matrix.name }} + runs-on: ${{ matrix.runs-on }} + timeout-minutes: 120 + + 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: 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: Build and run tests & collect coverage data + run: | + set -xe + ls -al + export ORGANIZATION=${GITHUB_REPOSITORY_OWNER} + export REPONAME=$(basename ${GITHUB_REPOSITORY}) + export B2_CXXSTD=${{matrix.cxxstd}} + ${{matrix.gcovr_script}} + + - name: Checkout GitHub pages branch + uses: actions/checkout@v6 + with: + ref: code-coverage + path: gh_pages_dir + + - name: Copy gcovr results + run: | + set -xe + pwd + ls -al + touch gh_pages_dir/.nojekyll # Prevent GH pages from treating these files as Jekyll pages. + mkdir -p gh_pages_dir/develop + mkdir -p gh_pages_dir/master + rm -rf "gh_pages_dir/${GITHUB_REF_NAME}/gcovr" + cp -rp gcovr gh_pages_dir/${GITHUB_REF_NAME}/ + echo -e "\n\n\n\ndevelop
\nmaster
\n\n\n" > gh_pages_dir/index.html + # In the future: echo -e "\n\n\n\ngcovr
\n\n\n" > gh_pages_dir/develop/index.html + echo -e "\n\n\n\n\n\n\n" > gh_pages_dir/develop/index.html + cp gh_pages_dir/develop/index.html gh_pages_dir/master/index.html + cd gh_pages_dir + git add . + git commit --amend -m "$GCOVR_COMMIT_MSG" + git push -f origin code-coverage diff --git a/README.md b/README.md index 32021b01..f38753fd 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ [![Boost.HTTP](doc/modules/ROOT/images/repo-logo.png)](http://master.http.cpp.al/) -| | Docs | GitHub Actions | Drone | Codecov | +| | Docs | GitHub Actions | Drone | Code Coverage | |---|---|---|---|---| -| [`master`](https://github.com/cppalliance/http/tree/master) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](https://master.http.cpp.al/) | [![CI](https://github.com/cppalliance/http/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/cppalliance/http/actions/workflows/ci.yml?query=branch%3Amaster) | [![Build Status](https://drone.cpp.al/api/badges/cppalliance/http/status.svg?ref=refs/heads/master)](https://drone.cpp.al/cppalliance/http/branches) | [![codecov](https://codecov.io/gh/cppalliance/http/branch/master/graph/badge.svg)](https://app.codecov.io/gh/cppalliance/http/tree/master) | -| [`develop`](https://github.com/cppalliance/http/tree/develop) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](https://develop.http.cpp.al/) | [![CI](https://github.com/cppalliance/http/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/cppalliance/http/actions/workflows/ci.yml?query=branch%3Adevelop) | [![Build Status](https://drone.cpp.al/api/badges/cppalliance/http/status.svg?ref=refs/heads/develop)](https://drone.cpp.al/cppalliance/http/branches) | [![codecov](https://codecov.io/gh/cppalliance/http/branch/develop/graph/badge.svg)](https://app.codecov.io/gh/cppalliance/http/tree/develop) | +| [`master`](https://github.com/cppalliance/http/tree/master) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](https://master.http.cpp.al/) | [![CI](https://github.com/cppalliance/http/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/cppalliance/http/actions/workflows/ci.yml?query=branch%3Amaster) | [![Build Status](https://drone.cpp.al/api/badges/cppalliance/http/status.svg?ref=refs/heads/master)](https://drone.cpp.al/cppalliance/http/branches) | [![Lines](https://cppalliance.org/http/master/gcovr/badges/coverage-lines.svg)](https://cppalliance.org/http/master/gcovr/index.html) | +| [`develop`](https://github.com/cppalliance/http/tree/develop) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](https://develop.http.cpp.al/) | [![CI](https://github.com/cppalliance/http/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/cppalliance/http/actions/workflows/ci.yml?query=branch%3Adevelop) | [![Build Status](https://drone.cpp.al/api/badges/cppalliance/http/status.svg?ref=refs/heads/develop)](https://drone.cpp.al/cppalliance/http/branches) | [![Lines](https://cppalliance.org/http/develop/gcovr/badges/coverage-lines.svg)](https://cppalliance.org/http/develop/gcovr/index.html) | ## Boost.HTTP