Files
deskflow/.github/workflows/sonarcloud-analysis.yml
Nick Bolton 5945114b7b refactor: Run SonarCloud workflow standalone and cleanup comments
fix: Prevent SonarCloud analysis from running on draft pull requests
2025-10-13 08:10:30 -04:00

92 lines
2.7 KiB
YAML

name: "SonarCloud Analysis"
# This is best run as a standalone workflow, not as part of another workflow like CI
# because of how GitHub understands the code scanning workflows in it's UI.
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
- "**/*.md"
- ".github/ISSUE_TEMPLATE/**"
- ".editorconfig"
- ".env-example"
- ".gitignore"
- ".gitattributes"
- "cspell.json"
push:
branches: [master]
jobs:
sonarcloud-analysis:
if: ${{ vars.SONAR_SCANNER_ENABLED }}
runs-on: ubuntu-latest
container: debian:trixie-slim
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: Install container dependencies
run: |
apt update -qqq > /dev/null
apt install -qqq git curl unzip gcovr > /dev/null
- name: Fancy Checkout
uses: sithlord48/fancy-checkout@v1
- name: Install project dependencies
uses: ./.github/actions/install-dependencies
with:
like: "debian"
- 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 \
-DSKIP_BUILD_TESTS=ON \
-DENABLE_COVERAGE=ON
- name: Build
run: |
build-wrapper-linux-x86-64 --out-dir bw-output cmake --build build -j${CPU_CORE_COUNT}
- name: Test coverage
shell: bash
env:
QT_QPA_PLATFORM: offscreen
run: |
tests=(`cmake --build build --target help | grep -o "^coverage-[^:]*"`)
for i in "${tests[@]}"; do
cmake --build build --target "$i"
done
- name: Get coverage report paths
id: coverage-paths
run: |
paths=$(ls -w 0 -m build/coverage-*.xml | sed 's/ //g')
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 }}