Last active
March 4, 2020 11:35
-
-
Save marcelorxaviers/7d60258ee79e93c31bcfbf6c406f77db to your computer and use it in GitHub Desktop.
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/bash | |
chruby 2.7.0 | |
export RUBYOPT=-W:no-deprecated | |
# Install all gem dependencies | |
bundle install | |
# Just to prevent showing many "error" messages | |
dirty_bit=0 | |
# Run rubocop | |
rubocop -a | |
last_command_ret_code=$? | |
if [ $last_command_ret_code -eq 0 ]; then | |
# Run unit tests | |
bundle exec rails test | |
last_command_ret_code=$? | |
else | |
echo "RUBOCOP OFFENSES PREVENTED ME FROM COMMITTING..." | |
dirty_bit=1 | |
fi | |
if [ $last_command_ret_code -eq 0 ]; then | |
# Prepare to run system tests | |
yarn build-for-tests | |
# Run system tests | |
bundle exec rails test:system | |
last_command_ret_code=$? | |
elif [ $dirty_bit -eq 0 ]; then | |
echo "UNIT TESTS FAILURES/ERRORS PREVENTED ME FROM COMMITTING..." | |
dirty_bit=1 | |
fi | |
if [ $last_command_ret_code -eq 0 ]; then | |
echo "ALL GOOD. COMMITTING..." | |
elif [ $dirty_bit -eq 0 ]; then | |
echo "SYSTEM TESTS FAILURES/ERRORS PREVENTED ME FROM COMMITTING..." | |
fi | |
# Return the last "error" code if any | |
exit $last_command_ret_code |
Also be careful with this condition: if [ $NUM_FAILS -ne 0 ]
cause when its true the script exits without doing a git stash pop -q
At Codegram we are using https://github.com/typicode/husky to manage git hooks. You can include the hooks in the package json like this
{
"scripts": {
"pre-commit": "bundle exec rubocop -a"
},
"lint-staged": {
"*.rb": [
"bundle exec rubocop -a"
]
}
}
The lint-staged
package is optional but it is very useful to run the command just for the files that have been changed.
Nice, I'll check Husky out. 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My suggestion:
just one pass of
rubocop
The idea is
no offenses => 0
N offenses detected, K offenses corrected => N-K