Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add sonarcloud example #19934

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/sonarcloud_demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: SonarCloud
on:
push:
branches:
- main
paths:
- 'applications/asset_tracker_v2/**/*.c'
- 'applications/asset_tracker_v2/**/*.h'
pull_request:
paths:
- 'applications/asset_tracker_v2/**/*.c'
- 'applications/asset_tracker_v2/**/*.h'
- '.github/workflows/sonarcloud_demo.yml'

jobs:
build:
name: Build and analyze
runs-on: ubuntu-22.04
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ubuntu-latest? GH switched to 24.04 last week.

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 }}
thst-nordic marked this conversation as resolved.
Show resolved Hide resolved
run: |
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.compile-commands=build_wrapper_output/compile_commands.json \
--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 }}

Check warning on line 89 in .github/workflows/sonarcloud_demo.yml

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

YAMLLint (empty-lines)

.github/workflows/sonarcloud_demo.yml:89 too many blank lines (1 > 0)
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/VERSION @nrfconnect/ncs-code-owners
/west.yml @nrfconnect/ncs-code-owners
/west-test.yml @nrfconnect/ncs-ci
/sonar-project.properties @nrfconnect/ncs-ci

# Dot folders
/.github/ @nrfconnect/ncs-ci
Expand Down
3 changes: 3 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sonar.projectKey=nrfconnect_sdk-nrf
sonar.organization=nrfconnect

Loading