|
| 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 | +env: |
| 30 | + GIT_FETCH_JOBS: 8 |
| 31 | + NET_RETRY_COUNT: 5 |
| 32 | + # Commit title of the automatically created commits |
| 33 | + GCOVR_COMMIT_MSG: "Update coverage data" |
| 34 | + # Should branch coverage be reported? Default to no. |
| 35 | + BOOST_BRANCH_COVERAGE: 0 |
| 36 | + |
| 37 | +jobs: |
| 38 | + build: |
| 39 | + defaults: |
| 40 | + run: |
| 41 | + shell: bash |
| 42 | + |
| 43 | + strategy: |
| 44 | + fail-fast: false |
| 45 | + matrix: |
| 46 | + include: |
| 47 | + - runs-on: "ubuntu-24.04" |
| 48 | + name: Coverage |
| 49 | + cxxstd: "20" |
| 50 | + gcovr_script: './ci-automation/scripts/lcov-jenkins-gcc-13.sh --only-gcovr' |
| 51 | + |
| 52 | + name: ${{ matrix.name }} |
| 53 | + runs-on: ${{ matrix.runs-on }} |
| 54 | + timeout-minutes: 120 |
| 55 | + |
| 56 | + steps: |
| 57 | + - name: Checkout code |
| 58 | + uses: actions/checkout@v6 |
| 59 | + |
| 60 | + - name: Check for code-coverage Branch |
| 61 | + run: | |
| 62 | + set -xe |
| 63 | + git config --global user.name cppalliance-bot |
| 64 | + git config --global user.email cppalliance-bot@example.com |
| 65 | + git fetch origin |
| 66 | + if git branch -r | grep origin/code-coverage; then |
| 67 | + echo "The code-coverage branch exists. Continuing." |
| 68 | + else |
| 69 | + echo "The code-coverage branch does not exist. Creating it." |
| 70 | + git switch --orphan code-coverage |
| 71 | + git commit --allow-empty -m "$GCOVR_COMMIT_MSG" |
| 72 | + git push origin code-coverage |
| 73 | + git checkout $GITHUB_REF_NAME |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Install Python |
| 77 | + uses: actions/setup-python@v6 |
| 78 | + with: |
| 79 | + python-version: '3.13' |
| 80 | + |
| 81 | + - name: Install Python packages |
| 82 | + run: pip install gcovr |
| 83 | + |
| 84 | + - name: Checkout ci-automation |
| 85 | + uses: actions/checkout@v6 |
| 86 | + with: |
| 87 | + repository: cppalliance/ci-automation |
| 88 | + path: ci-automation |
| 89 | + |
| 90 | + - name: Build and run tests & collect coverage data |
| 91 | + run: | |
| 92 | + set -xe |
| 93 | + ls -al |
| 94 | + export ORGANIZATION=${GITHUB_REPOSITORY_OWNER} |
| 95 | + export REPONAME=$(basename ${GITHUB_REPOSITORY}) |
| 96 | + export B2_CXXSTD=${{matrix.cxxstd}} |
| 97 | + ${{matrix.gcovr_script}} |
| 98 | +
|
| 99 | + - name: Checkout GitHub pages branch |
| 100 | + uses: actions/checkout@v6 |
| 101 | + with: |
| 102 | + ref: code-coverage |
| 103 | + path: gh_pages_dir |
| 104 | + |
| 105 | + - name: Copy gcovr results |
| 106 | + run: | |
| 107 | + set -xe |
| 108 | + pwd |
| 109 | + ls -al |
| 110 | + touch gh_pages_dir/.nojekyll # Prevent GH pages from treating these files as Jekyll pages. |
| 111 | + mkdir -p gh_pages_dir/develop |
| 112 | + mkdir -p gh_pages_dir/master |
| 113 | + rm -rf "gh_pages_dir/${GITHUB_REF_NAME}/gcovr" |
| 114 | + cp -rp gcovr gh_pages_dir/${GITHUB_REF_NAME}/ |
| 115 | + 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 |
| 116 | + # 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 |
| 117 | + 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 |
| 118 | + cp gh_pages_dir/develop/index.html gh_pages_dir/master/index.html |
| 119 | + cd gh_pages_dir |
| 120 | + git add . |
| 121 | + git commit --amend -m "$GCOVR_COMMIT_MSG" |
| 122 | + git push -f origin code-coverage |
0 commit comments