From 91c571829690fa7538a900c2bf235541bfcb4c85 Mon Sep 17 00:00:00 2001
From: Serge Bazanski <q3k@q3k.org>
Date: Thu, 20 Jul 2023 21:46:20 +0200
Subject: [PATCH] ci: run clang-format

---
 .clang-format   |  4 ++++
 .gitlab-ci.yml  |  6 ++++++
 tools/format.sh | 16 ++++++++++++++++
 3 files changed, 26 insertions(+)
 create mode 100644 .clang-format
 create mode 100755 tools/format.sh

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000000..d6b3adc8a1
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,4 @@
+---
+BasedOnStyle: Google
+IndentWidth: 4
+IncludeBlocks: Preserve
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bfab284bfa..3197845daa 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -38,6 +38,12 @@ mypy:
     reports:
       codequality: cqual.json
 
+format:
+  stage: check
+  script:
+    - "bash tools/format.sh"
+    - "[ -z \"$(git status --porcelain -u no)\" ] || (echo 'Differences found, please run tools/format.sh.' && git diff HEAD && exit 1)"
+
 build-p3:
   stage: build
   script:
diff --git a/tools/format.sh b/tools/format.sh
new file mode 100755
index 0000000000..6f3da1cc7c
--- /dev/null
+++ b/tools/format.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+set -e -x
+
+find . \
+    -type d \
+    \( \
+        -path './build' -o \
+        -path './recovery/build' -o \
+        -path './components/micropython/vendor' -o \
+        -path './components/tinyusb' -o \
+        -path './components/ctx' -o \
+        -path './sim' \
+    \) -prune \
+    -o \
+    -name '*.[ch]' \
+    -exec clang-format -i \{\} \;
-- 
GitLab