Skip to content

Instantly share code, notes, and snippets.

@Jalalx
Created April 9, 2020 12:21
Show Gist options
  • Save Jalalx/14e77098c9d228db5e7530408aa61cd4 to your computer and use it in GitHub Desktop.
Save Jalalx/14e77098c9d228db5e7530408aa61cd4 to your computer and use it in GitHub Desktop.
#!/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
@Jalalx
Copy link
Author

Jalalx commented Apr 9, 2020

Remember to store this file as pre-push in .git/hooks/ directory.

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