tag_deploy.sh 1.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/bin/bash

printf "\n"

if [[ $1 = "" ]] ; then
  printf "Missing tag name to deploy!\n"
  printf "Usage: ./tag_deploy.sh <tag_name>\n" 
  exit
fi

# Save the branch name of the branch we were on before deploy. This enables
# us to be nice and checkout that branch post deploy
initialBranch=`git branch | grep \* | cut -d ' ' -f2`
checkoutInitialBranch="git checkout $initialBranch"

# Confirm with the user that this is indeed the tag to deploy.
printf "Tag to deploy: [$1]\n"
read -p "Are you sure you wish to deploy (y/n)? " answer

shopt -s nocasematch # case insentitive matching may save you one day
if [[ $answer =~ ^(n|no)$ ]] ; then
  printf "\nEject eject eject!!\n"
  exit
fi

# Checkout tag
checkoutCommand="git checkout $1"
if eval $checkoutCommand; then
  # checkout was successful
  printf "Tag checked out, starting deploy.\n"
  nanoboxDeploy="nanobox deploy -m 'Deployment of git tag: [$1]'"
  if eval $nanoboxDeploy; then
    printf "Deploy sucessful, monitor status from your dashboard!\n"
  else
    printf "Deploy failed.\n"
  fi
  eval $checkoutInitialBranch
else
  printf "$checkoutCommand returned a non-successful status code. Exiting.\n"
  eval $checkoutInitialBranch
  exit
fi