-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Generate SonarCloud code coverage | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
env: | ||
PACKAGES: libspdlog-dev libpcap-dev libprotobuf-dev libgmock-dev | ||
|
||
jobs: | ||
code_coverage: | ||
if: github.repository == 'uweseimet/scsi2pi' | ||
env: | ||
SOURCES: cpp | ||
BUILD_WRAPPER_OUT_DIR: "$HOME/.build_wrapper_out" # Directory where build-wrapper output will be placed | ||
SONAR_SCANNER_VERSION: 4.8.1.3023 | ||
SONAR_SERVER_URL: "https://sonarcloud.io" | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
SONAR_PROJECT_KEY: "uweseimet/scsi2pi" | ||
SONAR_ORGANIZATION: "uweseimet" | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
|
||
- name: Install dependencies | ||
run: sudo apt-get install ${{ env.PACKAGES }} | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 17 | ||
|
||
- uses: actions/cache@v3 | ||
name: Cache setup | ||
id: sonar-install-cache | ||
with: | ||
path: ~/.sonar | ||
key: sonar-with-build-wrapper-${{ env.SONAR_SCANNER_VERSION }} | ||
|
||
- name: Set up scanner | ||
if: steps.sonar-install-cache.outputs.cache-hit != 'true' | ||
env: | ||
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip | ||
run: | | ||
mkdir -p $HOME/.sonar | ||
curl -sSLo /tmp/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} | ||
unzip -o /tmp/sonar-scanner.zip -d $HOME/.sonar/ | ||
- name: Set up build wrapper | ||
if: steps.sonar-install-cache.outputs.cache-hit != 'true' | ||
env: | ||
BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip | ||
run: | | ||
curl -sSLo /tmp/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} | ||
unzip -o /tmp/build-wrapper-linux-x86.zip -d $HOME/.sonar/ | ||
- name: Generate coverage | ||
run: >- | ||
(mkdir -p ${{ env.BUILD_WRAPPER_OUT_DIR }} || true) && | ||
$HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 | ||
--out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} | ||
make -j $(nproc) -C $SOURCES coverage | ||
- name: Run gcov | ||
working-directory: cpp | ||
run: gcov --preserve-paths $(find -name '*.gcno') | ||
|
||
- name: Run scanner | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: >- | ||
$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin/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.cfamily.gcov.reportsPath=. | ||
--define sonar.coverage.exclusions="cpp/**/test/**" | ||
--define sonar.cpd.exclusions="cpp/**/test/**" |