Skip to content

SonarCloud C/C++ CI (Trigger #501) #824

SonarCloud C/C++ CI (Trigger #501)

SonarCloud C/C++ CI (Trigger #501) #824

Workflow file for this run

name: SonarCloud C/C++ CI
run-name: "SonarCloud C/C++ CI (Trigger #${{ github.event.workflow_run.run_number }})"
on:
workflow_run:
workflows: [ SonarCloud Trigger ]
types: [ completed ]
jobs:
run:
name: sonar_cloud
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# checkout out the proper repository in case of pull request
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0 # shallow clones should be disabled for a better relevancy of analysis
submodules: recursive
# BEGIN PULL REQUEST
- name: Download pull request number artifact
if: github.event.workflow_run.event == 'pull_request'
uses: dawidd6/action-download-artifact@v6
with:
workflow: sonar_cloud_trigger
run_id: ${{ github.event.workflow_run.id }}
name: pull_request_number
- name: "Read pull request number"
if: github.event.workflow_run.event == 'pull_request'
id: pull_request_number
uses: juliangruber/read-file-action@v1
with:
path: ./pull_request_number.txt
- name: Request GitHub API for pull_request data
if: github.event.workflow_run.event == 'pull_request'
uses: octokit/request-action@v2.x
id: get_pull_request_data
with:
route: GET /repos/${{ github.event.repository.full_name }}/pulls/${{ steps.pull_request_number.outputs.content }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout upstream base branch and checkout pull request head branch
if: github.event.workflow_run.event == 'pull_request'
run: |
git remote add upstream ${{ github.event.repository.clone_url }}
git fetch upstream
git checkout -B ${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }} \
upstream/${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }}
git checkout origin/${{ github.event.workflow_run.head_branch }}
git clean -ffdx && git reset --hard HEAD
- name: Set pull request variables
if: github.event.workflow_run.event == 'pull_request'
run: |
echo "PULL_REQUEST_KEY=${{ fromJson(steps.get_pull_request_data.outputs.data).number }}" >> ${GITHUB_ENV}
echo "PULL_REQUEST_BRANCH=${{ fromJson(steps.get_pull_request_data.outputs.data).head.ref }}" >> ${GITHUB_ENV}
echo "PULL_REQUEST_BASE=${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }}" >> ${GITHUB_ENV}
# END PULL REQUEST
- name: Install build wrapper
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v6
- name: Set up Java 8
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
- name: Install dependencies
run: |
sudo apt-get install cmake doxygen graphviz
- name: Build Zserio compiler with C++ extension
run: |
scripts/build.sh core cpp zserio
scripts/release.sh -p zserio
- name: Build C++ runtime and C++ tests under build-wrapper
run: |
cat > build_and_test.sh << EOF
#!/bin/bash
scripts/build.sh cpp_rt-linux64-gcc && scripts/release.sh -p runtime_libs && \
scripts/test.sh cpp-linux64-gcc
EOF
chmod a+x build_and_test.sh
build-wrapper-linux-x86-64 --out-dir ${{env.BUILD_WRAPPER_OUT_DIR}} ./build_and_test.sh
env:
CMAKE_EXTRA_ARGS: "-DCMAKE_BUILD_TYPE=Release"
CMAKE_BUILD_OPTIONS: "-j4"
- name: Run SonarCloud analysis
if: github.event.workflow_run.event != 'pull_request'
uses: SonarSource/sonarqube-scan-action@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_ZSERIO_TOKEN }}
with:
args: >
"-Dsonar.projectKey=ndsev_zserio"
"-Dsonar.organization=ndsev"
"-Dsonar.sourceEncoding=UTF-8"
"-Dsonar.sources=compiler/extensions/cpp/runtime/src,build/test/extensions/cpp/linux64-gcc/release"
"-Dsonar.inclusions=**/*.h,**/*.cpp"
"-Dsonar.exclusions=**/CMakeFiles/**/*"
"-Dsonar.tests=compiler/extensions/cpp/runtime/test,test"
"-Dsonar.test.inclusions=compiler/**/test/**/*.h,compiler/**/test/**/.cpp,test/**/*.h,test/**/*.cpp"
"-Dsonar.scm.exclusions.disabled=true"
"-Dsonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
"-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}"
"-Dsonar.branch.name=${{ github.event.workflow_run.head_branch }}"
- name: Run SonarCloud analysis on PR
if: github.event.workflow_run.event == 'pull_request'
uses: SonarSource/sonarqube-scan-action@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_ZSERIO_TOKEN }}
with:
args: >
"-Dsonar.projectKey=ndsev_zserio"
"-Dsonar.organization=ndsev"
"-Dsonar.sourceEncoding=UTF-8"
"-Dsonar.sources=compiler/extensions/cpp/runtime/src,build/test/extensions/cpp/linux64-gcc/release"
"-Dsonar.inclusions=**/*.h,**/*.cpp"
"-Dsonar.exclusions=**/CMakeFiles/**/*"
"-Dsonar.tests=compiler/extensions/cpp/runtime/test,test"
"-Dsonar.test.inclusions=compiler/**/test/**/*.h,compiler/**/test/**/.cpp,test/**/*.h,test/**/*.cpp"
"-Dsonar.scm.exclusions.disabled=true"
"-Dsonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
"-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}"
"-Dsonar.pullrequest.key=${{ env.PULL_REQUEST_KEY }}"
"-Dsonar.pullrequest.branch=${{ env.PULL_REQUEST_BRANCH }}"
"-Dsonar.pullrequest.base=${{ env.PULL_REQUEST_BASE }}"