Skip to content

Commit

Permalink
Add command line options and GitHub CLI to release script (#1321)
Browse files Browse the repository at this point in the history
* Add command line options and GitHub CLI to release script

* Extra info

* Fix Linting Errors
  • Loading branch information
tunetheweb authored Sep 27, 2020
1 parent aa1b8ac commit 45e9678
Showing 1 changed file with 60 additions and 10 deletions.
70 changes: 60 additions & 10 deletions src/tools/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@
# exit when any command fails instead of trying to continue on
set -e

# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [-hv] [-f OUTFILE] [FILE]...
Release the Web Alamanac to Google Cloud Platform
Requires Permissions on Google Cloud Platform for the Web Amanac account
-h display this help and exit
-f force mode (no interactive prompts for each step)
-n no-promote - release a test version
EOF
}

OPTIND=1 #Reseting is good practive
force=0
no_promote=0
while getopts "h?fn" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
f) force=1
;;
n) no_promote=1
;;
esac
done
shift "$((OPTIND-1))" # Discard the options and sentinel --

# These color codes allow us to colour text output when used with "echo -e"
RED="\033[0;31m"
GREEN="\033[0;32m"
Expand All @@ -15,6 +45,10 @@ RESET_COLOR="\033[0m" # No Color

# A helper function to ask if it is OK to continue with [y/N] answer
function check_continue {
if [ "$force" == "1" ]; then
return
fi

read -r -n 1 -p "${1} [y/N]: " REPLY
if [ "${REPLY}" != "Y" ] && [ "${REPLY}" != "y" ]; then
echo
Expand All @@ -31,14 +65,15 @@ echo "Beginning the Web Almanac deployment process"
if [ -n "$(git status --porcelain)" ]; then
check_continue "Your branch is not clean. Do you still want to continue deploying?"
fi

check_continue "Please confirm you've updated the eBooks via GitHub Actions."

echo "Update local production branch"
git checkout production
git status
git pull
git pull origin main
if [ "${no_promote}" == "0" ]; then
echo "Update local production branch"
git checkout production
git status
git pull
git pull origin main
fi

if [ "$(pgrep -f 'python main.py')" ]; then
echo "Killing existing server to run a fresh version"
Expand All @@ -48,6 +83,13 @@ fi
echo "Run and test website"
./tools/scripts/run_and_test_website.sh

if [ "${no_promote}" == "1" ]; then
echo "Deploying to GCP (no promote)"
echo "Y" | gcloud app deploy --project webalmanac --no-promote
echo "Done"
echo "exit 0"
fi

echo "Please test the site locally"

check_continue "Are you ready to deploy?"
Expand Down Expand Up @@ -104,10 +146,18 @@ git checkout main
echo
echo -e "${GREEN}Successfully deployed!${RESET_COLOR}"
echo
echo -e "${AMBER}Please update release on GitHub: https://github.com/HTTPArchive/almanac.httparchive.org/releases${RESET_COLOR}"
echo -e "${AMBER}Using tag ${TAG_VERSION}@production${RESET_COLOR}"
echo -e "${AMBER}Please upload deploy.zip as the release artifact${RESET_COLOR}"
echo

if [[ $(which gh) ]]; then
gh release create "${TAG_VERSION}@production" deployed.zip -t "${TAG_VERSION}"
echo "Release updated on GitHub"
else
echo -e "${AMBER}GitHub cli is not available${RESET_COLOR}"
echo -e "${AMBER}Please update release on GitHub: https://github.com/HTTPArchive/almanac.httparchive.org/releases${RESET_COLOR}"
echo -e "${AMBER}Using tag ${TAG_VERSION}@production${RESET_COLOR}"
echo -e "${AMBER}Please upload deploy.zip as the release artifact${RESET_COLOR}"
echo
fi

echo "Have a good one!"
echo
exit 0

0 comments on commit 45e9678

Please sign in to comment.