Last active
April 8, 2021 12:46
-
-
Save Synkevych/15426b53361c5795bc2d456a01a187c2 to your computer and use it in GitHub Desktop.
Run RSpec tests on pre-push - git hook for Rails projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
changed_files=`git status --short` | |
if [ "$changed_files" ]; then | |
echo "There some changes:" | |
echo "$changed_files" | |
echo "please commit or reset them, before push." | |
exit 1 | |
else | |
echo "There no changes, move on to the next task" | |
fi | |
echo "Running RSpec" | |
bundle exec rspec spec | |
spec=$? | |
if [ $spec -eq 0 ]; then | |
echo -en "\\033[32mTests are green, pushing...\\033[0;39m\n" | |
exit | |
else | |
echo -en "\\033[1;31mCannot push, tests are failing. Use --no-verify to force push.\\033[0;39m\n" | |
exit 1 | |
fi | |
echo "looks for console.log or puts inside project files" | |
FILES_PATTERN='\.(js|coffee|rb)(\..+)?$' | |
FORBIDDEN='console.info\|console.log\|alert\|puts| | |
git diff --cached --name-only | \ | |
grep -E $FILES_PATTERN | \ | |
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN && echo 'COMMIT REJECTED Found "$FORBIDDEN" references. Please remove them before commiting' && exit 1 | |
changed_files=`git log ..origin/develop` | |
if [ "$changed_files" ]; then | |
echo "There are some changes in origin/develop, please pull them before pushing" | |
exit 1 | |
else | |
echo "There are no changes in origin/develop, pushing to the remote server" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To setup this hook: