Created
June 30, 2019 01:29
-
-
Save roloenusa/9129e9b1992c4434faa3798d7c91dbf0 to your computer and use it in GitHub Desktop.
Deploys an application on a folder to heroku.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Constants | |
# Variables | |
folder= | |
herokuapp= | |
init= | |
commit=`git rev-parse --short HEAD` | |
# Functions | |
push() | |
{ | |
echo "Deploying heroku app:" | |
echo 'Folder = ' $folder | |
echo 'Heroku App = ' $herokuapp | |
echo 'Current commit = ' $commit | |
git push https://git.heroku.com/$herokuapp.git `git subtree split --prefix $folder $commit`:master --force | |
} | |
push_init() | |
{ | |
echo "Deploying heroku app for the first time:" | |
echo 'Folder = ' $folder | |
echo 'Heroku App = ' $herokuapp | |
echo 'Current commit = ' $commit | |
heroku create $herokuapp --buildpack heroku/php | |
echo $herokuapp > "$folder/herokuapp" | |
git add "$folder/" | |
git commit -m "[$folder] Initial Commit" | |
git push https://git.heroku.com/$herokuapp.git `git subtree split --prefix $folder $commit`:refs/heads/master --force | |
} | |
usage() | |
{ | |
echo "usage: deploy [[[-f folder ] [-a herokuapp] [-i|--init]] | [-h]]" | |
echo "" | |
echo "-i|--init: Initializes the heroku app with the webpack," | |
echo " and creates a 'herokuapp' file with the name created." | |
echo "" | |
echo "-a|--app: The name of the heroku application to use. If empty," | |
echo " it will read a 'herokuapp' file." | |
echo "" | |
echo "-f|--folder: The folder to deploy. This is a required field." | |
} | |
# Parse the command line | |
while [[ $# -gt 0 ]]; do | |
case $1 in | |
-f | --folder ) | |
shift # past argument | |
folder=$1 | |
shift # past value | |
;; | |
-a | --app ) | |
shift # past argument | |
herokuapp=$1 | |
shift # past value | |
;; | |
-i | --init ) | |
shift # past argument | |
init=1 | |
;; | |
-h | --help ) | |
usage | |
exit | |
;; | |
* ) | |
usage | |
exit 1 | |
esac | |
done | |
if [ "$folder" = "" ]; then | |
echo "You must declare a folder to deploy." | |
usage | |
exit | |
fi | |
if [ "$herokuapp" = "" ]; then | |
echo "Reading herokuapp file..." | |
herokuapp=`cat $folder/herokuapp` | |
fi | |
if [ "$init" = "1" ]; then | |
push_init | |
else | |
push | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment