Skip to content

add framework

add framework #2

Workflow file for this run

# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
#
# SPDX-License-Identifier: MPL-2.0
name: Sonar Cloud
on:
# run pipeline on push event of main branch
push:
branches:
- main
# run pipeline on pull request
pull_request:
# run pipeline on merge queue
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
sonar-cloud:
if: (github.event_name == 'push') || (!startsWith(github.head_ref, 'release'))
name: SonarCloud
runs-on: ubuntu-latest
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
CMAKE_PREFIX_PATH: /home/linuxbrew/.linuxbrew
LLVM_COV: llvm-cov-15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install -y ninja-build clang-15 lcov gcovr
sudo ln -s /usr/bin/clang-15 /usr/local/bin/clang
sudo ln -s /usr/bin/clang++-15 /usr/local/bin/clang++
- name: Enable brew
run: |
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
- name: Install C++ dependencies
run: |
brew install boost eigen nlohmann-json msgpack-cxx doctest
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v3
- name: Python test and coverage
run: |
pip install -e .[dev]
pytest
- name: Run build-wrapper for C++
run: |
cmake --preset ci-sonar
VERBOSE=1 build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build --preset ci-sonar
- name: C++ test and coverage
env:
binaries: cpp_build/ci-sonar
run: |
cd cpp_build/ci-sonar
ctest --test-dir . --output-on-failure
PATH=${PATH}:${PWD}/../.. gcovr --gcov-executable llvm-gcov.sh --sonarqube ../../cpp_coverage.xml -r ../..
cd ../..
# remove branch hits count, since it does not make sense in heavy C++ templates
sed -i -r "s/\s*branchesToCover\s*=\s*\"[0-9]+\"\s+coveredBranches\s*=\s*\"[0-9]+\"//g" cpp_coverage.xml
- name: Run sonar-scanner
# only run sonar server in push event or pull request event from own repo
if: ${{ (github.event_name == 'push') || (github.event.pull_request.head.repo.owner.login == 'PowerGridModel') }}
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 }}"