Last active
February 15, 2017 15:53
-
-
Save AaronRietschlin/d49aacd7a9eb918b9803d26786d164ca to your computer and use it in GitHub Desktop.
Pre Commit Hook for running tests prior to pushing to the Android repos
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 symbolic-ref --short HEAD) | |
COMMIT_MESSAGE=$(head -n 1 $1) | |
REGEX_TICKET_NUMBER="\APPS-*[0-9]*" | |
[[ "$CURRENT_BRANCH" =~ $REGEX_TICKET_NUMBER ]] && echo ${BASH_REMATCH[1]} | |
TICKET_NUMBER=$BASH_REMATCH | |
REGEX_CHECK_FOR_COMMIT_MESSAGE="(^""$TICKET_NUMBER""|Merge)" | |
SED_ARG_START="1s/^/" | |
SED_ARG_END="/" | |
SED_ADD_TICKET_NUMBER=$SED_ARG_START$TICKET_NUMBER$SED_ARG_END | |
if [ -z "$TICKET_NUMBER" ] && [ "$CURRENT_BRANCH" != "development" ] | |
then | |
echo "ERROR: Please include your APPS-XXXX ticket number in your branch name" | |
exit 1 | |
fi | |
if [[ $COMMIT_MESSAGE == "" ]] | |
then | |
echo "ERROR: Commit aborted. Please include a commit message" | |
exit 1; | |
fi | |
if [[ $COMMIT_MESSAGE =~ $REGEX_CHECK_FOR_COMMIT_MESSAGE ]] | |
then | |
exit | |
else | |
sed -i.bak -e $SED_ARG_START" "$SED_ARG_END $1 | |
sed -i.bak -e $SED_ADD_TICKET_NUMBER $1 | |
fi |
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 | |
# Colors | |
ESC_SEQ="\x1b[" | |
COL_RESET=$ESC_SEQ"39;49;00m" | |
COL_RED=$ESC_SEQ"31;01m" | |
COL_GREEN=$ESC_SEQ"32;01m" | |
COL_YELLOW=$ESC_SEQ"33;01m" | |
COL_BLUE=$ESC_SEQ"34;01m" | |
COL_MAGENTA=$ESC_SEQ"35;01m" | |
COL_CYAN=$ESC_SEQ"36;01m" | |
CMD_HCO="./gradlew clean testHcoDebugUnitTestCoverage" | |
CMD_ANF="./gradlew clean testAnfDebugUnitTestCoverage" | |
CMD_SDK="./gradlew clean sdk:testDebugUnitTestCoverage" | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
$CMD_HCO | |
RESULT=$? | |
if [ $RESULT -ne 0 ]; then | |
echo -e "$COL_MAGENTA $CMD_HCO: test did not pass! Push aborted. $COL_RESET" | |
exit 1 | |
fi | |
$CMD_ANF | |
RESULT=$? | |
if [ $RESULT -ne 0 ]; then | |
echo -e "$COL_MAGENTA $CMD_ANF: test did not pass! Push aborted. $COL_RESET" | |
exit 1 | |
fi | |
$CMD_SDK | |
RESULT=$? | |
if [ $RESULT -ne 0 ]; then | |
echo -e "$COL_MAGENTA $CMD_SDK: test did not pass! Push aborted. $COL_RESET" | |
exit 1 | |
fi | |
echo -e "$COL_MAGENTA All tests passed on Debug! Pushing $current_branch! $COL_RESET" | |
exit 0 |
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 | |
# Colors | |
ESC_SEQ="\x1b[" | |
COL_RESET=$ESC_SEQ"39;49;00m" | |
COL_RED=$ESC_SEQ"31;01m" | |
COL_GREEN=$ESC_SEQ"32;01m" | |
COL_YELLOW=$ESC_SEQ"33;01m" | |
COL_BLUE=$ESC_SEQ"34;01m" | |
COL_MAGENTA=$ESC_SEQ"35;01m" | |
COL_CYAN=$ESC_SEQ"36;01m" | |
CMD="./gradlew clean testHcoDebugUnitTest testAnfDebugUnitTest :debugMenu:testDebugUnitTest :sdk:testDebugUnitTest" | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
$CMD | |
RESULT=$? | |
if [ $RESULT -ne 0 ]; then | |
echo -e "$COL_MAGENTA $CMD: test did not pass! Push aborted. $COL_RESET" | |
exit 1 | |
fi | |
$CMD_SDK | |
"pre-push" 33L, 788C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment