Files
deskflow/.github/workflows/sonarcloud-analysis.yml
2024-10-18 18:23:26 +01:00

95 lines
2.8 KiB
YAML

name: "SonarCloud Analysis"
on:
workflow_dispatch:
workflow_call:
secrets:
SONAR_TOKEN:
required: true
jobs:
sonarcloud-analysis:
if: ${{ vars.SONAR_SCANNER_ENABLED }}
runs-on: ${{ vars.SONAR_SCANNER_RUNNER || 'ubuntu-24.04' }}
container: deskflow/deskflow:ubuntu-22.04-amd64
timeout-minutes: 20
env:
SONAR_SCANNER_VERSION: 6.1.0.4477
SONAR_SCANNER_OPTS: -server
SONAR_SCANNER_URL_BASE: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli
CPU_CORE_COUNT: ${{ vars.SONAR_SCANNER_CPU_COUNT || 4 }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# the fetch-tags option for checkout does not work correctly so we need todo this
- name: Fetch tags
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
git fetch --tags --force
- name: Add Kitware repo
uses: ./.github/actions/add-kitware-repo
with:
distro: jammy
- name: Install dependencies
run: |
./scripts/install_deps.py
apt install curl unzip cmake -y
pip install gcovr
env:
# Prevent apt prompting for input.
DEBIAN_FRONTEND: noninteractive
- name: Install sonar-scanner and build-wrapper
uses: sonarsource/sonarcloud-github-c-cpp@v3
- name: Configure
run: |
cmake -B build \
-G "Ninja" \
-DCMAKE_BUILD_TYPE="Debug" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DENABLE_COVERAGE=ON
- name: Build
run: |
build-wrapper-linux-x86-64 --out-dir bw-output cmake --build build -j${CPU_CORE_COUNT}
- name: Unit tests coverage
env:
QT_QPA_PLATFORM: offscreen
run: cmake --build build --target coverage-unittests
- name: Integration tests coverage
env:
QT_QPA_PLATFORM: offscreen
run: cmake --build build --target coverage-integtests
- name: Get coverage report paths
id: coverage-paths
run: |
unittests=$(find build -name coverage-unittests.xml)
integtests=$(find build -name coverage-integtests.xml)
paths="${unittests}${integtests:+,$integtests}"
if [ -z "$paths" ]; then
echo "Error: No coverage files found"
exit 1
fi
echo "csv=$paths" >> $GITHUB_OUTPUT
- name: Run SonarScanner
run: |
export PATH=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64/bin:$PATH
sonar-scanner \
-Dsonar.coverageReportPaths=${{ steps.coverage-paths.outputs.csv }} \
-Dsonar.cfamily.threads=${{ env.CPU_CORE_COUNT }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}