Skip to content

Run code analysis

Run code analysis #134

Workflow file for this run

name: Run code analysis
on:
workflow_dispatch:
inputs:
branch:
required: true
type: string
description: Branch to analyze
jobs:
code_analysis:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: cpp
env:
SONAR_SERVER_URL: "https://sonarcloud.io"
SONAR_PROJECT_KEY: "uweseimet_scsi2pi"
SONAR_ORGANIZATION: "uweseimet-org"
SCAN_HOST: ${{ secrets.SCAN_HOST }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
APT_PACKAGES: clang llvm protobuf-compiler libspdlog-dev libpcap-dev libgmock-dev
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
- name: Install dependencies
run: sudo apt install -y ${{ env.APT_PACKAGES }}
- name: Compile with coverage data
run: |
make -j $(nproc) EXTRA_FLAGS="-fprofile-instr-generate -fcoverage-mapping" CXX=clang++ DEBUG=1 DATABASE=1 test &&
sed -e '1s/^/[\n/' -e '$s/,$/\n]/' obj/*.o.json > compile_commands.json
- name: Convert coverage data
run: |
llvm-profdata merge default.profraw > coverage.dat &&
llvm-cov show --show-branches=count --instr-profile coverage.dat bin/s2p_test > coverage.txt
- name: Run sonar-scanner
run: |
sonar-scanner \
--define sonar.host.url=$SONAR_SERVER_URL \
--define sonar.projectKey=$SONAR_PROJECT_KEY \
--define sonar.organization=$SONAR_ORGANIZATION \
--define sonar.scm.provider=git \
--define sonar.sourceEncoding=UTF-8 \
--define sonar.cfamily.compile-commands=compile_commands.json \
--define sonar.cfamily.llvm-cov.reportPath=coverage.txt \
--define sonar.c.file.suffixes= \
--define sonar.cpp.file.suffixes=.cpp,.h \
--define sonar.sonarLanguages=c++ \
--define sonar.branch.name=`git rev-parse --abbrev-ref HEAD` \
--define sonar.test.inclusions=test/**