-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is example workflow to build one app with sonarcloud. Signed-off-by: Kari Hamalainen <[email protected]>
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
name: SonarCloud | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- "docs/**" | ||
pull_request: | ||
paths: | ||
- '**/*.c' | ||
- '**/*.h' | ||
|
||
jobs: | ||
build: | ||
name: Build and analyze | ||
runs-on: ubuntu-22.04 | ||
container: ghcr.io/nrfconnect/sdk-nrf-toolchain:v2.9.0 | ||
defaults: | ||
run: | ||
# Bash shell is needed to set toolchain related environment variables in docker container | ||
# It is a workaround for GitHub Actions limitation https://github.com/actions/runner/issues/1964 | ||
shell: bash | ||
|
||
steps: | ||
- uses: nrfconnect/action-checkout-west-update@main | ||
if: github.event_name == 'pull_request' | ||
with: | ||
git-ref: ${{ github.event.pull_request.head.sha }} | ||
git-fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
path: ncs/nrf | ||
|
||
- uses: nrfconnect/action-checkout-west-update@main | ||
if: github.event_name != 'pull_request' | ||
with: | ||
git-fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
path: ncs/nrf | ||
|
||
- name: Install dependencies | ||
run: | | ||
apt-get update | ||
apt-get install -y curl unzip ruby gcc-multilib make | ||
- name: Install sonar-scanner and build-wrapper | ||
uses: SonarSource/sonarcloud-github-c-cpp@v3 | ||
|
||
- name: Build and test | ||
working-directory: ncs/nrf | ||
run: | | ||
build-wrapper-linux-x86-64 --out-dir build_wrapper_output ../zephyr/scripts/twister \ | ||
--ninja --integration \ | ||
--quarantine-list scripts/quarantine.yaml --quarantine-list scripts/quarantine_integration.yaml \ | ||
-T applications/asset_tracker_v2 | ||
- name: Run sonar-scanner on main | ||
working-directory: ncs/nrf | ||
if: github.event_name != 'pull_request' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
run: | | ||
cat twister-out/coverage/coverage.sonarqube.xml | ||
sonar-scanner \ | ||
--define sonar.cfamily.compile-commands=build_wrapper_output/compile_commands.json \ | ||
--define project.settings=sonar-project.properties \ | ||
--define sonar.inclusions=**/*.c,**/*.h \ | ||
--define sonar.exclusions=tests/,drivers/sensor/*_dummy/ | ||
- name: Run sonar-scanner on PR | ||
working-directory: ncs/nrf | ||
if: github.event_name == 'pull_request' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
PR_BRANCH: ${{ github.event.pull_request.head.ref }} | ||
BASE_REF: ${{ github.event.pull_request.base.ref }} | ||
HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
run: | | ||
sonar-scanner \ | ||
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \ | ||
--define project.settings=sonar-project.properties \ | ||
--define sonar.inclusions=**/*.c,**/*.h \ | ||
--define sonar.exclusions=tests/ \ | ||
--define sonar.scm.revision=${{ env.HEAD_SHA }} \ | ||
--define sonar.pullrequest.key=${{ env.PR_NUMBER }} \ | ||
--define sonar.pullrequest.branch=${{ env.PR_BRANCH }} \ | ||
--define sonar.pullrequest.base=${{ env.BASE_REF }} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sonar.projectKey=nrfconnect-sdk-nrf | ||
sonar.organization=nrfconnect | ||
|