From 8e1d628adcdf507977e95d52e555f77635af74ec Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Thu, 19 Dec 2024 18:12:08 +0100 Subject: [PATCH 1/2] SQCPPGHA-13 Use unified sonarqube-scan-action (#10) * Update README.adoc * Update build.yml --- .github/workflows/build.yml | 20 ++++++++++---------- README.adoc | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d68e361..7108763 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,12 +25,12 @@ jobs: curl -L https://github.com/OpenCppCoverage/OpenCppCoverage/releases/download/release-0.9.9.0/OpenCppCoverageSetup-x64-0.9.9.0.exe -o OpenCppCoverageSetup.exe Start-Process -FilePath .\OpenCppCoverageSetup.exe -ArgumentList "/SUPRESSMSGBOXES /NORESTART /VERYSILENT" -NoNewWindow -Wait - - name: Install sonar-scanner and build-wrapper - uses: sonarsource/sonarcloud-github-c-cpp@v3 + - name: Install Build Wrapper + uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v4 - - name: Run build-wrapper + - name: Run Build Wrapper run: | - build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} msbuild sonar_scanner_example.vcxproj /t:rebuild /nodeReuse:false + build-wrapper-win-x86-64.exe --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} msbuild sonar_scanner_example.vcxproj /t:rebuild /nodeReuse:false - name: Build tests run: | msbuild test1\test1.vcxproj @@ -38,11 +38,11 @@ jobs: - name: Run tests with coverage run: | &"C:\Program Files\OpenCppCoverage\OpenCppCoverage.exe" --cover_children --sources=$(pwd) --modules test*\*\test*.dll "--export_type=cobertura:cobertura.xml" -- vstest.console.exe test1\*\test1.dll test2\*\test2.dll - - name: Run sonar-scanner + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@v4 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} # Put the name of your token here - run: > - sonar-scanner - --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" - --define sonar.cfamily.cobertura.reportPaths="cobertura.xml" + with: + args: > + --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" + --define sonar.cfamily.cobertura.reportPaths="cobertura.xml" diff --git a/README.adoc b/README.adoc index add0174..c9ce135 100644 --- a/README.adoc +++ b/README.adoc @@ -8,7 +8,7 @@ image:{img-build-status}[Build Status, link={uri-build-status}] image:{img-qg-status}[Quality Gate Status,link={uri-qg-status}] -*The test coverage shown here works on both SonarQube and SonarCloud. This project is analysed on https://sonarcloud.io/dashboard?id=sonarsource-cfamily-examples_windows-msbuild-opencppcoverage-gh-actions-sc[SonarCloud]!* +*The test coverage shown here works on both SonarQube Server and Cloud. This project is analysed on https://sonarcloud.io/dashboard?id=sonarsource-cfamily-examples_windows-msbuild-opencppcoverage-gh-actions-sc[SonarQube Cloud]!* :note-caption: :information_source: NOTE: This simple example aims at demonstrating code coverage in action. It explains how to add coverage on a project for which the analysis is already configured. Analysis configuration examples are available https://github.com/sonarsource-cfamily-examples?q=topic%3Amsbuild[here]. + @@ -18,25 +18,25 @@ To get coverage and feed it to the sonar-scanner, use the following procedure: . Build and run your tests using `vstest.console.exe`, wrapping the call with `OpenCppCoverage.exe` . Point the property `sonar.cfamily.cobertura.reportPaths` to the path that will contain your XML coverage report -. Run `sonar-scanner` as the final step +. Run the SonarQube scan using https://github.com/SonarSource/sonarqube-scan-action[the SonarSource/sonarqube-scan-action action] as final step You can take a look at the link:sonar-project.properties[sonar-project.properties] and link:.github/workflows/build.yml[build.yml] to see it in practice. = Documentation -- https://docs.sonarcloud.io/advanced-setup/languages/c-c-objective-c/[Documentation overview of the C, C++ and Objective-C analyzer] -- https://docs.sonarcloud.io/getting-started/github/[Documentation of using SonarCloud with GitHub] -- https://docs.sonarcloud.io/advanced-setup/languages/c-family/prerequisites/#generating-a-compilation-database[Generating a compilation database (compile_commands.json)] -- https://docs.sonarsource.com/sonarcloud/advanced-setup/languages/c-family/running-the-analysis/[Running the analysis in Compilation Database mode] -- https://docs.sonarcloud.io/enriching/test-coverage/test-coverage-parameters/[Test coverage parameters] -- https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/github-actions-for-sonarcloud/[GitHub Action for C and C++ usage] +- https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/c-family/overview/[C/C++/Objective-C analysis overview] +- https://docs.sonarcloud.io/getting-started/github/[Getting started with GitHub] +- https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/c-family/prerequisites/#generating-a-compilation-database[Generating a compilation database] +- https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/c-family/running-the-analysis/[Running the CFamily analysis] +- https://docs.sonarsource.com/sonarqube-cloud/enriching/test-coverage/test-coverage-parameters/[Test coverage parameters] +- https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/ci-based-analysis/github-actions-for-sonarcloud/[Analyze your repository with GitHub Actions] = Code Description An example of a flawed C++ code. The https://github.com/sonarsource-cfamily-examples/code[code repository] can be https://github.com/sonarsource-cfamily-examples/automatic-analysis-sc[analyzed automatically], but it can also be compiled with different build systems using different CI pipelines on Linux, macOS, and Windows. The https://github.com/sonarsource-cfamily-examples/code[code repository] is forked into other repositories in https://github.com/sonarsource-cfamily-examples[this collection] to add a specific build system, platform, and CI. -The downstream repositories are analyzed either with https://www.sonarqube.org/[SonarQube] or https://sonarcloud.io/[SonarCloud]. +The downstream repositories are analyzed either with https://www.sonarqube.org/[SonarQube Server] or https://sonarcloud.io/[SonarQube Cloud]. You can find examples for: @@ -63,8 +63,8 @@ Running on the following CI services: Configured for analysis on: -* https://github.com/sonarsource-cfamily-examples?q=-sq[SonarQube] -* https://github.com/sonarsource-cfamily-examples?q=-sc[SonarCloud] +* https://github.com/sonarsource-cfamily-examples?q=-sq[SonarQube Server] +* https://github.com/sonarsource-cfamily-examples?q=-sc[SonarQube Cloud] You can find also a few examples demonstrating: From 9ce66e00bc58033616ddafcfb94d3aa3a8c457a9 Mon Sep 17 00:00:00 2001 From: Abbas Sabra <49131500+AbbasNS@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:52:42 +0100 Subject: [PATCH 2/2] Update README.adoc Co-authored-by: Antonio Aversa --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index c9ce135..018ab1b 100644 --- a/README.adoc +++ b/README.adoc @@ -25,7 +25,7 @@ You can take a look at the link:sonar-project.properties[sonar-project.propertie = Documentation - https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/c-family/overview/[C/C++/Objective-C analysis overview] -- https://docs.sonarcloud.io/getting-started/github/[Getting started with GitHub] +- https://docs.sonarsource.com/sonarqube-cloud/getting-started/github/[Getting started with GitHub] - https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/c-family/prerequisites/#generating-a-compilation-database[Generating a compilation database] - https://docs.sonarsource.com/sonarqube-cloud/advanced-setup/languages/c-family/running-the-analysis/[Running the CFamily analysis] - https://docs.sonarsource.com/sonarqube-cloud/enriching/test-coverage/test-coverage-parameters/[Test coverage parameters]