Skip to content

Instantly share code, notes, and snippets.

@palewire
Created December 27, 2017 15:59
Show Gist options
  • Save palewire/c89f678de011676e18862665caacb604 to your computer and use it in GitHub Desktop.
Save palewire/c89f678de011676e18862665caacb604 to your computer and use it in GitHub Desktop.
#!/bin/sh
start_timer ()
{
STARTTIME=$(date +%s);
}
end_timer ()
{
ENDTIME=$(date +%s);
}
thumbs_up ()
{
printf " πŸ‘ ($(($ENDTIME - $STARTTIME)) seconds) \n";
}
printf "\n";
printf "Running bigbuilder's pre-push tests\n\n";
printf " - Checking you are inside a virtualenv";
start_timer;
if [ -z "$VIRTUAL_ENV" ]; then
printf " πŸ‘Ž\n\n";
printf "Sorry. You are not in a virtualenv. Maybe you need to run activate?";
printf "\n\n";
exit 1;
else
end_timer;
thumbs_up;
fi
printf " - Fetching latest GitHub activity"
start_timer;
FETCH=$(git fetch -q);
end_timer;
thumbs_up;
start_timer;
BRANCH=$(git rev-parse --abbrev-ref HEAD);
UPSTREAM=${1:-'@{u}'};
printf " - Figuring out if you can push to $UPSTREAM/$BRANCH"
LOCAL=$(git rev-parse @);
REMOTE=$(git rev-parse "$UPSTREAM/$BRANCH" 2> /dev/null);
BASE=$(git merge-base @ "$UPSTREAM/$BRANCH");
# If a branch is new, the first case will be true
if [ $REMOTE = "$UPSTREAM/$BRANCH" ]; then
end_timer;
thumbs_up;
# If your branch is up to date with GitHub ...
elif [ $LOCAL = $REMOTE ]; then
printf " πŸ‘Ž\n\n";
printf "Your branch is already synced with GitHub. There's no need to push.\n\n";
exit 1;
# If your branch needs to pull from GitHub ...
elif [ $LOCAL = $BASE ]; then
printf " πŸ‘Ž\n\n";
printf "Sorry. You cannot push until you pull the latest code from GitHub\n";
exit 1;
# If your branch is ahead of GitHub and need to push ...
elif [ $REMOTE = $BASE ]; then
end_timer;
thumbs_up;
# If your branch has diverged from GitHub and you need to pull ...
else
printf " πŸ‘Ž\n\n";
printf "Sorry. You cannot push until you pull the latest code from GitHub\n";
exit 1;
fi
printf " - Ensuring bigbuilder installation is up to date";
start_timer;
python setup.py -q install;
end_timer;
thumbs_up;
printf " - Removing unwanted files";
start_timer;
python setup.py -q clean;
end_timer;
thumbs_up;
printf " - Verifying Python meets flake8 style guide";
start_timer;
flake8=$(flake8 `pwd`/config);
if [ $? -eq 0 ]; then
end_timer;
thumbs_up;
else
printf " πŸ‘Ž\n\n";
printf "Sorry. You cannot commit until you correct the following flake8 errors:\n\n";
printf $flake8;
printf "\n\n";
exit 1;
fi
printf " - Updating cache of archived pages";
start_timer;
rm -f ./.archive/.cache;
python manage.py cachepages;
end_timer;
thumbs_up;
printf " - Verifying all pages can build";
start_timer;
BUILD=$(python manage.py build --skip-media --skip-static --verbosity=0);
if [ $? -eq 0 ]; then
end_timer;
thumbs_up;
else
printf "\nSorry. You cannot push to GitHub until you correct the page errors above.\n\n";
exit 1;
fi
printf "\nThe '${BRANCH}' branch will soon be built at http://travis-ci.com/[REDACTED]/builds/\n";
if [ $BRANCH = 'master' ]; then
URL="http://[REDACTED]/";
else
URL="https://[REDACTED]/${BRANCH}/projects/";
fi
printf "\nAfter that completes, updates will appear at ${URL}\n";
printf "\n";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment