SonarCloud C/C++ CI (Trigger #127) #450
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: 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 sonar-scanner and build-wrapper | |
uses: SonarSource/sonarcloud-github-c-cpp@v2 | |
- 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 sonar-scanner | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
sonar-scanner \ | |
--define sonar.projectKey="ndsev_zserio" \ | |
--define sonar.organization="ndsev" \ | |
--define sonar.sourceEncoding="UTF-8" \ | |
--define sonar.sources="compiler/extensions/cpp/runtime/src,build/test/extensions/cpp/linux64-gcc/release" \ | |
--define sonar.inclusions="**/*.h,**/*.cpp" \ | |
--define sonar.exclusions="**/CMakeFiles/**/*" \ | |
--define sonar.tests="compiler/extensions/cpp/runtime/test,test" \ | |
--define sonar.test.inclusions="compiler/**/test/**/*.h,compiler/**/test/**/.cpp,test/**/*.h,test/**/*.cpp" \ | |
--define sonar.scm.exclusions.disabled="true" \ | |
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \ | |
--define sonar.scm.revision="${{ github.event.workflow_run.head_sha }}" \ | |
--define sonar.branch.name="${{ github.event.workflow_run.head_branch }}" \ | |
--define sonar.pullrequest.key="${{ env.PULL_REQUEST_KEY }}" \ | |
--define sonar.pullrequest.branch="${{ env.PULL_REQUEST_BRANCH }}" \ | |
--define sonar.pullrequest.base="${{ env.PULL_REQUEST_BASE }}" |