Jelajahi Sumber

Merge branch 'fix/sonarqube_exclude_submodule_error' into 'master'

Fix: sonarqube exclude submodule error

Closes IDFCI-863

See merge request espressif/esp-idf!15043
Anton Maklakov 4 tahun lalu
induk
melakukan
be0c42cf9f

+ 11 - 0
.gitlab/ci/static-code-analysis.yml

@@ -67,6 +67,14 @@ check_pylint:
     - source tools/ci/utils.sh
     - export PYTHONPATH="$CI_PROJECT_DIR/tools:$CI_PROJECT_DIR/tools/ci/python_packages:$PYTHONPATH"
     - fetch_submodules
+    # Exclude the submodules, all paths ends with /**
+    - submodules=$(get_all_submodules)
+    # get all exclude paths specified in tools/ci/sonar_exclude_list.txt | ignore lines start with # | xargs | replace all <space> to <comma>
+    - custom_excludes=$(cat $CI_PROJECT_DIR/tools/ci/sonar_exclude_list.txt | grep -v '^#' | xargs | sed -e 's/ /,/g')
+    # Exclude the report dir as well
+    - export EXCLUSIONS="$custom_excludes,$submodules"
+    - export SONAR_SCANNER_OPTS="-Xmx2048m"
+
   variables:
     GIT_DEPTH: 0
     REPORT_PATTERN: clang_tidy_reports/*.txt
@@ -95,8 +103,10 @@ code_quality_check:
       -Dsonar.analysis.mode=preview
       -Dsonar.branch.name=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
       -Dsonar.cxx.clangtidy.reportPath=$REPORT_PATTERN
+      -Dsonar.exclusions=$EXCLUSIONS
       -Dsonar.gitlab.ci_merge_request_iid=$CI_MERGE_REQUEST_IID
       -Dsonar.gitlab.commit_sha=$CI_MERGE_REQUEST_COMMITS
+      -Dsonar.gitlab.merge_request_discussion=true
       -Dsonar.gitlab.ref_name=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
       -Dsonar.host.url=$SONAR_HOST_URL
       -Dsonar.login=$SONAR_LOGIN
@@ -112,6 +122,7 @@ code_quality_report:
     - sonar-scanner
       -Dsonar.branch.name=$CI_COMMIT_REF_NAME
       -Dsonar.cxx.clangtidy.reportPath=$REPORT_PATTERN
+      -Dsonar.exclusions=$EXCLUSIONS
       -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA
       -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
       -Dsonar.host.url=$SONAR_HOST_URL

+ 0 - 11
sonar-project.properties

@@ -5,16 +5,6 @@ sonar.projectVersion=4.4
 sonar.sources=.
 sonar.sourceEncoding=UTF-8
 
-# exclude list for sonarqube
-# Here're some examples: (relative with the idf_path)
-# test/**/*
-# test/*/*.c
-sonar.exclusion=\
-  components/freertos/*.c,\
-  components/freertos/include/freertos/*.h,\
-  components/wpa_supplicant/src/**/*,\
-  components/wpa_supplicant/include/**/*
-
 sonar.inclusions=\
   **/*.c,**/*.cpp,**/*.h,**/*.hpp,\
   **/*.py
@@ -33,5 +23,4 @@ sonar.cxx.file.suffixes=.cxx,.cpp,.cc,.c,.hxx,.hpp,.hh,.h
 #######################
 
 sonar.gitlab.failure_notification_mode=exit-code
-sonar.gitlab.merge_request_discussion=true
 sonar.gitlab.project_id=103

+ 15 - 0
tools/ci/sonar_exclude_list.txt

@@ -0,0 +1,15 @@
+# exclude list for sonarqube
+# Here're some examples: (relative with the idf_path)
+# test/**
+# test/*/*.c
+# test.c
+#
+# lines start with # will be ignored
+
+# FreeRTOS upstream code (don't include our port files here)
+components/freertos/*.c
+components/freertos/include/freertos/*.h
+
+# wpa_supplicant upstream code
+components/wpa_supplicant/src/**
+components/wpa_supplicant/include/**