Skip to content

Gather coverage from the unit tests. #121

Gather coverage from the unit tests.

Gather coverage from the unit tests. #121

Workflow file for this run

name: SonarCloud
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
contents: read
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-22.04
env:
SONAR_SERVER_URL: "https://sonarcloud.io"
# Directory where build-wrapper output will be placed
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
CLANG_VERSION: 16
BUILD_DIR: build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
submodules: 'True'
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake ninja-build
- name: Install Clang
run: |
wget https://apt.llvm.org/llvm.sh
# Force --yes to the end of the add-apt-repository command to
# prevent the llvm.sh script hanging.
sed -ie "/^add-apt-repository/ s/$/ --yes/" llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh ${{env.CLANG_VERSION }}
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@e4882e1621ad2fb48dddfa48287411bed34789b1 # v2.0.2
- name: CMake Configure
run: |
mkdir ${{ env.BUILD_DIR }}
cmake -G Ninja \
-S . \
-B ${{ env.BUILD_DIR }} \
-D COVERAGE=Yes \
-D CMAKE_C_COMPILER=clang-${{ env.CLANG_VERSION }} \
-D CMAKE_CXX_COMPILER=clang++-${{ env.CLANG_VERSION }}
- name: Build
run: |
build-wrapper-linux-x86-64 \
--out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} \
cmake --build ${{ env.BUILD_DIR }} --config Release
- name: Run Test Tools
run: |
set -v
TESTS="\
tests/iconv/iconv-test \
tests/ranges/ranges \
tests/demo8/demo8 \
tests/exhaust/icubaby-exhaust-test \
unittests/icubaby-unittests"
for f in $TESTS; do
P="${{ env.BUILD_DIR }}/$f"
LLVM_PROFILE_FILE="$P.profraw" $P
done
- name: Index the Raw Profiles
run: |
find ${{ env.BUILD_DIR }} -name \*.profraw -print0 |
xargs -0 \
llvm-profdata-${{ env.CLANG_VERSION }} \
merge \
-o ${{ env.BUILD_DIR }}/merged.profdata \
-sparse
- name: Collect Coverage
run: |
{ \
find ${{ env.BUILD_DIR }} -name CMakeFiles -prune -type f -or -type f -perm -u=x -print0 | \
xargs -0 -n 1 llvm-cov-${{ env.CLANG_VERSION }} show --instr-profile build/merged.profdata
} > coverage.txt
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
-X \
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
--define sonar.cfamily.llvm-cov.reportPath=coverage.txt \
--define sonar.exclusions='${{ env.BUILD_DIR }}/**/*,docs/**/*' \
--define sonar.host.url="${{ env.SONAR_SERVER_URL }}" \
--define sonar.organization=paulhuggett-github \
--define sonar.projectKey=paulhuggett_icubaby \
--define sonar.projectVersion="$(git rev-parse HEAD)" \
--define sonar.python.version=3.7,3.8,3.9,3.10,3.11 \
--define sonar.sourceEncoding=UTF-8