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

Use cmake only for sonarcloud #13771

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5678bc3
workflow: Add workflow that rebases from ncs/main and creates a PR
Nov 30, 2022
aa34339
workflow: Add sonarcloud workflow
Nov 28, 2022
8bc927a
workflow: sonarcloud: Add code coverage option
Dec 8, 2022
52b012d
workflow: sonarcloud: Fix code coverage report generation for atv2
Dec 9, 2022
258a9d0
workflow: rebase_to_ncs_main work flow will now create draft PRs
Dec 14, 2022
71da2b4
workflow: sonarcloud: Run all native_posix tests in sdk-nrf repo
Dec 14, 2022
db9908c
workflow: sonarcloud: Exclude modules
Jan 14, 2023
a30c426
workflow: Expand the scope of sonarcloud to include integration tests
Jan 18, 2023
271891e
workflow: sonarcloud: Exclude zephyr folder
Jan 25, 2023
bedd1e7
workflow: sonarcloud: Remove native_posix tests and code cov
Jan 25, 2023
3c1a5e2
workflow: Revert "workflow: sonarcloud: Remove native_posix tests"
Jan 26, 2023
68f7373
workflow: sonarcloud: Enable -X when calling sonarscanner
Jan 26, 2023
6099f16
workflow: sonarcloud: Ignore vsdx files
Jan 26, 2023
f1aeae4
workflow: sonarcloud: Clobber output when running unit tests
Jan 26, 2023
173743c
workflow: sonarcloud: Invoke twister with -i
Jan 26, 2023
ad630cd
workflow: Trigger sonarcloud only on native_posix tests on PR
Feb 1, 2023
cbc06d5
workflow: sonarcloud-pr: Add quarantine-list parameter
Feb 3, 2023
0feb8c3
workflow: Run native_posix build also on main
Feb 6, 2023
5e39acd
workflow: Rename sonarcloud-pr to sonarcloud-native-posix
Feb 6, 2023
54e3bcd
workflow: Do not include quarentined tests
Feb 8, 2023
225da34
workflow: Dont run native_posix analysis on push to main
Feb 10, 2023
f5ed5e6
workflow: Exclude zephyr from code coverage collection
Feb 13, 2023
6fd760d
workflow: Make gcov output verbose output
Feb 13, 2023
a5f3fde
coverage: add sockets_tls.c to ignore list
Feb 13, 2023
6f31b4e
workflow: Move common parts of sonarcloud and sonarcloud-native-posix
Mar 7, 2023
607c6be
workflow: Add chatgpt review workflow
Mar 23, 2023
9af09be
workflow: Include python code in the sonarcloud analysis
Mar 24, 2023
d21c273
workflow: Create separate quarentine file for downsream
Mar 28, 2023
5c9c19a
workflow: Create codeql.yml for security analysis of c and python code
Mar 27, 2023
ee66556
quarentine_downstream: Remove mesh test from quarentine
Mar 30, 2023
72b3337
workflows: Make codeql run every day at 12am
Mar 30, 2023
5f1bc4d
workflows: Remove chatgpt review workflow
May 3, 2023
dfe9b4b
quarentine: Remove a test and add another
May 5, 2023
fe6cae3
workflow: Allow sonarcloud-native-posix to run on PRs from forks
May 12, 2023
6b8d05a
workflow: Run sonarcloud-native_posix also on push to main
May 12, 2023
c00d760
workflow: sonarcloud: Fix sonarcloud run on PRs from fork
May 15, 2023
fd4f2f9
workflows: sonarcloud: Ignore test run failure on PRs.
May 15, 2023
256299d
fixup: download sonar-project props and quarentine
May 15, 2023
ab20b91
workflow: Remove gcc-multilib installation
Jun 5, 2023
cddae38
workflow: Use sonarcloud-github-c-cpp action
Jun 22, 2023
edc0d5a
Workflow: sonarcloud: Remove unused env variables
Jun 27, 2023
e4205d5
Workflow: Use zephyr's official docker image
Aug 16, 2023
b5b80ff
workflow: Add clang-tidy review workflow
Aug 16, 2023
805b6e9
deps: Install latest zcbor
Sep 14, 2023
fec5384
workflows: Bump sonarcloud version to 2.0.2.
Jan 25, 2024
2608eab
Workflow: Sonarcloud: Remove running of native_posix tests
Jan 26, 2024
c6d6f93
workflow: Remove zcbor install step
Jan 26, 2024
dbd6450
workflow: sonarcloud: Remove board-root when invoking twister
Jan 26, 2024
9fd69b9
workflow: sonarcloud: Optimize sonarcloud scan speed
Jan 26, 2024
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
110 changes: 110 additions & 0 deletions .github/workflows/clang-tidy-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Clang-tidy review
on:
pull_request:

jobs:
build:
name: Clang tidy review
runs-on: ubuntu-latest
container: zephyrprojectrtos/ci-base:v0.26.4
env:
CMAKE_PREFIX_PATH: /opt/toolchains
steps:
- name: Checkout the code
uses: actions/checkout@v2
with:
path: nrf
fetch-depth: 0

- name: Install deps
run: |
apt-get update
apt-get install -y jq clang clang-tidy ruby-full

- name: West init and update
working-directory: nrf
run: |
west init -l .
west update --narrow -o=--depth=1

- name: Build for native_posix
shell: bash
working-directory: nrf
continue-on-error: true # The llvm build fails with a non-zero exit code due to link stage error. But we still want to run clang-tidy. The clang-tidy will catch compile errors anyway. The point here is to get the compile_commands.json file and all the necessary headerfiles generated with clang as the compiler.
run: |
export ZEPHYR_TOOLCHAIN_VARIANT=llvm
../zephyr/scripts/twister -b -v -i -T ./ -p native_posix --quarantine-list scripts/quarantine_downstream.yaml

- name: Use jq to combine compile_commands.json files
shell: bash
working-directory: nrf
run: |
jq -s 'map(.[])' `find . -name compile_commands.json` > compile_commands.json

- name: Analyze
shell: bash
working-directory: nrf
run: |
mkdir clang-tidy-result
git fetch origin ${{ github.event.pull_request.base.sha }}
git diff -U0 ${{ github.event.pull_request.base.sha }} | clang-tidy-diff -p1 -path . -export-fixes clang-tidy-result/fixes.yml

- name: Print clang tidy results (yml format))
shell: bash
working-directory: nrf
run: |
ls clang-tidy-result
cat clang-tidy-result/fixes.yml

- name: Strip docker path so that the publisher workflow can find the files without being in a container
shell: bash
working-directory: nrf
run: |
sed -i "s/\/__w\/sdk-nrf\/sdk-nrf\/nrf\///g" clang-tidy-result/fixes.yml

- name: Upload clang tidy result as artifact
uses: actions/upload-artifact@v2
with:
name: clang-tidy-result
path: nrf/clang-tidy-result

- name: Upload compile_commands.json as artifact
uses: actions/upload-artifact@v2
with:
name: compile_commands.json
path: nrf/compile_commands.json

publish-review:
name: Publish clang tidy review
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout the code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: clang-tidy-result
path: clang-tidy-result

- name: Debug
shell: bash
run: |
ls clang-tidy-result
cat clang-tidy-result/fixes.yml

- name: Run clang-tidy-pr-comments action
uses: platisd/clang-tidy-pr-comments@master
with:
# The GitHub token (or a personal access token)
github_token: ${{ secrets.GITHUB_TOKEN }}
# The path to the clang-tidy fixes generated previously
clang_tidy_fixes: clang-tidy-result/fixes.yml
# Optionally set the number of comments per review
# to avoid GitHub API timeouts for heavily loaded
# pull requests
suggestions_per_comment: 10

65 changes: 65 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
paths-ignore:
- '**/*.md'
- '**/*.rst'
- '**/*.txt'
schedule:
- cron: '0 0 * * *'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
container: nordicplayground/nrfconnect-sdk:main
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout the code
uses: actions/checkout@v2
with:
path: ncs/nrf
fetch-depth: 0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: 'c'

# Install more dependencies that are not part of the docker image but are needed by the workflow
- name: Install more deps
shell: bash
run: |
apt install -y gcc-multilib

# The docker image comes pre-initialized with west dependencies. We want to do west update ourselves to to be sure that we get the latest changes in all repos.
# The docker image is built nightly. So it may contain slightly out of date repos.
# Hence we remove the .west folder and do a re-init
- name: West init and update
shell: bash
run: |
rm -rf /workdir/.west/
west init -l ncs/nrf
cd ncs
west update --narrow -o=--depth=1

- name: Build with twister
shell: bash
run: |
source ncs/zephyr/zephyr-env.sh
echo "Run, Build Application using script"
ncs/zephyr/scripts/twister -b -v -i -T ncs/nrf/ -p native_posix --quarantine-list ncs/nrf/scripts/quarantine_downstream.yaml

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:c"
43 changes: 43 additions & 0 deletions .github/workflows/rebase_to_ncs_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Rebase from ncs main

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:


