-
-
Save alekssamos/ec4ab50d99b586495ee7ce8ffd7b6713 to your computer and use it in GitHub Desktop.
pre-commit hook to run unit tests
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 | |
current_branch=`git rev-parse --abbrev-ref HEAD` | |
if [[ $current_branch =~ master|main ]]; then | |
message="Please don't push directly to $current_branch." | |
echo -e "\033[1;31mERROR: $message\033[0m"; | |
exit 1 | |
fi | |
repo_dir=`git rev-parse --show-toplevel` | |
message="[Policy] Doing unit tests ..." | |
echo -e "\033[1;34mInfo: $message\033[0m" | |
# pytest $repo_dir/test.py | |
python -m unittest discover | |
if [ $? -eq 1 ]; then | |
message="[Policy] Unit tests failed, please check and fix your code." | |
echo -e "\033[1;31mERROR: $message\033[0m"; | |
exit 1 | |
else | |
message="[Policy] Passed unit tests." | |
echo -e "\033[1;32mOK: $message\033[0m" | |
exit 0 | |
fi |
Author
alekssamos
commented
Jul 19, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment