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




commit f104737e0537ff740ff72f8f9fb3d4999cb3da33
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 | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2cb98c926..e0a63c3ef 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.2'
     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 patch diffutils'
     FDO_DISTRIBUTION_EXEC: |
       dnf install -y 'dnf-command(builddep)' &&
       dnf builddep -y tracker tracker-miners --setopt=install_weak_deps=False &&
@@ -172,6 +173,22 @@ 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
+  stage: code-review
+  script:
+    - 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
+  allow_failure: true
+
 .build-template: &build
   stage: build
   script:


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