Parcourir la source

Merge branch 'ci/sonarqube_improvement' into 'master'

CI: Sonarqube: CI_MERGE_REQUEST_IID

See merge request espressif/esp-idf!10218
Anton Maklakov il y a 5 ans
Parent
commit
587f97ab15
2 fichiers modifiés avec 35 ajouts et 0 suppressions
  1. 31 0
      tools/ci/ci_get_latest_mr_iid.py
  2. 4 0
      tools/ci/config/build.yml

+ 31 - 0
tools/ci/ci_get_latest_mr_iid.py

@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+#
+# internal use only for CI
+# get latest MR IID by source branch
+
+import argparse
+import os
+
+from gitlab_api import Gitlab
+
+
+def get_MR_IID_by_source_branch(source_branch):
+    if not source_branch:
+        return ''
+    gl = Gitlab(os.getenv('CI_PROJECT_ID'))
+    if not gl.project:
+        return ''
+    mrs = gl.project.mergerequests.list(state='opened', source_branch=source_branch)
+    if mrs:
+        mr = mrs[0]  # one source branch can only have one opened MR at one moment
+        return mr.iid
+    return ''
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description='Get the latest MR IID by source branch, if not found, return empty string')
+    parser.add_argument('source_branch', nargs='?', help='source_branch')  # won't fail if it's empty
+
+    args = parser.parse_args()
+
+    print(get_MR_IID_by_source_branch(args.source_branch))

+ 4 - 0
tools/ci/config/build.yml

@@ -447,7 +447,11 @@ code_quality_check:
     - clang_tidy_check_regular
   only:
     - triggers
+  allow_failure: true
   script:
+    - export CI_MERGE_REQUEST_IID=`python ${CI_PROJECT_DIR}/tools/ci/ci_get_latest_mr_iid.py ${CI_COMMIT_BRANCH} | xargs`
+    # test if this branch have merge request, if not, exit 0
+    - test -n "$CI_MERGE_REQUEST_IID" || exit 0
     - sonar-scanner
       -Dsonar.analysis.mode=preview
       -Dsonar.host.url=$SONAR_HOST_URL