Skip to content

Instantly share code, notes, and snippets.

@brenolf
Last active October 31, 2016 23:28
Show Gist options
  • Save brenolf/d7ccd8285a8e5b1cc70da456cb4c4874 to your computer and use it in GitHub Desktop.
Save brenolf/d7ccd8285a8e5b1cc70da456cb4c4874 to your computer and use it in GitHub Desktop.
Script for deploying yeoman projects to either staging or production environment on Heroku
#!/bin/bash
PROJECT=name;
if [[ "$1" == "staging" || "$1" == "production" ]]; then
TARGET=`echo "$1" | tr '[:lower:]' '[:upper:]'`;
read -p "Do you really wish to deploy to $TARGET? [yn] " yn;
if [[ "$yn" != "y" ]]; then
exit 0;
fi
else
echo "You must supply a parameter: 'staging' or 'production'";
exit 1;
fi
if [[ "$1" == "staging" ]]; then
BRANCH=staging;
else
BRANCH=production;
fi
TMP=tmp-deploy-branch-`date +%s`;
rm -rf dist bower_components;
bower install;
NODE_ENV=$BRANCH gulp;
git stash save -u;
git checkout master;
git pull;
git checkout -b $TMP;
sed -i -e 's/dist\///;s/bower_components//' .gitignore;
heroku git:remote -a $PROJECT-$BRANCH;
git add -A;
git commit -m "`date`";
heroku maintenance:on --app $PROJECT-$BRANCH;
git push -f git@heroku.com:$PROJECT-$BRANCH.git $TMP:master;
heroku run --app $PROJECT-$BRANCH -- npm run migrate;
heroku maintenance:off --app $PROJECT-$BRANCH;
git checkout -f @{-2};
git branch -D $TMP;
git stash pop;
bower install --force;
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment