Created
April 9, 2020 12:21
-
-
Save Jalalx/14e77098c9d228db5e7530408aa61cd4 to your computer and use it in GitHub Desktop.
A `pre-push` hook for git. A fork from https://github.com/Redfern/dot-net-core-pre-push-checks/blob/master/pre-push
This file contains hidden or 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 symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
RED='\033[0;31m' | |
GREEN='\033[1;32m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' # No Color | |
echo -e "${YELLOW}Running pre push check...${NC}" | |
echo -e "${YELLOW}Trying to build tests project...${NC}" | |
# build the project | |
dotnet build | |
# $? is a shell variable which stores the return code from what we just ran | |
rc=$? | |
if [[ $rc != 0 ]] ; then | |
echo -e "${RED}Failed to build the project, please fix this and push again${NC}" | |
echo "" | |
exit $rc | |
fi | |
echo -e "${YELLOW}Running unit tests...${NC}" | |
echo "" | |
# run the unit tests | |
dotnet test --filter Category=UnitTest | |
# $? is a shell variable which stores the return code from what we just ran | |
rc=$? | |
if [[ $rc != 0 ]] ; then | |
# A non-zero return code means an error occurred, so tell the user and exit | |
echo -e "${RED}Unit tests failed, please fix and push again${NC}" | |
echo "" | |
exit $rc | |
fi | |
# Everything went OK so we can exit with a zero | |
echo -e "${GREEN}Pre push check passed!${NC}" | |
echo "" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remember to store this file as
pre-push
in.git/hooks/
directory.