Skip to content

Commit

Permalink
Add SonarQube GitHub Action
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarcps committed Feb 3, 2024
1 parent c05a1c1 commit 28ce820
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 10 deletions.
90 changes: 80 additions & 10 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
setup:
runs-on: ubuntu-latest

container:
container:
image: debian:bookworm

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Update apt-get
run: apt-get update

Expand All @@ -39,7 +39,9 @@ jobs:

container:
image: debian:bookworm

env:
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -49,26 +51,39 @@ jobs:

- name: Install project dependencies
run: DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential cmake tmux clang-tidy autoconf libtool pkg-config libabsl-dev libboost-all-dev libc-ares-dev libcrypto++-dev libgrpc-dev libgrpc++-dev librocksdb-dev libscrypt-dev libsnappy-dev libssl-dev zlib1g-dev openssl protobuf-compiler protobuf-compiler-grpc libprotobuf-dev git


- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v2

- name: Configure CMake
run: cmake -S . -B build
run: cmake -S . -B build -DSONARQUBE_ANALYSIS=ON -DDEBUG=OFF

- name: Build with CMake
run: cmake --build build || cat build/deps/src/ethash-stamp/ethash-configure-*.log
- name: Build with SonarQube BuildWrapper + CMake
run: build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release -- -j $(nproc)

- name: Upload build artifacts
uses: actions/upload-artifact@v2
with:
name: build
path: build

- name: Upload build wrapper output
uses: actions/upload-artifact@v2
with:
name: build_wrapper_output
path: ${{ env.BUILD_WRAPPER_OUT_DIR }}

test:
needs: build
runs-on: ubuntu-latest

container:
image: debian:bookworm

env:
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed

steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -83,14 +98,69 @@ jobs:
run: apt-get update

- name: Install project dependencies
run: DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential cmake tmux clang-tidy autoconf libtool pkg-config libabsl-dev libboost-all-dev libc-ares-dev libcrypto++-dev libgrpc-dev libgrpc++-dev librocksdb-dev libscrypt-dev libsnappy-dev libssl-dev zlib1g-dev openssl protobuf-compiler protobuf-compiler-grpc libprotobuf-dev git
run: DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential cmake tmux clang-tidy autoconf libtool pkg-config libabsl-dev libboost-all-dev libc-ares-dev libcrypto++-dev libgrpc-dev libgrpc++-dev librocksdb-dev libscrypt-dev libsnappy-dev libssl-dev zlib1g-dev openssl protobuf-compiler protobuf-compiler-grpc libprotobuf-dev git gcovr

- name: Give execute permissions
run: chmod +x ./build/orbitersdkd-tests

- name: Run Catch2 Tests
working-directory: build
run: ./orbitersdkd-tests -d yes
run: ./build/orbitersdkd-tests -d yes

- name: Collect coverage into one XML report
run: |
gcovr --gcov-ignore-parse-errors --sonarqube > coverage.xml
- name: Upload coverage report
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage.xml

analysis:
needs: test
runs-on: ubuntu-latest

container:
image: debian:bookworm

env:
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Download build artifacts
uses: actions/download-artifact@v2
with:
name: build
path: build

- name: Download build wrapper output
uses: actions/download-artifact@v2
with:
name: build_wrapper_output
path: ${{ env.BUILD_WRAPPER_OUT_DIR }}

- name: Download coverage report
uses: actions/download-artifact@v2
with:
name: coverage
path: coverage.xml

- name: Update apt-get
run: apt-get update

- name: Install project dependencies
run: DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential cmake tmux clang-tidy autoconf libtool pkg-config libabsl-dev libboost-all-dev libc-ares-dev libcrypto++-dev libgrpc-dev libgrpc++-dev librocksdb-dev libscrypt-dev libsnappy-dev libssl-dev zlib1g-dev openssl protobuf-compiler protobuf-compiler-grpc libprotobuf-dev git gcovr

- name: Run SonarQube Scanner
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: |
sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" --define sonar.coverageReportPaths=coverage.xml
documentation:
needs: test
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ set(CMAKE_CXX_EXTENSIONS OFF)
SET(DEBUG ON CACHE BOOL "Debug mode")
if(DEBUG)
set(CMAKE_CXX_FLAGS "-O0 -g -fsanitize=address -fno-inline -fno-eliminate-unused-debug-types -fstack-protector -Werror=unused-variable") # Provides faster compile time.
elseif(SONARQUBE_ANALYSIS)
set(CMAKE_CXX_FLAGS "-O0 -g --coverage")
else()
set(CMAKE_CXX_FLAGS "-O2 -Werror=unused-variable")
endif()
Expand Down
15 changes: 15 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sonar.projectKey=SparqNet_orbitersdk-cpp_AY1vvp50gD6sKGxuuiUE
sonar.organization=SparqNet
sonar.cfamily.threads=4
sonar.projectVersion=1.0

# =====================================================
# Properties that will be shared amongst all modules
# =====================================================

# SQ standard properties
sonar.sources=src
sonar.sourceEncoding=UTF-8

sonar.cfamily.cpp23.enabled=true
sonar.exclusions=src/libs/**, tests/**

0 comments on commit 28ce820

Please sign in to comment.