Skip to content

Commit

Permalink
Merge pull request #7 from systemseed/precommit
Browse files Browse the repository at this point in the history
Added pre-commit hook with code quality checks.
  • Loading branch information
spleshka authored Aug 22, 2018
2 parents 65da039 + 86aaf16 commit 58ee11e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
41 changes: 41 additions & 0 deletions .git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

#######################################
####### FALCON PRE-COMMIT HOOK ########
#######################################

# Define colors for error message.
white='\033[38;5;7m'
bg_red='\033[48;5;1m'
bold='\033[1m'
reset='\033[0m'

# Always run this hook from repository root.
cd "."

STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMRT | tr '\r\n' ' ')
# Skip if there were not code changes.
if [ -z "$STAGED_FILES" ]
then
exit 0
fi

# Run code standards checks.
make --quiet code:check
CHECKS_RESULT=$?

if [ $CHECKS_RESULT -ne 0 ]
then

echo "${white}${bg_red}"
cat <<\EOF
Code styling checks failed. Commit has been aborted.
Please fix the issues listed above and commit again.
EOF
echo ${reset}
echo "If you need to skip this check please use --no-verify option (not recommended)."
exit 1
fi

exit 0
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Define here list of available make commands.
.PHONY: default pull up stop down clean exec exec\:wodby exec\:root drush \
code\:check code\:fix \
install \
prepare install \
tests\:prepare tests\:run tests\:cli tests\:autocomplete

# Create local environment files.
Expand Down Expand Up @@ -83,9 +83,14 @@ prepare: | up
# Prepare settings.php file.
$(call message,$(PROJECT_NAME): Making settings.php writable)
$(call docker-wodby, php chmod 666 web/sites/default/settings.php)
# Prepare git hooks.
$(call message,$(PROJECT_NAME): Setting up git hooks)
ln -s $(shell pwd)/.git-hooks/* $(shell pwd)/.git/hooks


install: | prepare
$(call message,$(PROJECT_NAME): Installing Drupal)
sleep 5
$(call docker-www-data, php drush -r /var/www/html/web site-install falcon \
--db-url=mysql://$(DB_USER):$(DB_PASSWORD)@$(DB_HOST)/$(DB_NAME) --site-name=$(PROJECT_NAME) --account-pass=admin \
install_configure_form.enable_update_status_module=NULL --yes)
Expand All @@ -96,25 +101,25 @@ install: | prepare
code\:check:
# PHP coding standards check.
$(call message,$(PROJECT_NAME): Checking PHP for compliance with Drupal coding standards...)
docker run -it --rm \
docker run --rm \
-v $(shell pwd)/modules:/app/modules $(DOCKER_PHPCS) phpcs \
-s --colors --warning-severity=0 --standard=Drupal,DrupalPractice .
# Javascript coding standards check.
$(call message,$(PROJECT_NAME): Checking Javascript for compliance with Drupal coding standards...)
docker run -it --rm \
-v $(shell pwd)/modules:/app/modules \
-v $(shell pwd)/.eslintrc.json:/app/.eslintrc.json \
$(DOCKER_ESLINT) -c /app/.eslintrc.json /app
docker run --rm \
-v $(shell pwd)/modules:/eslint/modules \
-v $(shell pwd)/.eslintrc.json:/eslint/.eslintrc.json \
$(DOCKER_ESLINT) .

code\:fix:
$(call message,$(PROJECT_NAME): Auto-fixing coding style issues...)
docker run -it --rm \
docker run --rm \
-v $(shell pwd)/modules:/app/modules $(DOCKER_PHPCS) phpcbf \
-s --colors --warning-severity=0 --standard=Drupal,DrupalPractice .
docker run -it --rm \
-v $(shell pwd)/modules:/app/modules \
-v $(shell pwd)/.eslintrc.json:/app/.eslintrc.json \
$(DOCKER_ESLINT) -c /app/.eslintrc.json --fix /app
docker run --rm \
-v $(shell pwd)/modules:/eslint/modules \
-v $(shell pwd)/.eslintrc.json:/eslint/.eslintrc.json \
$(DOCKER_ESLINT) --fix .

tests\:prepare:
$(call message,$(PROJECT_NAME): Preparing Codeception framework for testing...)
Expand Down

0 comments on commit 58ee11e

Please sign in to comment.