This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
/
deploy.sh
executable file
·94 lines (67 loc) · 1.99 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# Fail on error
set -e
# Be somewhere predictable
cd "$(dirname "$0")"
# Helpers
yesno () {
proceed=""
while [ "$proceed" != "y" ]; do
read -p"$1 (y/n) " proceed
[ "$proceed" = "n" ] && return 1
done
return 0
}
require () {
if [ ! "$(which "$1")" ]; then
echo "The '$1' command was not found."
exit 1
fi
}
maybe_commit () {
if git commit --dry-run &> /dev/null; then git commit -m "$1"; fi
}
# Check that we have the required tools
require heroku
require git
require curl
require pg_dump
# Make sure we have the latest master
if [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]; then
echo "Not on master, checkout master first."
exit
fi
git pull
# Compute the next version number
prev="$(git describe --tags --match '[0-9]*' | cut -d- -f1 | sed 's/\.//g')"
version="$((prev + 1))"
# Check that the environment contains all required variables
heroku config -s -a gratipay | ./env/bin/honcho run -e /dev/stdin \
./env/bin/python -m gratipay.wireup
# Ask confirmation and bump the version
yesno "Tag and deploy version $version?" || exit
echo $version > www/version.txt
git commit www/version.txt -m "Bump version to $version"
git tag $version
# Deploy to Heroku, with hooks
cd deploy
[ -e before.sql ] && heroku pg:psql -a gratipay < before.sql
git push --force heroku master
[ -e after.py ] && heroku run -a gratipay python deploy/after.py
[ -e after.sql ] && heroku pg:psql -a gratipay < after.sql
cd ..
# Clear deploy hooks and dump production schema back to schema.sql
rm -rf deploy/{before,after}.{sql,py} deploy/test*
pg_dump --schema-only \
--no-owner \
--no-privileges \
"`heroku config:get DATABASE_URL -a gratipay`" \
> sql/schema.sql
git add deploy sql/schema.sql
maybe_commit "Clear deploy hooks and update schema.sql"
# Push to GitHub
git push
git push --tags
# Provide visual confirmation of deployment.
echo "Checking version.txt ..."
curl https://gratipay.com/version.txt