diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit new file mode 100755 index 00000000..2815fb6a --- /dev/null +++ b/.git-hooks/pre-commit @@ -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 diff --git a/Makefile b/Makefile index ad9953f3..b6326786 100644 --- a/Makefile +++ b/Makefile @@ -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. @@ -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) @@ -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...)