Skip to content

Instantly share code, notes, and snippets.

@inirudebwoy
Created November 6, 2017 15:32
Show Gist options
  • Save inirudebwoy/e415531dec8262fef5dd23127d518e43 to your computer and use it in GitHub Desktop.
Save inirudebwoy/e415531dec8262fef5dd23127d518e43 to your computer and use it in GitHub Desktop.
Make verifying of PRs easier
#!/bin/bash
UNITTEST_LOG=error_unittest_verify_pr.log
INTEGRATIONTEST_LOG=error_integrationtest_verify_pr.log
CURRENT_GIT_BRANCH=$(git name-rev --name-only HEAD)
# check argument
if [ -z "$1" ]; then
echo "$(tput setaf 1)Please supply name of the branch to verify"
exit 1
fi
# remove log files
if [[ -s $UNITTEST_LOG ]]; then
rm $UNITTEST_LOG
fi
if [[ -s $INTEGRATIONTEST_LOG ]]; then
rm $INTEGRATIONTEST_LOG
fi
# checkout branch only if clean
git_clean=$(git status --porcelain --untracked-files=no)
if [[ $? != 0 ]]; then
echo "Git is dirty. Stash your changes before running this command again."
fi
echo "Fetching from git"
git fetch > /dev/null 2>&1
echo "Switching branch to $1"
git checkout $1 > /dev/null 2>&1
# build
echo "Building docker images"
docker-compose build > /dev/null 2>&1
# run tests, with internal integration
temp_log=$(mktemp)
echo "Running unit tests"
test_unit_output=$(docker-compose run --rm backend pytest > $temp_log)
if [[ $? != 0 ]]; then
cp $temp_log "$UNITTEST_LOG"
fi
echo "Running integration internal tests"
test_internal_output=$(docker-compose run --rm backend pytest --runslow-internal > $temp_log)
if [[ $? != 0 ]]; then
cp $temp_log "$INTEGRATIONTEST_LOG"
fi
echo "Switching back to $CURRENT_GIT_BRANCH"
git checkout $CURRENT_GIT_BRANCH > /dev/null 2>&1
if [[ -s $UNITTEST_LOG || -s $INTEGRATIONTEST_LOG ]]; then
echo "$(tput setaf 1)Tests failed. See log files."
echo "$UNITTEST_LOG or/and $INTEGRATIONTEST_LOG"
else
echo "$(tput setaf 2)Tests are good. $(tput setaf 3)Merge it!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment