From 5731b337d96842bf185da805b9a6c55e021bb544 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Tue, 9 Dec 2025 10:16:22 +0100 Subject: [PATCH] Fix SonarCloud / SonarQube Scan Signed-off-by: Toni Uhlig --- .github/workflows/sonarcloud.yml | 66 -------------------------------- .github/workflows/sonarqube.yml | 51 ++++++++++++++++++++++++ scripts/build-sonarcloud.sh | 20 ---------- 3 files changed, 51 insertions(+), 86 deletions(-) delete mode 100644 .github/workflows/sonarcloud.yml create mode 100644 .github/workflows/sonarqube.yml delete mode 100755 scripts/build-sonarcloud.sh diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml deleted file mode 100644 index 5c92e73ff..000000000 --- a/.github/workflows/sonarcloud.yml +++ /dev/null @@ -1,66 +0,0 @@ -on: - push: - branches: - - main - - tmp - pull_request: - types: [opened, synchronize, reopened] - -name: Sonarcloud Scan -jobs: - sonarcloud: - runs-on: ubuntu-latest - env: - BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Set up Python 3.8 for gcovr - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - name: install gcovr 5.0 - run: | - pip install gcovr==5.0 # 5.1 is not supported - - name: Install sonar-scanner and build-wrapper - uses: SonarSource/sonarcloud-github-c-cpp@v3.2.0 - - name: Install Prerequisites - run: | - sudo apt-get update - sudo apt-get install autoconf automake cmake lcov \ - libtool pkg-config gettext \ - libjson-c-dev flex bison \ - libcurl4-openssl-dev libpcap-dev zlib1g-dev - - name: Run build-wrapper - run: | - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} ./scripts/build-sonarcloud.sh - - name: Run tests - run: | - for file in $(ls libnDPI/tests/cfgs/*/pcap/*.pcap libnDPI/tests/cfgs/*/pcap/*.pcapng libnDPI/tests/cfgs/*/pcap/*.cap); do \ - echo -n "${file} "; \ - cd ./build-sonarcloud; \ - ./nDPId-test "../${file}" >/dev/null 2>/dev/null; \ - cd ..; \ - echo "[ok]"; \ - done - mkdir -p gcov_report - cd gcov_report - gcov ../build-sonarcloud/CMakeFiles/nDPId-test.dir/nDPId-test.c.o - cd .. - - name: Run sonar-scanner - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: | - sonar-scanner \ - --define sonar.projectName=nDPId \ - --define sonar.projectVersion=1.7 \ - --define sonar.sourceEncoding=UTF-8 \ - --define sonar.branch.name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} \ - --define sonar.organization=lnslbrty \ - --define sonar.projectKey=lnslbrty_nDPId \ - --define sonar.python.version=3.8 \ - --define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json \ - --define sonar.cfamily.gcov.reportsPath=gcov_report \ - --define sonar.exclusions=build-sonarcloud/**,libnDPI/**,test/results/**,dependencies/jsmn/**,dependencies/uthash/**,examples/js-rt-analyzer-frontend/**,examples/js-rt-analyzer/**,examples/c-collectd/www/**,examples/py-flow-dashboard/assets/** diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 000000000..66427b2d6 --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,51 @@ +on: + push: + branches: + - main + - tmp + pull_request: + types: [opened, synchronize, reopened] + +name: SonarQube Scan +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install Prerequisites + run: | + sudo apt-get update + sudo apt-get install autoconf automake cmake libtool pkg-config gettext flex bison libpcap-dev zlib1g-dev libcurl4-openssl-dev libdbus-1-dev + - name: Install Build Wrapper + uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v6 + - name: Run Build Wrapper + run: | + mkdir build + cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DENABLE_COVERAGE=ON \ + -DBUILD_NDPI=ON \ + -DBUILD_EXAMPLES=ON \ + -DENABLE_CURL=ON \ + -DENABLE_ZLIB=ON \ + -DNDPI_WITH_GCRYPT=OFF + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@v6 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + --define sonar.projectName=nDPId + --define sonar.projectVersion=1.7 + --define sonar.sourceEncoding=UTF-8 + --define sonar.organization=lnslbrty + --define sonar.projectKey=lnslbrty_nDPId + --define sonar.python.version=3.8 + --define sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json + --define sonar.cfamily.gcov.reportsPath=gcov_report + --define sonar.exclusions=libnDPI/**,test/results/**,dependencies/jsmn/**,dependencies/uthash/**,examples/c-collectd/www/** diff --git a/scripts/build-sonarcloud.sh b/scripts/build-sonarcloud.sh deleted file mode 100755 index 55a62c959..000000000 --- a/scripts/build-sonarcloud.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -x - -cd "$(dirname "${0}")/.." - -BUILD_DIR=./build-sonarcloud -NUMBER_OF_PROCESSORS=$(nproc --all) -mkdir "${BUILD_DIR}" -cmake -S . -B "${BUILD_DIR}" \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DENABLE_COVERAGE=ON \ - -DBUILD_NDPI=ON \ - -DBUILD_EXAMPLES=ON \ - -DENABLE_CURL=ON \ - -DENABLE_ZLIB=ON \ - -DNDPI_WITH_GCRYPT=OFF -cmake --build "${BUILD_DIR}" -j ${NUMBER_OF_PROCESSORS} \ - --config Release