Skip to content

SonarQube Code Coverage #591

SonarQube Code Coverage

SonarQube Code Coverage #591

Workflow file for this run

name: C++ Build
on:
push:
branches:
- main
- development
pull_request:
branches:
- main
- development
jobs:
build_test_and_analyse:
runs-on: [self-hosted, linux, x64]
env:
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
# Directory where build-wrapper output will be placed
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
TARGET_DIR: "/home/actions/actions-runner/_work/bdk-cpp/bdk-cpp"
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
steps:
- name: Clone the repository
run: git clone https://github.com/${{github.repository}} ${{env.TARGET_DIR}} || true
- name: Sync with remote repository
run: git -C ${{env.TARGET_DIR}} fetch
- name: Checkout to current branch
run: git -C ${{env.TARGET_DIR}} checkout ${{env.BRANCH_NAME}}
- name: Set user.email
run: git -C ${{env.TARGET_DIR}} config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Set user.name
run: git -C ${{env.TARGET_DIR}} config --global user.name "github-actions"
- name: Update local repository
run: git -C ${{env.TARGET_DIR}} pull
- name: Build the container
run: ./scripts/auto.sh -s bdk build
- name: Stop the container
run: ./scripts/auto.sh -s bdk stop
- name: Restart the container
run: ./scripts/auto.sh -s bdk up
- name: Clean previous build (if there is one)
run: ./scripts/auto.sh -s bdk exec 'make -C build clean' || true
- name: Configure MOLD linker
run: ./scripts/auto.sh -s bdk exec 'cmake -S . -B build
-DSONARQUBE_ANALYSIS=ON -DDEBUG=OFF
-DCMAKE_EXE_LINKER_FLAGS=\"-fuse-ld=mold\"
-DCMAKE_SHARED_LINKER_FLAGS=\"-fuse-ld=mold\"'
- name: Build with SonarQube BuildWrapper + CMake
run: ./scripts/auto.sh -s bdk exec \
'build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }}
cmake --build build --config Release -- -j $(nproc)'
- name: Run Tests
run: ./scripts/auto.sh -s bdk exec \
'./build/src/bins/bdkd-tests/bdkd-tests -d yes'
- name: Delete coverage XML report (if any)
run: ./scripts/auto.sh -s bdk exec 'rm coverage.xml || true'
- name: Collect coverage into one XML report
run: ./scripts/auto.sh -s bdk exec \
'gcovr -d \
--gcov-ignore-errors=all \
--gcov-ignore-parse-errors=all \
--sonarqube -o coverage.xml'
- name: Run SonarQube Scanner
run: ./scripts/auto.sh -s bdk exec \
'env SONAR_TOKEN=${{ env.SONAR_TOKEN }}
SONAR_HOST_URL=${{ env.SONAR_HOST_URL }}
sonar-scanner
--define sonar.cfamily.build-wrapper-output=${{ env.BUILD_WRAPPER_OUT_DIR }}
--define sonar.coverageReportPaths=coverage.xml'
documentation:
runs-on: [self-hosted, linux, x64]
needs: build_test_and_analyse
steps:
- name: Generate Doxygen Documentation
run: ./scripts/auto.sh -s bdk exec 'doxygen Doxyfile'
- name: Publish Documentation
uses: actions/upload-artifact@v4
with:
name: Documentation
path: docs