Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #2829 from gratipay/improve-release.sh
Browse files Browse the repository at this point in the history
Improve release.sh
  • Loading branch information
chadwhitacre committed Oct 20, 2014
2 parents 11fcaf3 + ed0613e commit cf99c0f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 89 deletions.
4 changes: 2 additions & 2 deletions configure-aspen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from gratipay import canonize, utils
from gratipay.security import authentication, csrf, x_frame_options
from gratipay.utils import cache_static, i18n, set_cookie, timer
from gratipay.version import get_version


import aspen
Expand Down Expand Up @@ -39,8 +40,7 @@ def _set_cookie(response, *args, **kw):
# Wireup Algorithm
# ================

version_file = os.path.join(website.www_root, 'version.txt')
website.version = open(version_file).read().strip()
website.version = get_version()


website.renderer_default = "jinja2"
Expand Down
31 changes: 31 additions & 0 deletions gratipay/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from os.path import dirname, isdir, join
import re
from subprocess import CalledProcessError, check_output


def get_version():
d = dirname(dirname(__file__))

if isdir(join(d, '.git')):
# Get the version using "git describe".
cmd = 'git describe --tags --match [0-9]*'.split()
try:
version = check_output(cmd).decode().strip()
except CalledProcessError:
print('Unable to get version number from git tags')
exit(1)

# PEP 386 compatibility
if '-' in version:
version = '.post'.join(version.split('-')[:2])

else:
# Extract the version from the PKG-INFO file.
with open(join(d, 'PKG-INFO')) as f:
version = re.search('^Version: (.+)$', f.read(), re.M).group(1)

return version


if __name__ == '__main__':
print(get_version())
133 changes: 52 additions & 81 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
#!/bin/sh

# Fail on error.
# ==============

# Fail on error
set -e


# Be somewhere predictable.
# =========================

# Be somewhere predictable
cd "`dirname $0`"


# --help
# ======

if [ $# = 0 ]; then
echo
echo "Usage: $0 <version>"
echo
echo " This is a release script for Gratipay. We bump the version number in "
echo " www/version.txt and then do a git dance, pushing to Heroku."
echo
exit
fi


# Helpers
# =======

confirm () {
yesno () {
proceed=""
while [ "$proceed" != "y" ]; do
read -p"$1 (y/N) " proceed
if [ "$proceed" = "n" -o "$proceed" = "N" -o "$proceed" = "" ]
then
return 1
fi
read -p"$1 (y/n) " proceed
[ "$proceed" = "n" ] && return 1
done
return 0
}
Expand All @@ -49,73 +28,65 @@ require () {
}


# Work
# ====
# Check that we have the required tools
require heroku
require git

if [ $1 ]; then

require heroku
require git

if [ "`git rev-parse --abbrev-ref HEAD`" != "master" ]; then
echo "Not on master, checkout master first."
exit
fi

# Make sure we have the latest master.
# ====================================

git pull

if [ "`git tag | grep $1`" ]; then
echo "Version $1 is already git tagged."
exit
fi

if ! grep -e \-dev$ www/version.txt > /dev/null; then
echo "Current version does not end with '-dev'."
exit
fi

confirm "Tag and push version $1?"
if [ $? -eq 0 ]; then

# Check that the environment contains all required variables.
# ===========================================================

heroku config -sa gratipay | ./env/bin/honcho run -e /dev/stdin \
./env/bin/python gratipay/wireup.py
# 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


# Bump the version.
# =================
# Compute the next version number
prev="$(git describe --tags --match '[0-9]*' | cut -d- -f1 | sed 's/\.//g')"
version="$((prev + 1))"

printf "$1\n" > www/version.txt
git commit www/version.txt -m"Bump version to $1"
git tag $1

# Check that the environment contains all required variables
heroku config -sa gratipay | ./env/bin/honcho run -e /dev/stdin \
./env/bin/python gratipay/wireup.py

# Deploy to Heroku.
# =================

git push heroku master
# Check for a branch.sql
if [ -e branch.sql ]; then
# Merge branch.sql into schema.sql
git rm --cached branch.sql
echo | cat branch.sql >>schema.sql
echo "branch.sql has been appended to schema.sql"
read -p "If you have manual modifications to make to schema.sql do them now, then press Enter to continue... " enter
git add schema.sql
git commit -m "merge branch.sql into schema.sql"

# Deployment options
if yesno "Should branch.sql be applied before deploying to Heroku instead of after?"; then
run_sql="before"
if yesno "Should the maintenance mode be turned on during deployment?"; then
maintenance="yes"
fi
else
run_sql="after"
fi
fi

# Bump the version again.
# =======================
# We're using a Pythonic convention here by using -dev to mean, "a
# dev version following $whatever." We escape the dash for bash's
# sake

printf "$1\055dev\n" > www/version.txt
git commit www/version.txt -m"Bump version to $1-dev"
# Ask confirmation and bump the version
yesno "Tag and deploy version $version?" || exit
git tag $version


# Push to GitHub.
# ===============
# Deploy to Heroku
[ "$maintenance" = "yes" ] && heroku maintenance:on -a gratipay
[ "$run_sql" = "before" ] && heroku pg:psql -a gratipay <branch.sql
git push heroku master
[ "$maintenance" = "yes" ] && heroku maintenance:off -a gratipay
[ "$run_sql" = "after" ] && heroku pg:psql -a gratipay <branch.sql
rm -f branch.sql

git push
git push --tags

fi
fi
# Push to GitHub
git push
git push --tags
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import os
from setuptools import setup, find_packages


def get_version():
try:
return open(os.path.join('www', 'version.txt')).read().strip()
except OSError:
return 'n/a'
from gratipay.version import get_version


setup( name='gratipay'
Expand Down

0 comments on commit cf99c0f

Please sign in to comment.