]> git.mxchange.org Git - friendica.git/commitdiff
Added sample pre-commit hook to give you an idea how to start to include:
authorRoland Häder <roland@mxchange.org>
Tue, 25 Oct 2022 20:55:15 +0000 (22:55 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 17 Jan 2024 00:03:02 +0000 (01:03 +0100)
- lint check by `php -l $CHANGED_FILE`
- code-style check by php-cs --dry-run
- executing unit-tests (non-fatal)

Please feel free to modify it.

mods/sample-pre-commit-hook.sh [new file with mode: 0755]

diff --git a/mods/sample-pre-commit-hook.sh b/mods/sample-pre-commit-hook.sh
new file mode 100755 (executable)
index 0000000..143be43
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+# INSTRUCTION: Copy this file to .git/hooks/pre-commit
+
+DBSTRUCTURE_PHP="static/dbstructure.config.php"
+
+# You might have to change this to run the unit tests:
+UNIT_TEST_SCRIPT="/some/path/run_unit_tests.sh"
+
+echo "$0: Checking syntax and code-style ..."
+CHANGES=$(git status | grep "modified:" | grep ".php" | cut -d ":" -f 2)
+ERRORS=""
+
+for CHANGE in ${CHANGES};
+do
+       CHECK=$(php -l ${CHANGE} | grep -v "No syntax errors detected in")
+       if [ -n "${CHECK}" ]
+       then
+               echo "${CHECK}"
+               ERRORS="1"
+       fi
+       CHECK=$(./bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run ${CHANGE})
+       if [ "$$" != "0" -a "$$" -lt 100 ]
+       then
+               echo "$0: Found code-style issue in '${CHANGE}'."
+               ERRORS="1"
+       fi
+done
+
+if [ -n "${ERRORS}" ]
+then
+       echo "$0: Some error(s) were found."
+       exit 255
+fi
+
+DBSTRUCTURE=$(echo "${CHANGES}" | grep "${DBSTRUCTURE_PHP}")
+if [ -n "${DBSTRUCTURE}" ]
+then
+       echo "$0: '${DBSTRUCTURE_PHP}' has changed. Updating documentation ..."
+       ./bin/console dbstructure dumpsql > database.sql || exit 255
+       git add database.sql doc/database/*.md
+fi
+
+echo "$0: Running unit tests ..."
+${UNIT_TEST_SCRIPT}
+STATUS=$?
+echo "$0: STATUS='${STATUS}'"
+
+echo "$0: All checks passed."
+exit 0