/
deploy.sh
executable file
·62 lines (56 loc) · 1.46 KB
/
deploy.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Deploy script for heroku!
function printStatus {
echo -e "\033[1;32m--- $1 ---\033[0m"
}
function printError {
echo -e "\033[1;31m--- $1 ---\033[0m"
}
#####
# Push changes to Git
#####
status=$(git status 2>&1)
if [[ ! $status =~ "nothing to commit, working directory clean" ]]; then
if [[ $status =~ "Untracked files:" ]]; then
read -e -p "Untracked files present, continue? (y/n): " UNTRACKED
if [[ -z "$UNTRACKED" ]] || [[ $UNTRACKED == "n" ]] || [[ $UNTRACKED == "N" ]]; then
printError "Untracked files present, aborting."
exit 1
fi
fi
UNSTAGED=false
if [[ $status =~ "Changes not staged for commit:" ]]; then
read -e -p "Unstaged changes, add them? (y/n): " UNSTAGED
if [[ -z "$UNSTAGED" ]] || [[ $UNSTAGED == "n" ]] || [[ $UNSTAGED == "N" ]]; then
UNSTAGED=false
else
UNSTAGED=true
fi
fi
if [[ $status =~ "Changes to be committed" ]] || $UNSTAGED; then
printStatus "Pushing changes to Github"
read -e -p "Please enter a commit message (empty to abort): " COMMIT_MSG
if [[ -z "$COMMIT_MSG" ]]; then
printError "No commit message, aborting."
exit 1
fi
if $UNSTAGED; then
git commit -a -m "$COMMIT_MSG"
else
git commit -m "$COMMIT_MSG"
fi
git push origin master
fi
fi
#####
# Deploy to heroku
#####
printStatus "Deploying to Heroku"
heroku config:push --overwrite
git push heroku master
#####
# Finish
#####
echo
sleep 0.5
printStatus "Done"