Add python-eventlet package to MOS 9.0 repository
[packages/trusty/python-eventlet.git] / python-eventlet / bin / release
1 #!/bin/bash -e
2 cd "$( dirname "${BASH_SOURCE[0]}" )/.."
3 if [[ ! -d venv-release ]]; then
4         virtualenv venv-release
5         echo '*' >venv-release/.gitignore
6         venv-release/bin/pip install -U pip setuptools sphinx wheel
7 fi
8 . $PWD/venv-release/bin/activate
9 pip install -e $PWD
10
11 version=
12 version_next=
13
14 main() {
15         branch="${1-$(git symbolic-ref --short HEAD)}"
16         version="$(python -c 'import eventlet; print(eventlet.__version__)')"
17         printf "\nbranch: %s eventlet.__version__: '%s'\n" $branch $version >&2
18         if [[ "$branch" != "master" ]]; then
19                 echo "Must be on master" >&2
20                 exit 1
21         fi
22         if [[ -n "$(git status --short -uall)" ]]; then
23                 echo "Tree must be clean. git status:" >&2
24                 echo "" >&2
25                 git status --short -uall
26                 echo "" >&2
27                 exit 1
28         fi
29         last_commit_message=$(git show --format="%s" --no-patch HEAD)
30         expect_commit_message="v$version release"
31         if [[ "$last_commit_message" != "$expect_commit_message" ]]; then
32                 printf "Last commit message: '%s' expected: '%s'\n" "$last_commit_message" "$expect_commit_message" >&2
33                 if confirm "Create release commit? [yN] "; then
34                         create_commit
35                 elif ! confirm "Continue without proper release commit? [yN] "; then
36                         exit 1
37                 fi
38         fi
39         confirm "Continue? [yN] " || exit 1
40
41         echo "Creating tag v$version" >&2
42         if ! git tag "v$version"; then
43                 echo "git tag failed " >&2
44                 confirm "Continue still? [yN] " || exit 1
45         fi
46
47         if confirm "Build documentation (website)? [Yn] " >&2; then
48                 bin/build-website.bash || exit 1
49         fi
50
51         if confirm "Upload to PyPi? [Yn] "; then
52                 rm -rf build dist
53                 python setup.py sdist bdist_wheel register upload || exit 1
54         fi
55
56         git push --verbose origin master gh-pages || exit 1
57         git push --tags
58 }
59
60 create_commit() {
61         echo "" >&2
62         echo "Plan:" >&2
63         echo "1. bump version" >&2
64         echo "2. update NEWS, AUTHORS" >&2
65         echo "3. commit" >&2
66         echo "4. run bin/release again" >&2
67         echo "" >&2
68
69         bump_version
70         edit_news
71
72         git diff
73         confirm "Ready to commit? [Yn] " || exit 1
74         git commit -a -m "v$version_next release"
75
76         echo "Re-exec $0 to continue" >&2
77         exec $0
78 }
79
80 bump_version() {
81         local current=$version
82         echo "Current version: '$current'" >&2
83         echo -n "Enter next version (empty to abort): " >&2
84         read version_next
85         if [[ -z "$version_next" ]]; then
86                 exit 1
87         fi
88         echo "Next version:    '$version_next'" >&2
89
90         local current_tuple="${current//./, }"
91         local next_tuple="${version_next//./, }"
92         local version_path="eventlet/__init__.py"
93         echo "Updating file '$version_path'" >&2
94         if ! sed -i '' -e "s/($current_tuple)/($next_tuple)/" "$version_path"; then
95                 echo "sed error $?" >&2
96                 exit 1
97         fi
98         if git diff --exit-code "$version_path"; then
99                 echo "File '$version_path' is not modified" >&2
100                 exit 1
101         fi
102         echo "" >&2
103
104         local doc_path="doc/real_index.html"
105         echo "Updating file '$doc_path'" >&2
106         if ! sed -i '' -e "s/$current/$version_next/g" "$doc_path"; then
107                 echo "sed error $?" >&2
108                 exit 1
109         fi
110         if git diff --exit-code "$doc_path"; then
111                 echo "File '$doc_path' is not modified" >&2
112                 exit 1
113         fi
114         echo "" >&2
115
116         confirm "Confirm changes? [yN] " || exit 1
117 }
118
119 edit_news() {
120         echo "Changes since last release:" >&2
121         git log --format='%h   %an   %s' "v$version"^.. -- || exit 1
122         echo "" >&2
123
124         local editor=$(which edit 2>/dev/null)
125         [[ -z "$editor" ]] && editor="$EDITOR"
126         if [[ -n "$editor" ]]; then
127                 if confirm "Open default editor for NEWS and AUTHORS? [Yn] "; then
128                         $editor NEWS
129                         $editor AUTHORS
130                 else
131                         confirm "Change files NEWS and AUTHORS manually and press any key"
132                 fi
133         else
134                 echo "Unable to determine default text editor." >&2
135                 confirm "Change files NEWS and AUTHORS manually and press any key"
136         fi
137         echo "" >&2
138
139         if git diff --exit-code NEWS AUTHORS; then
140                 echo "Files NEWS and AUTHORS are not modified" >&2
141                 exit 1
142         fi
143         echo "" >&2
144
145         confirm "Confirm changes? [yN] " || exit 1
146 }
147
148 confirm() {
149         local reply
150         local prompt="$1"
151         read -n1 -p "$prompt" reply >&2
152         echo "" >&2
153         rc=0
154         local default_y=" \[Yn\] $"
155         if [[ -z "$reply" ]] && [[ "$prompt" =~ $default_y ]]; then
156                 reply="y"
157         fi
158         [[ "$reply" != "y" ]] && rc=1
159         return $rc
160 }
161
162 main "$@"