mirror of
https://github.com/Karaka-Management/Build.git
synced 2026-02-13 17:48:39 +00:00
Fix new hooks
This commit is contained in:
parent
25f09e7d5a
commit
d8750c90dd
|
|
@ -5,13 +5,15 @@
|
||||||
. ${rootpath}/Build/Hooks/filename.sh
|
. ${rootpath}/Build/Hooks/filename.sh
|
||||||
. ${rootpath}/Build/Hooks/tests.sh
|
. ${rootpath}/Build/Hooks/tests.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
git diff --cached --name-only | while read FILE; do
|
git diff --cached --name-only | while read FILE; do
|
||||||
if [[ ! -f "$FILE" ]]; then
|
if [[ ! -f "$FILE" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Filename
|
# Filename
|
||||||
if [[ ! $(isValidFileName "$FILE") ]]; then
|
if [[ $(isValidFileName "$FILE") = 1 ]]; then
|
||||||
echo -e "\e[1;31m\tInvalid file name '$FILE'.\e[0m" >&2
|
echo -e "\e[1;31m\tInvalid file name '$FILE'.\e[0m" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -22,16 +24,16 @@ git diff --cached --name-only | while read FILE; do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(js)$ ]] && [[ $(hasJsLogging "$FILE") = 1 ]]; then
|
if [[ "$FILE" =~ ^.+(js)$ ]] && [[ $(hasJsLogging "$FILE") = 1 ]]; then
|
||||||
echo -e "\e[1;33m\tWarning, the commit contains a call to console.log() in '$1'. Commit was not aborted, however.\e[0m" >&2
|
echo -e "\e[1;33m\tWarning, the commit contains a call to console.log() in '$FILE'. Commit was not aborted, however.\e[0m" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ ! $(isPhanTestSuccessfull "$FILE") ]]; then
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(isPhanTestSuccessfull "$FILE") = 0 ]]; then
|
||||||
echo -e "\e[1;31m\tPhan error.\e[0m" >&2
|
echo -e "\e[1;31m\tPhan error.\e[0m" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ ! $(isPhpStanTestSuccessfull "$FILE") ]]; then
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(isPhpStanTestSuccessfull "$FILE") = 0 ]]; then
|
||||||
echo -e "\e[1;31m\tPhp stan error.\e[0m" >&2
|
echo -e "\e[1;31m\tPhp stan error.\e[0m" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -56,29 +58,32 @@ git diff --cached --name-only | while read FILE; do
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(sh)$ ]] && [[ ! $(isValidBashScript "$FILE") ]]; then
|
if [[ "$FILE" =~ ^.+(sh)$ ]] && [[ $(isValidBashScript "$FILE") = 0 ]]; then
|
||||||
echo -e "\e[1;31m\tBash linting error.\e[0m" >&2
|
echo -e "\e[1;31m\tBash linting error in '$FILE'.\e[0m" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then
|
if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then
|
||||||
GEN_SYNTAX = $(hasInvalidBasicSyntax "$FILE")
|
echo 1
|
||||||
|
GEN_SYNTAX=$(hasInvalidBasicSyntax "$FILE")
|
||||||
|
|
||||||
|
echo 2
|
||||||
|
|
||||||
if [[ $GEN_SYNTAX = 1 ]]; then
|
if [[ $GEN_SYNTAX = 1 ]]; then
|
||||||
echo -e "\e[1;31m\tFound whitespace at end of line in $1.\e[0m" >&2
|
echo -e "\e[1;31m\tFound whitespace at end of line in $FILE.\e[0m" >&2
|
||||||
grep -P ' $' $1 >&2
|
grep -P ' $' $FILE >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $GEN_SYNTAX = 2 ]]; then
|
if [[ $GEN_SYNTAX = 2 ]]; then
|
||||||
echo -e "\e[1;31m\tFound tab instead of whitespace $1.\e[0m" >&2
|
echo -e "\e[1;31m\tFound tab instead of whitespace $FILE.\e[0m" >&2
|
||||||
grep -P '\t' $1 >&2
|
grep -P '\t' $FILE >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then
|
if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then
|
||||||
TPL_SYNTAX = $(hasInvalidHtmlTemplateContent "$FILE")
|
TPL_SYNTAX=$(hasInvalidHtmlTemplateContent "$FILE")
|
||||||
|
|
||||||
if [[ $TPL_SYNTAX = 1 ]]; then
|
if [[ $TPL_SYNTAX = 1 ]]; then
|
||||||
echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2
|
echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
isValidFileName() {
|
isValidFileName() {
|
||||||
if test $(git diff --cached --name-only --diff-filter=A-z "$1" |
|
if test $(git diff --cached --name-only --diff-filter=A -z "$1" |
|
||||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@ hasPhpLogging() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
hasJsLogging() {
|
hasJsLogging() {
|
||||||
RESULT=$(grep "console.log(" "$1")
|
RESULT=$(grep "console.log(" "$1")
|
||||||
if [ ! -z $RESULT ]; then
|
if [ ! -z $RESULT ]; then
|
||||||
return 1;
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0;
|
return 0
|
||||||
}
|
}
|
||||||
|
|
@ -3,17 +3,17 @@
|
||||||
isPhanTestSuccessfull() {
|
isPhanTestSuccessfull() {
|
||||||
php -d memory_limit=4G ${rootpath}/vendor/bin/phan -k ${rootpath}/Build/Config/phan.php -f "$1"
|
php -d memory_limit=4G ${rootpath}/vendor/bin/phan -k ${rootpath}/Build/Config/phan.php -f "$1"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
return 0;
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 1;
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
isPhpStanTestSuccessfull() {
|
isPhpStanTestSuccessfull() {
|
||||||
php -d memory_limit=4G ${rootpath}/vendor/bin/phpstan analyse --autoload-file=${rootpath}/phpOMS/Autoloader.php -l 7 -c ${rootpath}/Build/Config/phpstan.neon "$1"
|
php -d memory_limit=4G ${rootpath}/vendor/bin/phpstan analyse --autoload-file=${rootpath}/phpOMS/Autoloader.php -l 7 -c ${rootpath}/Build/Config/phpstan.neon "$1"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
return 0;
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 1;
|
return 1
|
||||||
}
|
}
|
||||||
|
|
@ -5,33 +5,37 @@
|
||||||
. ${rootpath}/Build/Hooks/filename.sh
|
. ${rootpath}/Build/Hooks/filename.sh
|
||||||
. ${rootpath}/Build/Hooks/tests.sh
|
. ${rootpath}/Build/Hooks/tests.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
rootpath="$(pwd)"
|
||||||
|
echo $rootpath
|
||||||
|
|
||||||
($(git diff --name-only $TRAVIS_COMMIT_RANGE)) | while read FILE; do
|
($(git diff --name-only $TRAVIS_COMMIT_RANGE)) | while read FILE; do
|
||||||
if [[ ! -f "$FILE" ]]; then
|
if [[ ! -f "$FILE" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Filename
|
# Filename
|
||||||
if [[ ! $(isValidFileName "$FILE") = 1]]; then
|
if [[ $(isValidFileName "$FILE") = 1 ]]; then
|
||||||
echo -e "\e[1;31m\tInvalid file name.\e[0m" >&2
|
echo -e "\e[1;31m\tInvalid file name '$FILE'.\e[0m" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(hasPhpLogging "$FILE") = 1]]; then
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(hasPhpLogging "$FILE") = 1 ]]; then
|
||||||
echo -e "\e[1;33m\tWarning, the commit contains a call to var_dump() in '$FILE'. Commit was not aborted, however.\e[0m" >&2
|
echo -e "\e[1;33m\tWarning, the commit contains a call to var_dump() in '$FILE'. Commit was not aborted, however.\e[0m" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(js)$ ]] && [[ $(hasJsLogging "$FILE") = 1]]; then
|
if [[ "$FILE" =~ ^.+(js)$ ]] && [[ $(hasJsLogging "$FILE") = 1 ]]; then
|
||||||
echo -e "\e[1;33m\tWarning, the commit contains a call to console.log() in '$1'. Commit was not aborted, however.\e[0m" >&2
|
echo -e "\e[1;33m\tWarning, the commit contains a call to console.log() in '$1'. Commit was not aborted, however.\e[0m" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ ! $(isPhanTestSuccessfull "$FILE")]]; then
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(isPhanTestSuccessfull "$FILE") = 0 ]]; then
|
||||||
echo -e "\e[1;31m\tPhan error.\e[0m" >&2
|
echo -e "\e[1;31m\tPhan error.\e[0m" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ ! $(isPhpStanTestSuccessfull "$FILE")]]; then
|
if [[ "$FILE" =~ ^.+(php)$ ]] && [[ $(isPhpStanTestSuccessfull "$FILE") = 0 ]]; then
|
||||||
echo -e "\e[1;31m\tPhp stan error.\e[0m" >&2
|
echo -e "\e[1;31m\tPhp stan error.\e[0m" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -56,13 +60,13 @@
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(sh)$ ]] && [[ ! $(isValidBashScript "$FILE")]]; then
|
if [[ "$FILE" =~ ^.+(sh)$ ]] && [[ $(isValidBashScript "$FILE") = 0 ]]; then
|
||||||
echo -e "\e[1;31m\tBash linting error.\e[0m" >&2
|
echo -e "\e[1;31m\tBash linting error in '$FILE'.\e[0m" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then
|
if [[ "$FILE" =~ ^.+(sh|js|php|json|css)$ ]]; then
|
||||||
GEN_SYNTAX = $(hasInvalidBasicSyntax "$FILE")
|
GEN_SYNTAX=$(hasInvalidBasicSyntax "$FILE")
|
||||||
|
|
||||||
if [[ $GEN_SYNTAX = 1 ]]; then
|
if [[ $GEN_SYNTAX = 1 ]]; then
|
||||||
echo -e "\e[1;31m\tFound whitespace at end of line in $1.\e[0m" >&2
|
echo -e "\e[1;31m\tFound whitespace at end of line in $1.\e[0m" >&2
|
||||||
|
|
@ -78,7 +82,7 @@
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then
|
if [[ "$FILE" =~ ^.+(tpl\.php|html)$ ]]; then
|
||||||
TPL_SYNTAX = $(hasInvalidHtmlTemplateContent "$FILE")
|
TPL_SYNTAX=$(hasInvalidHtmlTemplateContent "$FILE")
|
||||||
|
|
||||||
if [[ $TPL_SYNTAX = 1 ]]; then
|
if [[ $TPL_SYNTAX = 1 ]]; then
|
||||||
echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2
|
echo -e "\e[1;31m\tFound missing image alt attribute.\e[0m" >&2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user