From 2830ce8f12d96a2288cdb853178cf2a12d874bbc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20W=C3=B6lzer?= <martin@libclapp.org>
Date: Mon, 16 Sep 2024 21:07:00 +0200
Subject: [PATCH] .ci/check/check.sh: introduced file

---
 .ci/check/check.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100755 .ci/check/check.sh

diff --git a/.ci/check/check.sh b/.ci/check/check.sh
new file mode 100755
index 00000000..ca9afa73
--- /dev/null
+++ b/.ci/check/check.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+function usage() {
+    local script
+    script=$(basename "${BASH_SOURCE[0]}")
+    echo "$script [--help] --check-command <CMD> --files-regex <REGEX> [--exclude-files-regex <REGEX>]"
+}
+
+files_regex=""
+exclude_files_regex="^$"
+while [[ "${#}" -gt 0 ]]; do
+    case "${1}" in
+    --exclude-files-regex)
+        exclude_files_regex="${2}"
+        shift
+        ;;
+    --files-regex)
+        files_regex="${2}"
+        shift
+        ;;
+    --check-command)
+        check_command="${2}"
+        shift
+        ;;
+    --help)
+        usage
+        exit 0
+        ;;
+    -?*)
+        echo "ERROR: Invalid argument: $1"
+        usage
+        exit 1
+        ;;
+    esac
+    shift
+done
+
+if [ -z "${check_command}" ]; then
+    echo "ERROR: Please give the check_command!"
+    usage
+    exit 1
+fi
+
+if [ -z "${files_regex}" ]; then
+    echo "ERROR: Please give a files regex!"
+    usage
+    exit 1
+fi
+
+echo "INFO: Searching for files matching '${files_regex}' in the git repository and exclude all matching '${exclude_files_regex}'"
+if ! files=$(git ls-files | grep -E "${files_regex}"); then
+    echo "ERROR: Could not find any files matching '${files_regex}' in the git repository!"
+    exit 1
+fi
+
+mapfile -t files < <(echo "${files}" | grep -Ev "${exclude_files_regex}")
+
+echo "INFO: Using command '${check_command}' to check the folowing files:" "${files[@]}"
+if ! ${check_command} "${files[@]}"; then
+    echo "ERROR: Some issues found in files!"
+    exit 1
+fi
-- 
GitLab