Skip to content

Commit bd5477a

Browse files
committed
sonar: sonar
sonar Signed-off-by: Simen S. Røstad <[email protected]>
1 parent 678cbd5 commit bd5477a

File tree

2 files changed

+13
-42
lines changed

2 files changed

+13
-42
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Sonarcloud and Twister Native Sim
1+
name: SonarQube and Twister Native Sim
22
on:
33
push:
44
branches:
@@ -20,7 +20,6 @@ jobs:
2020
runs-on: build_self_hosted
2121
container: ghcr.io/zephyrproject-rtos/ci:v0.27.4
2222
env:
23-
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
2423
CMAKE_PREFIX_PATH: /opt/toolchains
2524
steps:
2625
- uses: actions/checkout@v4
@@ -58,56 +57,24 @@ jobs:
5857
apt-get update
5958
apt install -y curl ruby-full
6059
61-
- name: Run tests with ASAN, no Sonarcloud and build_wrapper
60+
- name: Run tests with ASAN
6261
working-directory: asset-tracker-template
6362
run: |
6463
west twister -T tests/ --enable-coverage --coverage-platform=native_sim -v --inline-logs --integration --enable-asan --enable-lsan --enable-ubsan
6564
66-
- name: Install sonar-scanner and build-wrapper
67-
uses: SonarSource/sonarcloud-github-c-cpp@v3
68-
69-
- name: Build and test
65+
- name: Build and test with coverage
7066
working-directory: asset-tracker-template
7167
run: |
72-
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} west twister -T tests/ --enable-coverage --coverage-platform=native_sim -v --inline-logs --integration
68+
west twister -T tests/ --enable-coverage --coverage-platform=native_sim -v --inline-logs --integration
7369
7470
- name: Extract coverage into sonarqube xml format
7571
working-directory: asset-tracker-template
7672
run: |
7773
gcovr twister-out -v --merge-mode-functions=separate --exclude='twister-out|drivers' --sonarqube coverage.xml
7874
79-
- name: Run sonar-scanner on main
80-
working-directory: asset-tracker-template
81-
if: github.event_name != 'pull_request'
82-
env:
83-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
85-
run: |
86-
sonar-scanner \
87-
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
88-
--define project.settings=sonar-project.properties \
89-
--define sonar.coverageReportPaths=coverage.xml \
90-
--define sonar.inclusions=**/*.c,**/*.h \
91-
--define sonar.exclusions=tests/,drivers/sensor/*_dummy/
92-
93-
- name: Run sonar-scanner on PR
94-
working-directory: asset-tracker-template
95-
if: github.event_name == 'pull_request'
75+
- name: SonarCloud Scan
76+
uses: SonarSource/sonarcloud-github-action@v3
77+
with:
78+
projectBaseDir: asset-tracker-template
9679
env:
97-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9880
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
99-
PR_NUMBER: ${{ github.event.pull_request.number }}
100-
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
101-
BASE_REF: ${{ github.event.pull_request.base.ref }}
102-
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
103-
run: |
104-
sonar-scanner \
105-
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
106-
--define project.settings=sonar-project.properties \
107-
--define sonar.coverageReportPaths=coverage.xml \
108-
--define sonar.inclusions=**/*.c,**/*.h \
109-
--define sonar.exclusions=tests/,drivers/sensor/*_dummy/ \
110-
--define sonar.scm.revision=${{ env.HEAD_SHA }} \
111-
--define sonar.pullrequest.key=${{ env.PR_NUMBER }} \
112-
--define sonar.pullrequest.branch=${{ env.PR_BRANCH }} \
113-
--define sonar.pullrequest.base=${{ env.BASE_REF }}

sonar-project.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
sonar.projectKey=nrfconnect_Asset-Tracker-Template
22
sonar.organization=nrfconnect
3-
sonar.host.url=https://sonarcloud.io
3+
4+
# Coverage and analysis settings
5+
sonar.coverageReportPaths=coverage.xml
6+
sonar.inclusions=**/*.c,**/*.h
7+
sonar.exclusions=tests/,drivers/sensor/*_dummy/

0 commit comments

Comments
 (0)