mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 09:37:26 +00:00
Add php pre-commit hook
This commit is contained in:
parent
0f61fb6d89
commit
5b4f57ef37
6 changed files with 78 additions and 12 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -10,4 +10,5 @@ nbproject
|
||||||
composer
|
composer
|
||||||
.ht*
|
.ht*
|
||||||
/vendor/
|
/vendor/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.php_cs.cache
|
9
dev.sh
9
dev.sh
|
@ -6,13 +6,16 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
|
||||||
if [ ! -e "data/config.php" ]; then
|
if [ ! -e "data/config.php" ]; then
|
||||||
cp "$DIR/data/config.php.example" "$DIR/data/config.php"
|
cp "$DIR/data/config.php.example" "$DIR/data/config.php"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! which $PHPBIN 2>/dev/null; then
|
if ! which $PHPBIN 2>/dev/null; then
|
||||||
PHPBIN=php
|
PHPBIN=php
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Installing git hook
|
||||||
|
$DIR/hooks/install.sh
|
||||||
|
|
||||||
$PHPBIN composer.phar install
|
$PHPBIN composer.phar install
|
||||||
|
|
||||||
$PHPBIN --server localhost:8000 --docroot "$DIR/web" "$DIR/web/index.php"
|
$PHPBIN --server localhost:8000 --docroot "$DIR/web" "$DIR/web/index.php"
|
20
docker.sh
20
docker.sh
|
@ -4,14 +4,18 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
|
||||||
if [ ! -e "$DIR/data/config.php" ]; then
|
if [ ! -e "$DIR/data/config.php" ]; then
|
||||||
cp "$DIR/data/config.php.example" "$DIR/data/config.php"
|
cp "$DIR/data/config.php.example" "$DIR/data/config.php"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Installing git hook
|
||||||
|
$DIR/hooks/install.sh
|
||||||
|
|
||||||
docker run --rm -it --name "dev.lbry.io" \
|
docker run --rm -it --name "dev.lbry.io" \
|
||||||
-v "$DIR:/usr/src/lbry.io" \
|
-v "$DIR:/usr/src/lbry.io" \
|
||||||
-w "/usr/src/lbry.io" \
|
-w "/usr/src/lbry.io" \
|
||||||
-p "127.0.0.1:8000:8000" \
|
-p "127.0.0.1:8000:8000" \
|
||||||
-u "$(id -u):$(id -g)" \
|
-u "$(id -u):$(id -g)" \
|
||||||
php:7-alpine \
|
php:7-alpine \
|
||||||
php composer.phar install
|
php composer.phar install
|
||||||
php --server "0.0.0.0:8000" --docroot "web/" "index.php"
|
|
||||||
|
php --server "0.0.0.0:8000" --docroot "web/" "index.php"
|
18
hooks/install.sh
Executable file
18
hooks/install.sh
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ -e .git/hooks/pre-commit ];
|
||||||
|
then
|
||||||
|
PRE_COMMIT_EXISTS=1
|
||||||
|
else
|
||||||
|
PRE_COMMIT_EXISTS=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp ./hooks/pre-commit .git/hooks/pre-commit
|
||||||
|
chmod +x .git/hooks/pre-commit
|
||||||
|
|
||||||
|
if [ "$PRE_COMMIT_EXISTS" = 0 ];
|
||||||
|
then
|
||||||
|
echo "Pre-commit git hook is installed!"
|
||||||
|
else
|
||||||
|
echo "Pre-commit git hook is updated!"
|
||||||
|
fi
|
40
hooks/pre-commit
Normal file
40
hooks/pre-commit
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
|
||||||
|
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
|
||||||
|
|
||||||
|
# Determine if a file list is passed
|
||||||
|
if [ "$#" -eq 1 ]
|
||||||
|
then
|
||||||
|
oIFS=$IFS
|
||||||
|
IFS='
|
||||||
|
'
|
||||||
|
SFILES="$1"
|
||||||
|
IFS=$oIFS
|
||||||
|
fi
|
||||||
|
SFILES=${SFILES:-$STAGED_FILES_CMD}
|
||||||
|
|
||||||
|
echo "Checking PHP Lint..."
|
||||||
|
for FILE in $SFILES
|
||||||
|
do
|
||||||
|
php -l -d display_errors=0 $PROJECT/$FILE
|
||||||
|
if [ $? != 0 ]
|
||||||
|
then
|
||||||
|
echo "Fix the error before commit."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
FILES="$FILES $PROJECT/$FILE"
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$FILES" != "" ]
|
||||||
|
then
|
||||||
|
echo "Running php-cs-fixer"
|
||||||
|
$PROJECT/php-cs-fixer fix $FILES
|
||||||
|
git add $FILES
|
||||||
|
if [ $? != 0 ]
|
||||||
|
then
|
||||||
|
echo "Error was found"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $?
|
BIN
php-cs-fixer
Executable file
BIN
php-cs-fixer
Executable file
Binary file not shown.
Loading…
Add table
Reference in a new issue