[tracker/wip/carlosg/code-style-checks] ci: Check code style in merge request changes




commit 48747780e0e47fcbc008294c52b4262cce26c6c7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jun 13 20:58:20 2021 +0200

    ci: Check code style in merge request changes
    
    Use the new check-style script to check the code style for all
    changes in a merge request, in order to suggest changes to conform
    to it.
    
    However, allow these checks to fail, so they are more of a hint
    while the uncrustify configuration is tested to be correct, we
    decide to enforce the style, etc.
    
    As the script requires uncrustify, ensure it's installed in the
    Fedora image, and use it to run the check.

 .gitlab-ci.yml | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2cb98c926..cf5b64710 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -16,6 +16,7 @@ variables:
 stages:
   - review
   - prepare
+  - code-review
   - build
   - test
   - analysis
@@ -59,9 +60,9 @@ check-merge-request:
 
 .tracker.fedora@common:
   variables:
-    BASE_TAG: '2021-05-15.9'
+    BASE_TAG: '2021-06-13.1'
     FDO_UPSTREAM_REPO: GNOME/tracker
-    FDO_DISTRIBUTION_PACKAGES: 'clang clang-analyzer gcovr git libasan libubsan python3-gobject python3-pip 
umockdev-devel xmlto'
+    FDO_DISTRIBUTION_PACKAGES: 'clang clang-analyzer gcovr git libasan libubsan python3-gobject python3-pip 
umockdev-devel xmlto uncrustify'
     FDO_DISTRIBUTION_EXEC: |
       dnf install -y 'dnf-command(builddep)' &&
       dnf builddep -y tracker tracker-miners --setopt=install_weak_deps=False &&
@@ -172,6 +173,29 @@ build-alpine-container@x86_64:
     - check-commit-log
     - check-merge-request
 
+check-code-style:
+  extends:
+    - .fdo.distribution-image@fedora
+    - .tracker.fedora:34@x86_64
+  needs:
+    - build-fedora-container@x86_64
+  variables:
+    GIT_DEPTH: "100"
+  stage: code-review
+  script:
+    - if [[ x"$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" != "x" ]] ;
+      then
+        export common_parent_sha=$(diff --old-line-format='' --new-line-format='' <(git rev-list 
--first-parent "${ORIGIN}/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}") <(git rev-list 
--first-parent HEAD) | head -1)
+        ./check-style.py --sha $common_parent_sha;
+        if [ $? -ne 0 ];
+        then
+          echo -e "Issue the following command in your local tree to apply the suggested changes (needs 
uncrustify installed):\n\n $ git rebase 
"${ORIGIN}/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-${CI_DEFAULT_BRANCH}}" --exec \"./check-style.py -r\" \n"
+        fi
+      else
+        echo "Not a merge request" ;
+      fi
+  allow_failure: true
+
 .build-template: &build
   stage: build
   script:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]