From: Roland Häder Date: Tue, 25 Oct 2022 20:55:15 +0000 (+0200) Subject: Added sample pre-commit hook to give you an idea how to start to include: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b6225ed3783dacefe7f70eb375bcd756a0510a6a;p=friendica.git Added sample pre-commit hook to give you an idea how to start to include: - 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. --- diff --git a/mods/sample-pre-commit-hook.sh b/mods/sample-pre-commit-hook.sh new file mode 100755 index 0000000000..143be43dc5 --- /dev/null +++ b/mods/sample-pre-commit-hook.sh @@ -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