Run code analysis #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run SonarCloud analysis | |
on: | |
workflow_dispatch: | |
jobs: | |
code_analysis: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: cpp | |
env: | |
PACKAGES: protobuf-compiler libspdlog-dev libpcap-dev libprotobuf-dev libgmock-dev | |
BUILD_WRAPPER_OUT_DIR: "$HOME/.build_wrapper_out" | |
SONAR_SERVER_URL: "https://sonarcloud.io" | |
SONAR_PROJECT_KEY: "uweseimet_scsi2pi" | |
SONAR_ORGANIZATION: ${{ secrets.SONAR_ORGANIZATION }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# Shallow clones should be disabled for a better relevancy of analysis | |
fetch-depth: 0 | |
- name: Install additional packages | |
run: sudo apt install --yes ${{ env.PACKAGES }} | |
- name: Set up Java | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: temurin | |
- name: test | |
run: echo $JAVA_HOME && echo $PATH && echo java -version | |
- name: Set up Python for gcovr | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.8 | |
- name: Install gcovr | |
run: pip install gcovr==5.0 # 5.1 is not supported | |
- name: Install sonar-scanner and build-wrapper | |
uses: SonarSource/sonarcloud-github-c-cpp@v1 | |
- name: Run build-wrapper | |
run: | | |
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make -j $(nproc) coverage DEBUG=1 | |
- name: Generate coverage data | |
run: gcovr --sonarqube > coverage.xml | |
- name: Run sonar-scanner | |
run: | | |
sonar-scanner \ | |
--define sonar.host.url=${{ env.SONAR_SERVER_URL }} \ | |
--define sonar.projectKey=${{ env.SONAR_PROJECT_KEY }} \ | |
--define sonar.organization=${{ env.SONAR_ORGANIZATION }} \ | |
--define sonar.cfamily.build-wrapper-output=${{ env.BUILD_WRAPPER_OUT_DIR }} \ | |
--define sonar.coverageReportPaths=coverage.xml \ | |
--define sonar.exclusions="obj/**,bin/**,generated/**" \ | |
--define sonar.coverage.exclusions="test/**" \ | |
--define sonar.cpd.exclusions="test/**" |