-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy.sh
executable file
·42 lines (34 loc) · 1.19 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
#!/usr/bin/env bash
HEROKU_REPOSITORY="https://git.heroku.com/subsidystorieseu.git"
# check if git cli is available
if ! which git 1>/dev/null 2>/dev/null; then
echo "Git cli not installed.";
exit 1;
fi
# create temporary branch for deploy
DEPLOY_BRANCH="temporary/heroku-deploy"
PREVIOUS_BRANCH=`git rev-parse --abbrev-ref HEAD`
git checkout ${DEPLOY_BRANCH} 2>/dev/null || git checkout -b ${DEPLOY_BRANCH}
if [ $? == 0 ]; then
# install dependencies, build and add everything to git
if npm install && NODE_ENV=production npm run build && npm run review && npm test; then
rm ./public/.gitignore 2>/dev/null
git add --force ./public
git commit -m "Build"
# deploy
if git push --force ${HEROKU_REPOSITORY} ${DEPLOY_BRANCH}:master; then
# successful build - return to previous branch and cleanup
git checkout ${PREVIOUS_BRANCH} 2>/dev/null
git branch -D ${DEPLOY_BRANCH} 2>/dev/null
echo ""
echo "Build succeeded. Open you application using \`heroku apps:open\`"
exit 0
fi
fi
fi
# cleanup anyway, and shor error message
git checkout ${PREVIOUS_BRANCH} 2>/dev/null
git branch -D ${DEPLOY_BRANCH} 2>/dev/null
echo ""
echo "Build failed."
exit 2