Skip to content

Commit 39ba36a

Browse files
SQCPPGHA-13 Use unified sonarqube-scan-action (#12)
1 parent bd23450 commit 39ba36a

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

.github/workflows/build.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ jobs:
1313
- uses: actions/checkout@v4
1414
with:
1515
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16-
- name: Install sonar-scanner
17-
uses: sonarsource/sonarqube-github-c-cpp@v2
18-
env:
19-
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} # SonarQube URL is stored in a GitHub secret
2016
- name: Generate compilation database
2117
run: |
2218
mkdir build
2319
cmake -S . -B build
24-
- name: Run sonar-scanner
20+
- name: SonarQube Scan
21+
uses: SonarSource/sonarqube-scan-action@v4
2522
env:
26-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2723
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
2824
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} # SonarQube URL is stored in a GitHub secret
29-
run: sonar-scanner --define sonar.cfamily.compile-commands=build/compile_commands.json
25+
with:
26+
args: >
27+
--define sonar.cfamily.compile-commands=build/compile_commands.json

README.adoc

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= C++ example project scanned on SonarQube using compilation database (compile_commands.json)
1+
= C++ example project scanned on SonarQube Server using compilation database (compile_commands.json)
22
// URIs:
33
:uri-qg-status: https://next.sonarqube.com/sonarqube/dashboard?id=sonarsource-cfamily-examples_linux-cmake-compdb-gh-actions-sq_AYCKCTwgbpi2xFX3-L27
44
:img-qg-status: https://next.sonarqube.com/sonarqube/api/project_badges/measure?project=sonarsource-cfamily-examples_linux-cmake-compdb-gh-actions-sq_AYCKCTwgbpi2xFX3-L27&metric=alert_status&token=squ_a0683d6d23bc3fa8b93a6befc840c774511333cc
@@ -8,27 +8,26 @@
88
image:{img-build-status}[Build Status, link={uri-build-status}]
99
image:{img-qg-status}[Quality Gate Status,link={uri-qg-status}]
1010

11-
*This project is analysed on https://next.sonarqube.com/sonarqube/dashboard?id=sonarsource-cfamily-examples_linux-cmake-compdb-gh-actions-sq_AYCKCTwgbpi2xFX3-L27[SonarQube]!*
11+
*This project is analysed on https://next.sonarqube.com/sonarqube/dashboard?id=sonarsource-cfamily-examples_linux-cmake-compdb-gh-actions-sq_AYCKCTwgbpi2xFX3-L27[SonarQube Server]!*
1212

1313

1414
It is very easy to analyze a C, C++ and Objective-C project with SonarQube using compilation database:
1515

1616
. Create a `sonar-project.properties` file to store your configuration
1717
. In your `.github/workflows/build.yml` file:
1818
.. Set the environment variable `SONAR_HOST_URL` to your server url (e.g.: https://example.com:9000)
19-
.. Download the Sonar Scanner using https://github.com/SonarSource/sonarqube-github-c-cpp[the SonarQube Scan for C and C++ Github Action]
2019
.. Generate the compilation database file (set `CMAKE_EXPORT_COMPILE_COMMANDS` to `ON`)
21-
.. Run `sonar-scanner` with the property `sonar.cfamily.compile-commands` set to your compilation database file
22-
. Ensure that your token is stored as a secret in your repository (`SONARQUBE_TOKEN` in this example project). If you don't have a token yet, you can generate a new one in SonarQube (see https://docs.sonarqube.org/latest/user-guide/user-token/[Generating and Using Tokens]).
20+
.. Run the SonarQube scan using https://github.com/SonarSource/sonarqube-scan-action[the SonarSource/sonarqube-scan-action action] with the property `sonar.cfamily.compile-commands` set to your compilation database file
21+
. Ensure that your token is stored as a secret in your repository (`SONARQUBE_TOKEN` in this example project). If you don't have a token yet, you can generate a new one in SonarQube Server (see https://docs.sonarsource.com/sonarqube-server/latest/user-guide/managing-tokens/[Managing your tokens]).
2322

2423
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.
2524

2625
= Documentation
2726

28-
- https://docs.sonarqube.org/latest/analysis/languages/cfamily/[Documentation overview of the C, C++ and Objective-C analyzer]
29-
- https://docs.sonarqube.org/latest/analysis/github-integration/[GitHub Integration in SonarQube]
30-
- https://docs.sonarqube.org/latest/analyzing-source-code/languages/c-family/prerequisites/#generating-a-compilation-database[Generating a compilation database (compile_commands.json)]
31-
- https://docs.sonarqube.org/latest/analyzing-source-code/languages/c-family/running-the-analysis/[Running the analysis in Compilation Database mode]
27+
- https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/languages/c-family/overview/[C/C++/Objective-C analysis overview]
28+
- https://docs.sonarsource.com/sonarqube-server/latest/devops-platform-integration/github-integration/introduction/[GitHub Integration]
29+
- https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/languages/c-family/prerequisites/#generating-a-compilation-database[Generating a compilation database]
30+
- https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/languages/c-family/running-the-analysis/[Running the CFamily analysis]
3231

3332
= Linux\CMake
3433

@@ -46,7 +45,7 @@ make
4645
An example of a flawed C++ code. The https://github.com/sonarsource-cfamily-examples/code[code repository] is meant to be compiled with different build systems using different CI pipelines on Linux, macOS, and Windows.
4746

4847
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.
49-
The downstream repositories are analyzed either with https://www.sonarqube.org/[SonarQube] or https://sonarcloud.io/[SonarCloud].
48+
The downstream repositories are analyzed either with https://www.sonarsource.com/products/sonarqube/[SonarQube Server] or https://www.sonarsource.com/products/sonarcloud/[SonarQube Cloud].
5049

5150
You can find examples for:
5251

@@ -73,8 +72,8 @@ Running on the following CI services:
7372

7473
Configured for analysis on:
7574

76-
* https://github.com/sonarsource-cfamily-examples?q=-sq[SonarQube]
77-
* https://github.com/sonarsource-cfamily-examples?q=-sc[SonarCloud]
75+
* https://github.com/sonarsource-cfamily-examples?q=-sq[SonarQube Server]
76+
* https://github.com/sonarsource-cfamily-examples?q=-sc[SonarQube Cloud]
7877

7978
You can find also a few examples demonstrating:
8079

0 commit comments

Comments
 (0)