1#!/bin/bash
2
3set -eu -o pipefail
4
5pip install twine sphinx
6
7changelog=$(cat HISTORY.rst)
8
9regex='
10([0-9]+\.[0-9]+\.[0-9]+) \(([0-9]{4}-[0-9]{2}-[0-9]{2})\)
11\+*
12
13((.|
14)*)
15'
16
17if [[ ! $changelog =~ $regex ]]; then
18      echo "Could not find date line in change log!"
19      exit 1
20fi
21
22version="${BASH_REMATCH[1]}"
23date="${BASH_REMATCH[2]}"
24notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^[0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')"
25
26if [[ "$date" !=  $(date +"%Y-%m-%d") ]]; then
27    echo "$date is not today!"
28    exit 1
29fi
30
31tag="v$version"
32
33if [ -n "$(git status --porcelain)" ]; then
34    echo ". is not clean." >&2
35    exit 1
36fi
37
38perl -pi -e "s/(?<=__version__ = \").+?(?=\")/$version/gsm" maxminddb/__init__.py
39
40echo $"Test results:"
41python setup.py test
42
43echo $'\nDiff:'
44git diff
45
46echo $'\nRelease notes:'
47echo "$notes"
48
49read -e -p "Commit changes and push to origin? " should_push
50
51if [ "$should_push" != "y" ]; then
52    echo "Aborting"
53    exit 1
54fi
55
56git commit -m "Update for $tag" -a
57
58git push
59
60message="$version
61
62$notes"
63
64hub release create -m "$message" "$tag"
65
66git push --tags
67
68rm -fr dist
69python setup.py build_html sdist
70twine upload dist/*
71