add template code coverage #83
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SonarQube | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
SONAR_SCANNER_VERSION: 4.4.0.2170 | |
SONAR_SERVER_URL: "https://sonarcloud.io" | |
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed | |
os: "ubuntu-latest" | |
build_profile: "clang20d" | |
conan_preset: "clang-20-debug" | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: seanmiddleditch/gha-setup-ninja@v4 | |
- uses: seanmiddleditch/gha-setup-vsdevenv@master | |
- uses: KyleMayes/install-llvm-action@v1 | |
with: | |
version: "17.0" | |
directory: ${{ runner.temp }}/llvm | |
- run: pip install conan | |
- name: Install sonar-scanner and build-wrapper | |
uses: SonarSource/sonarcloud-github-c-cpp@v2 | |
- name: Install GCC | |
if: ${{ env.os == 'ubuntu-latest' }} | |
run: | | |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test | |
sudo apt update | |
sudo apt install gcc-13 g++-13 | |
sudo update-alternatives --remove-all gcc || true | |
sudo update-alternatives --remove-all g++ || true | |
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 10 --slave /usr/bin/g++ g++ /usr/bin/g++-13 | |
sudo apt install lcov | |
- name: Cache conan packages | |
id: cache-conan | |
uses: actions/cache@v3 | |
with: | |
path: ~/.conan2/p | |
key: conan-cache-packages-${{ env.build_profile }} | |
- name: Create Build Environment | |
run: cmake -E make_directory ${{github.workspace}}/build | |
- name: Configure CMake | |
shell: bash | |
env: | |
PR: "${{github.workspace}}/.github/build_profiles/${{env.build_profile}}" | |
run: | | |
cmake -E make_directory "${{github.workspace}}/build" | |
conan install "${{github.workspace}}" --build=missing -pr $PR -pr:b $PR | |
conan cache clean | |
cmake -S "${{github.workspace}}" --preset conan-${{ env.conan_preset }} -DENABLE_LLVM_COV:BOOL=ON | |
- name: Build using Sonar wrapper | |
run: | | |
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build --preset conan-${{ env.conan_preset }} | |
- name: Template coverage | |
run: | | |
wget https://github.com/petiaccja/TemplateCoverage/releases/download/v1.1.0/TemplateCoverage_Linux_x86_64.zip | |
unzip TemplateCoverage_Linux_x86_64.zip | |
python3 ./TemplateCoverage_Linux_x86_64/run_on_compile_commands.py -p ${{github.workspace}}/build/${{env.conan_preset}}/compile_commands.json ./TemplateCoverage_Linux_x86_64/template-coverage -- --format=lcov --out-file=${{github.workspace}}/template_coverage.info | |
- name: Test & code coverage | |
working-directory: ${{github.workspace}}/build/${{ env.conan_preset }}/bin | |
shell: bash | |
run: | | |
./test --reporter junit --out ${{github.workspace}}/tests.xml | |
llvm-profdata merge -sparse default.profraw -o coverage.profdata | |
llvm-cov export -format=lcov -object ./test -instr-profile=coverage.profdata > ${{github.workspace}}/test_coverage.info | |
lcov -a ${{github.workspace}}/template_coverage.info -a ${{github.workspace}}/test_coverage.info -o ${{github.workspace}}/coverage.info | |
- name: Run sonar-scanner | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" |