jobs:
update:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Rebase from main
run: |
git config --global user.email "[email protected]"
git config --global user.name "github-actions[bot]"
git remote add ncs https://github.com/nrfconnect/sdk-nrf
git fetch ncs
git rev-parse HEAD
git rebase --verbose ncs/main

- name: Check if changes were made
run: |
if [[ `git diff origin/main --exit-code` ]]; then
echo "HAS_CHANGES=1" >> $GITHUB_ENV
else
echo "HAS_CHANGES=0" >> $GITHUB_ENV
fi

- name: Create Pull Request
if: env.HAS_CHANGES == '1'
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PR_CREATOR_TOKEN }} # Personal access token of balaji-nordic with contents:write and pull requestes:write permission
title: 'Updates from upstream ncs'
assignees: balaji-nordic
reviewers: balaji-nordic
draft: true
116 changes: 116 additions & 0 deletions .github/workflows/sonarcloud-native-posix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Sonarcloud analysis (native_posix only)
on:
push:
branches:
- main
pull_request_target:

jobs:
build:
name: Sonar cloud analysis
runs-on: ubuntu-latest
container: zephyrprojectrtos/ci:v0.26.4
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
CMAKE_PREFIX_PATH: /opt/toolchains
steps:
- name: Checkout the code
uses: actions/checkout@v2
if: github.event_name == 'pull_request_target'
with:
ref: ${{ github.event.pull_request.head.sha }} # Checkout the PR's head sha instead of the target branch's sha
path: ncs/nrf
fetch-depth: 0

- name: Checkout the code
uses: actions/checkout@v2
if: github.event_name != 'pull_request_target'
with:
path: ncs/nrf
fetch-depth: 0

# Install more dependencies that are not part of the docker image but are needed by the workflow
- name: Install more deps
run: |
apt-get update
apt install -y lcov curl ruby-full
pip3 install zcbor

- name: Install sonar-scanner and build-wrapper
uses: sonarsource/[email protected]

# The docker image comes pre-initialized with west dependencies. We want to do west update ourselves to to be sure that we get the latest changes in all repos.
# The docker image is built nightly. So it may contain slightly out of date repos.
# Hence we remove the .west folder and do a re-init
- name: West init and update
run: |
rm -rf /workdir/.west/
west init -l ncs/nrf
cd ncs
west update --narrow -o=--depth=1

# Download the quarantine file base branch. This is needed to build and run the tests.
- name: Download quarentine file from nrf (PR only)
if: github.event_name == 'pull_request_target'
run: |
wget https://raw.githubusercontent.com/balaji-nordic/sdk-nrf/master/scripts/quarantine_downstream.yaml -P ncs/nrf/scripts/

- name: Build native_posix tests with coverage enabled (via sonarcloud build wrapper)
shell: bash
run: |
source ncs/zephyr/zephyr-env.sh
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} ncs/zephyr/scripts/twister -b -C -v -i -T ncs/nrf/ -p native_posix --quarantine-list ncs/nrf/scripts/quarantine_downstream.yaml --coverage-tool gcovr

- name: Run native_posix tests
shell: bash
run: |
source ncs/zephyr/zephyr-env.sh
ncs/zephyr/scripts/twister --test-only -v -i -C -T ncs/nrf/ -p native_posix

# Exclude twister-out because we dont need coverage reports for mocks and generated files.
# Exclude tests/unity because it is not interesting
# Exclude folders that contain source code with multiple definitions of the same function
# depending on preprocessor macros. gcovr misbehaves due to this.
# Issue: https://github.com/gcovr/gcovr/issues/586
- name: Collect coverage into one XML report
shell: bash
run: |
gcovr twister-out -v \
--exclude=twister-out \
--exclude=tests/unity \
--exclude=ncs/nrf/tests/subsys/dfu/dfu_target_stream/src/main.c \
--exclude=ncs/zephyr/subsys/net/ip \
--exclude=ncs/nrf/lib/hw_id/hw_id.c \
--exclude=ncs/zephyr/subsys/net/lib/sockets/sockets_tls.c \
--sonarqube coverage.xml

- name: Run sonar-scanner on main
if: github.event_name != 'pull_request_target'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner -X \
--define project.settings=ncs/nrf/sonar-project.properties \
--define sonar.coverageReportPaths=coverage.xml \
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"

- name: Run sonar-scanner on PR
if: github.event_name == 'pull_request_target'
env:
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 }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
wget https://raw.githubusercontent.com/balaji-nordic/sdk-nrf/main/sonar-project.properties -P ncs/nrf
sonar-scanner -X \
--define project.settings=ncs/nrf/sonar-project.properties \
--define sonar.coverageReportPaths=coverage.xml \
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
--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 }}
Loading
Loading