-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease
More file actions
executable file
·156 lines (115 loc) · 4.27 KB
/
release
File metadata and controls
executable file
·156 lines (115 loc) · 4.27 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# ./release.sh
# -> test, build the doc in gh-pages
# ./release.sh upload
# -> bump the patch if no b else bump the beta (check last_upload)
# ./release.sh pre_minor upload
# -> bump the patch if no b else bumupload
# ./release.sh bump_beta
# -> bump the patch if no b else bump the beta and upload (check last_upload)
build_doc () {
#1 Do the job in the local branch
( cd doc ; sphinx-build -Q . ../html )
( cd html
rm -rf static sources images *.pyc .buildinfo .doctrees/
mv {_,}sources
mv {_,}static
mv {_,}images || true
find . -name '*.html' -o -name '*.js' | \
xargs sed -i 's/_static/static/g;s/_sources/sources/g'
)
# - interlude - Make an incursion in another branch
# stash if needed, prepare come back
set -x
if ! git status | grep -q "nothing to commit (working directory clean)";
then git stash save "just building doc" ; fi
current_branch=`git branch | awk '/\*/ {print $2}'`
git checkout gh-pages || return 1
#2 Do the job in the other branch
mv html/* .
git commit -a -m "Updated the doc to version $version"
# - conclusion - Back to the work branch
git checkout $current_branch || return 1
if git stash list | grep "just building doc"; then
git stash pop ; fi
}
update_long_description () {
python <<EOF
import re, wordish
replacement = re.compile('^.. sourcecode:: sh', re.M).sub('::', wordish.__doc__)
m = re.compile('(?P<before>.*?long_description\W*=\W*""").*?(?P<after>""".*)', re.S
).match( file('setup.py').read() )
file('setup.py','w').write(m.group('before') + replacement + m.group('after'))
file('README.txt','w').write(replacement)
EOF
}
new_version () {
unset major minor patch beta
remaining=`cat version`
major=${remaining%%.*}
remaining=${remaining#*.}
minor=${remaining%%.*}
remaining=${remaining#*.}
if [ `expr index b $remaining` -ne 0 ] ; then
patch=${remaining%%b*}
beta=${remaining##*b}
else
patch=$remaining
fi
case "$1" in
pre_minor ) new=$major.$(($minor+1)).0b ;;
pre_major ) new=$(($major+1)).0.0.0b ;;
bump_beta ) new=$major.$minor.${patch}b$((1+$beta));;
bump_patch ) new=$major.$minor.$(($patch+1)) ;;
bump_minor ) new=$major.$(($minor+1)).0 ;;
stabilize ) new=$major.$minor.$patch ;;
* ) new=`cat version` ;;
esac
set -x
echo $new > version
sed -i "s/\(__version__ = \).*/\1'$new'/" wordish.py
sed -i "s/\(version = \).*/\1'$new'/" doc/conf.py
sed -i "s/\( version = \).*/\1'$new',/" setup.py
update_long_description
git commit -m "Updated version to $new" setup.py doc/conf.py wordish.py version README.txt --no-verify
}
die () { echo "$1" >&2 ; exit 1 ; }
# 1. Update the version if a version is set on the command line Never
# upload twice the same version: increment the version if an upload
# is requested, and the current version is the last uploaded
# version (bump the beta if in beta, else bump the patch)
version=`cat version`
if [ -n "$1" -a "$1" != upload ];
then
new_version "$@"
version=`cat version`
elif ( [ "$1" = upload -o "$2" = upload ] ) \
&& [ $version = `cat .last_uploaded` ]; then
if [ `expr index $version b` -eq 0 ] ;
then new_version bump_patch
else new_version bump_beta ; fi
fi
# 2. Do the tests, build the doc, build the python packaging
# bail out if any problem
version=`cat version`
for f in `ls test_*.py`; do
python $f > /dev/null || die "Unit tests failed" ; done
build_doc || die "Build documentation failed"
python setup.py sdist || die "Python package build failed"
# 3. If requested, upload to pypi, to gh-pages, to master
if [ "$1" = upload -o "$2" = upload ]; then
curbranch=`git branch | awk '/\*/ {print $2}'`
test $curbranch == master || \
die "Please switch from the current '$curbranch' to the master branch"
git status | grep "nothing to commit (working directory clean)" \
|| die "release.sh must be called from a commited repository"
set -e -x
git checkout gh-pages
git push origin gh-pages
git checkout master
python setup.py sdist upload
echo $version > .last_uploaded
git tag v$version
git commit -a -m "Released v$version" --no-verify
git push origin master
fi