From d70c8152ea34e7af4026d8e0dea446474eb38a6f Mon Sep 17 00:00:00 2001 From: Changaco Date: Mon, 20 Oct 2014 13:33:39 +0200 Subject: [PATCH 1/4] get rid of version.txt --- configure-aspen.py | 4 ++-- gratipay/version.py | 31 +++++++++++++++++++++++++++++++ release.sh | 20 +------------------- setup.py | 7 +------ 4 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 gratipay/version.py diff --git a/configure-aspen.py b/configure-aspen.py index d952ec1a63..58493ca941 100644 --- a/configure-aspen.py +++ b/configure-aspen.py @@ -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 @@ -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" diff --git a/gratipay/version.py b/gratipay/version.py new file mode 100644 index 0000000000..2f3e3dd637 --- /dev/null +++ b/gratipay/version.py @@ -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()) diff --git a/release.sh b/release.sh index 04d51909d6..bb8162e879 100755 --- a/release.sh +++ b/release.sh @@ -19,8 +19,7 @@ if [ $# = 0 ]; then echo echo "Usage: $0 " 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 " This is a release script for Gratipay. We do a git dance, pushing to Heroku." echo exit fi @@ -72,11 +71,6 @@ if [ $1 ]; then 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 @@ -90,8 +84,6 @@ if [ $1 ]; then # Bump the version. # ================= - printf "$1\n" > www/version.txt - git commit www/version.txt -m"Bump version to $1" git tag $1 @@ -101,16 +93,6 @@ if [ $1 ]; then git push heroku master - # 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" - - # Push to GitHub. # =============== diff --git a/setup.py b/setup.py index 9c90a2b1ff..5d842b083f 100644 --- a/setup.py +++ b/setup.py @@ -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' From cf3f4bcec62c846213723155e1fee511a18277d1 Mon Sep 17 00:00:00 2001 From: Changaco Date: Mon, 20 Oct 2014 14:04:49 +0200 Subject: [PATCH 2/4] reformat release.sh --- release.sh | 76 +++++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 49 deletions(-) diff --git a/release.sh b/release.sh index bb8162e879..a1829cef53 100755 --- a/release.sh +++ b/release.sh @@ -1,21 +1,16 @@ #!/bin/sh -# Fail on error. -# ============== +# Fail on error set -e -# Be somewhere predictable. -# ========================= - +# Be somewhere predictable cd "`dirname $0`" # --help -# ====== - -if [ $# = 0 ]; then +if [ "$1" = "" ]; then echo echo "Usage: $0 " echo @@ -26,7 +21,6 @@ fi # Helpers -# ======= confirm () { proceed="" @@ -48,56 +42,40 @@ require () { } -# Work -# ==== - -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 +# Check that we have the required tools +require heroku +require git - if [ "`git tag | grep $1`" ]; then - echo "Version $1 is already git tagged." - exit - fi - - confirm "Tag and push version $1?" - if [ $? -eq 0 ]; then - # Check that the environment contains all required variables. - # =========================================================== +# Make sure we have the latest master - heroku config -sa gratipay | ./env/bin/honcho run -e /dev/stdin \ - ./env/bin/python gratipay/wireup.py +if [ "`git rev-parse --abbrev-ref HEAD`" != "master" ]; then + echo "Not on master, checkout master first." + exit +fi +git pull - # Bump the version. - # ================= +if [ "`git tag | grep $1`" ]; then + echo "Version $1 is already git tagged." + exit +fi - 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 +# Ask confirmation and bump the version +confirm "Tag and push version $1?" || exit +git tag $1 - # Push to GitHub. - # =============== +# Deploy to Heroku +git push heroku master - git push - git push --tags - fi -fi +# Push to GitHub +git push +git push --tags From 6f9fd9f4151fdc10915a74071301a73509e3b2eb Mon Sep 17 00:00:00 2001 From: Changaco Date: Mon, 20 Oct 2014 14:50:50 +0200 Subject: [PATCH 3/4] handle branch.sql in release.sh --- release.sh | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/release.sh b/release.sh index a1829cef53..23e34ebabc 100755 --- a/release.sh +++ b/release.sh @@ -22,14 +22,11 @@ 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 } @@ -67,13 +64,40 @@ heroku config -sa gratipay | ./env/bin/honcho run -e /dev/stdin \ ./env/bin/python gratipay/wireup.py +# 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 + + # Ask confirmation and bump the version -confirm "Tag and push version $1?" || exit +yesno "Tag and deploy version $1?" || exit git tag $1 # Deploy to Heroku +[ "$maintenance" = "yes" ] && heroku maintenance:on -a gratipay +[ "$run_sql" = "before" ] && heroku pg:psql -a gratipay Date: Mon, 20 Oct 2014 15:11:37 +0200 Subject: [PATCH 4/4] switch to automated version numbers --- release.sh | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/release.sh b/release.sh index 23e34ebabc..78d5738f11 100755 --- a/release.sh +++ b/release.sh @@ -9,17 +9,6 @@ set -e cd "`dirname $0`" -# --help -if [ "$1" = "" ]; then - echo - echo "Usage: $0 " - echo - echo " This is a release script for Gratipay. We do a git dance, pushing to Heroku." - echo - exit -fi - - # Helpers yesno () { @@ -45,18 +34,16 @@ require git # 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 -if [ "`git tag | grep $1`" ]; then - echo "Version $1 is already git tagged." - exit -fi + +# 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 @@ -87,8 +74,8 @@ fi # Ask confirmation and bump the version -yesno "Tag and deploy version $1?" || exit -git tag $1 +yesno "Tag and deploy version $version?" || exit +git tag $version # Deploy to Heroku