Skip to content

Commit 14804a4

Browse files
committed
chore: Fix sonar-scan CI action.
1 parent e2db7d9 commit 14804a4

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

.github/scripts/sonar-prepare

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_ld_flag -Wl,-z,defs
1717
add_flag -Werror
1818

1919
cmake -B_build -H. -GNinja \
20+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
2021
-DCMAKE_C_FLAGS="$C_FLAGS" \
2122
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
2223
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \

.github/workflows/sonar-scan.yml

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,34 @@ on:
88

99
# Cancel old PR builds when pushing new commits.
1010
concurrency:
11-
group: scan-${{ github.event.pull_request.number || github.ref }}
11+
group: sonar-scan-${{ github.event.pull_request.number || github.ref }}
1212
cancel-in-progress: true
1313

1414
jobs:
1515
sonar-scan:
1616
runs-on: ubuntu-latest
1717
env:
18-
SONAR_SCANNER_VERSION: 5.0.1.3006
19-
SONAR_SERVER_URL: "https://sonarcloud.io"
2018
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
2119
steps:
2220
- uses: actions/checkout@v4
2321
with:
2422
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
2523
submodules: recursive
26-
- name: Set up JDK 17
27-
uses: actions/setup-java@v2
28-
with:
29-
distribution: "zulu"
30-
java-version: 17
31-
- name: Download and set up sonar-scanner
32-
env:
33-
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
34-
run: |
35-
mkdir -p $HOME/.sonar
36-
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
37-
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
38-
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH
39-
- name: Download and set up build-wrapper
40-
env:
41-
BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip
42-
run: |
43-
curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }}
44-
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
45-
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
24+
- name: Install Build Wrapper
25+
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v6
4626
- name: Install dependencies and prepare build
4727
run: |
4828
.github/scripts/sonar-prepare
49-
- name: Run build-wrapper
29+
- name: Run Build Wrapper
5030
run: |
5131
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} .github/scripts/sonar-build
52-
- name: Run sonar-scanner
32+
- name: Ensure compile_commands.json is generated
33+
run: ls -l "${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
34+
- name: SonarQube Scan
5335
if: github.event_name == 'push'
36+
uses: SonarSource/sonarqube-scan-action@v6
5437
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5638
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
57-
run: 'sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"'
39+
with:
40+
args: >
41+
--define "sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"

0 commit comments

Comments
 (0)