[gtranslator/add-clang-format-ci] Add check stage to CI with code style




commit 1d341f4125cfaffde0e9a32a27b6b0d7dc739976
Author: Daniel GarcĂ­a Moreno <dani danigm net>
Date:   Thu Jun 2 18:28:59 2022 +0200

    Add check stage to CI with code style
    
    Checks the code style using the clang-format-diff tool to unify the
    coding style to the GNU C coding style.

 .gitlab-ci.yml              | 15 +++++++++++++++
 scripts/check-diff-style.sh |  7 +++++++
 2 files changed, 22 insertions(+)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3b84c613..6f2abeb7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,5 +1,10 @@
 include: 'https://gitlab.gnome.org/GNOME/citemplates/raw/master/flatpak/flatpak_ci_initiative.yml'
 
+stages:
+  - check
+  - test
+  - deploy
+
 variables:
   BUNDLE: "org.gnome.GtranslatorDevel.flatpak"
 
@@ -19,3 +24,13 @@ nightly:
   extends: '.publish_nightly'
   dependencies:
     - 'flatpak'
+
+# Lint the code
+clang-format:
+  stage: check
+  image: fedora:36
+  script:
+    - dnf install -y clang-tools-extra git
+    - git diff -U0 --no-color --relative $CI_MERGE_REQUEST_TARGET_BRANCH_NAME | scripts/check-diff-style.sh
+  only:
+    - merge_requests
diff --git a/scripts/check-diff-style.sh b/scripts/check-diff-style.sh
new file mode 100755
index 00000000..936ff049
--- /dev/null
+++ b/scripts/check-diff-style.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+TMP_FILE=$(mktemp)
+clang-format-diff -p1 -style GNU | tee $TMP_FILE
+OUT=$(cat $TMP_FILE | wc -l)
+rm $TMP_FILE
+(( $OUT == 0 ))


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