static-code-analysis.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # pre_check stage
  2. clang_tidy_check:
  3. extends:
  4. - .pre_check_base_template
  5. - .rules:patterns:clang_tidy
  6. image: ${CI_DOCKER_REGISTRY}/clang-static-analysis
  7. artifacts:
  8. reports:
  9. junit: $IDF_PATH/output.xml
  10. when: always
  11. paths:
  12. - $IDF_PATH/examples/get-started/hello_world/tidybuild/report/*
  13. expire_in: 1 day
  14. script:
  15. - retry_failed git clone $IDF_ANALYSIS_UTILS static_analysis_utils && cd static_analysis_utils
  16. # Setup parameters of triggered/regular job
  17. - export TARGET_BRANCH=${BOT_CUSTOMIZED_REVISION-}
  18. - ./analyze.sh $IDF_PATH/examples/get-started/hello_world/ $IDF_PATH/tools/ci/static-analysis-rules.yml $IDF_PATH/output.xml
  19. # build stage
  20. # Sonarqube related jobs put here for this reason:
  21. # Here we have two jobs. code_quality_check and code_quality_report.
  22. #
  23. # code_quality_check will analyze the code changes between your MR and
  24. # code repo stored in sonarqube server. The analysis result is only shown in
  25. # the comments under this MR and won't be transferred to the server.
  26. #
  27. # code_quality_report will analyze and transfer both of the newly added code
  28. # and the analysis result to the server.
  29. #
  30. # Put in the front to ensure that the newly merged code can be stored in
  31. # sonarqube server ASAP, in order to avoid reporting unrelated code issues
  32. .sonar_scan_template:
  33. stage: build
  34. image:
  35. name: $CI_DOCKER_REGISTRY/sonarqube-scanner:2
  36. before_script:
  37. - source tools/ci/utils.sh
  38. - export PYTHONPATH="$CI_PROJECT_DIR/tools:$CI_PROJECT_DIR/tools/ci/python_packages:$PYTHONPATH"
  39. - fetch_submodules
  40. # Exclude the submodules, all paths ends with /**
  41. - export SUBMODULES=$(get_all_submodules)
  42. # get all exclude paths specified in tools/ci/sonar_exclude_list.txt | ignore lines start with # | xargs | replace all <space> to <comma>
  43. - export CUSTOM_EXCLUDES=$(cat $CI_PROJECT_DIR/tools/ci/sonar_exclude_list.txt | grep -v '^#' | xargs | sed -e 's/ /,/g')
  44. # Exclude the report dir
  45. - export EXCLUSIONS="$SUBMODULES,$REPORT_DIR/**,docs/_static/**,**/*.png,**/*.jpg"
  46. - python $NORMALIZE_CLANGTIDY_PY $CI_PROJECT_DIR/$REPORT_DIR/warnings.txt $CI_PROJECT_DIR/$REPORT_DIR/clang_tidy_report.txt $CI_PROJECT_DIR
  47. variables:
  48. GIT_DEPTH: 0
  49. NORMALIZE_CLANGTIDY_PY: $CI_PROJECT_DIR/tools/ci/normalize_clangtidy_path.py
  50. REPORT_DIR: examples/get-started/hello_world/tidybuild/report
  51. tags:
  52. - host_test
  53. dependencies: # Here is not a hard dependency relationship, could be skipped when only python files changed. so we do not use "needs" here.
  54. - clang_tidy_check
  55. code_quality_check:
  56. extends:
  57. - .sonar_scan_template
  58. - .rules:patterns:static-code-analysis-preview
  59. allow_failure: true # since now it's using exit code to indicate the code analysis result,
  60. # we don't want to block ci when critical issues founded
  61. script:
  62. - export CI_MERGE_REQUEST_COMMITS=$(python ${CI_PROJECT_DIR}/tools/ci/ci_get_mr_info.py commits ${CI_COMMIT_REF_NAME} | tr '\n' ',')
  63. # test if this branch have merge request, if not, exit 0
  64. - test -n "$CI_MERGE_REQUEST_IID" || exit 0
  65. - test -n "$CI_MERGE_REQUEST_COMMITS" || exit 0
  66. - sonar-scanner
  67. -Dsonar.analysis.mode=preview
  68. -Dsonar.branch.name=$CI_COMMIT_REF_NAME
  69. -Dsonar.cxx.clangtidy.reportPath=$REPORT_DIR/clang_tidy_report.txt
  70. -Dsonar.cxx.includeDirectories=components,/usr/include
  71. -Dsonar.exclusions=$EXCLUSIONS
  72. -Dsonar.gitlab.ci_merge_request_iid=$CI_MERGE_REQUEST_IID
  73. -Dsonar.gitlab.commit_sha=$CI_MERGE_REQUEST_COMMITS
  74. -Dsonar.gitlab.failure_notification_mode=exit-code
  75. -Dsonar.gitlab.merge_request_discussion=true
  76. -Dsonar.gitlab.project_id=$CI_PROJECT_ID
  77. -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
  78. -Dsonar.host.url=$SONAR_HOST_URL
  79. -Dsonar.login=$SONAR_LOGIN
  80. -Dsonar.projectBaseDir=$CI_PROJECT_DIR
  81. -Dsonar.projectKey=esp-idf
  82. -Dsonar.python.pylint_config=.pylintrc
  83. -Dsonar.sourceEncoding=UTF-8
  84. -Dsonar.sources=$CI_PROJECT_DIR
  85. code_quality_report:
  86. extends:
  87. - .sonar_scan_template
  88. - .rules:protected
  89. allow_failure: true # since now it's using exit code to indicate the code analysis result,
  90. # we don't want to block ci when critical issues founded
  91. script:
  92. - sonar-scanner
  93. -Dsonar.branch.name=$CI_COMMIT_REF_NAME
  94. -Dsonar.cxx.clangtidy.reportPath=$REPORT_DIR/clang_tidy_report.txt
  95. -Dsonar.cxx.includeDirectories=components,/usr/include
  96. -Dsonar.exclusions=$EXCLUSIONS
  97. -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA
  98. -Dsonar.gitlab.failure_notification_mode=exit-code
  99. -Dsonar.gitlab.project_id=$CI_PROJECT_ID
  100. -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
  101. -Dsonar.host.url=$SONAR_HOST_URL
  102. -Dsonar.login=$SONAR_LOGIN
  103. -Dsonar.projectBaseDir=$CI_PROJECT_DIR
  104. -Dsonar.projectKey=esp-idf
  105. -Dsonar.python.pylint_config=.pylintrc
  106. -Dsonar.sourceEncoding=UTF-8
  107. -Dsonar.sources=$CI_PROJECT_DIR
  108. # deploy stage
  109. clang_tidy_deploy:
  110. extends:
  111. - .deploy_job_template
  112. - .rules:patterns:clang_tidy
  113. dependencies: # set dependencies to null to avoid missing artifacts issue
  114. needs:
  115. - clang_tidy_check
  116. tags:
  117. - deploy
  118. - shiny
  119. script:
  120. - add_doc_server_ssh_keys $DOCS_DEPLOY_KEY $DOCS_SERVER $DOCS_SERVER_USER
  121. - export GIT_VER=$(git describe --always)
  122. - cd $IDF_PATH/examples/get-started/hello_world/tidybuild
  123. - mv report $GIT_VER
  124. - tar czvf $GIT_VER.tar.gz $GIT_VER
  125. - export STATIC_REPORT_PATH="web/static_analysis/esp-idf/"
  126. - ssh $DOCS_SERVER -x "mkdir -p $STATIC_REPORT_PATH/clang-tidy"
  127. - scp $GIT_VER.tar.gz $DOCS_SERVER:$STATIC_REPORT_PATH/clang-tidy
  128. - ssh $DOCS_SERVER -x "cd $STATIC_REPORT_PATH/clang-tidy && tar xzvf $GIT_VER.tar.gz && rm -f latest && ln -s $GIT_VER latest"
  129. # add link to view the report
  130. - echo "[static analysis][clang tidy] $CI_DOCKER_REGISTRY/static_analysis/esp-idf/clang-tidy/${GIT_VER}/index.html"
  131. - test ! -e ${GIT_VER}/FAILED_RULES || { echo 'Failed static analysis rules!'; cat ${GIT_VER}/FAILED_RULES; exit 1; }