Skip to content

Instantly share code, notes, and snippets.

@marcelorxaviers
Last active March 4, 2020 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelorxaviers/7d60258ee79e93c31bcfbf6c406f77db to your computer and use it in GitHub Desktop.
Save marcelorxaviers/7d60258ee79e93c31bcfbf6c406f77db to your computer and use it in GitHub Desktop.
#!/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
@marcelorxaviers
Copy link
Author

Nice, I'll check Husky out. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment