forked from plumdog/flask_table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·128 lines (98 loc) · 2.76 KB
/
release.sh
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
#!/bin/bash
set -e
function error() {
>&2 echo "$1"
exit 1
}
function confirm() {
read -r -p "Are you sure? [Y/n] " response
case $response in
[yY][eE][sS]|[yY]|"")
return
;;
*)
error "Abort."
;;
esac
}
function main() {
arg="$1"
if [[ $# -eq 0 ]]; then
error "No command given."
fi
case $arg in
tag)
tag "$2"
exit 0;
;;
publish)
publish
exit 0;
;;
*)
error "Unrecognised argument: $arg. Choose from tag,publish"
;;
esac
}
function _trim_from_upto() {
fname="$1"
from="$2"
upto="$3"
from_line="$(grep -n "$from" "$fname" | sed 's/\:.*//')"
upto_line="$(grep -n "$upto" "$fname" | sed 's/\:.*//')"
if [[ -z $from_line ]]; then error "Unable to find $from in $fname"; fi
if [[ -z $upto_line ]]; then error "Unable to find $upto in $fname"; fi
upto_line=$(($upto_line-1))
sed -i "$from_line,${upto_line}d" "$fname"
}
function generate_readme() {
pandoc --from=markdown --to=rst --output=README README.md || error "Unable to convert README.md"
# Remove the Github status links
sed -i '/Build Status.*Coverage Status/,+1d' README
# And remove a big chunk of html that gets a bit exploded
_trim_from_upto README "Or as HTML:" "Extra things:"
}
function tag() {
up="${1:-patch}"
[[ "$(git rev-parse --abbrev-ref HEAD)" == master ]] || error "Must be on master to tag."
git diff-files --quiet || error "Working directory must be clean to tag"
current="$(grep version setup.py | sed 's/^.*=//' | sed 's/,$//' | sed "s/['\"]//g")"
re='\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)'
major="$(echo $current | sed "s/$re/\1/")"
minor="$(echo $current | sed "s/$re/\2/")"
patch="$(echo $current | sed "s/$re/\3/")"
echo "Parsed current version as: $major.$minor.$patch"
case $up in
patch)
patch=$(($patch+1))
;;
minor)
minor=$(($minor+1))
patch=0
;;
major)
major=$(($major+1))
minor=0
patch=0
;;
*)
error "Unknown version section to increase: $up. Please select from: major,minor,patch."
;;
esac
new="$major.$minor.$patch"
echo "Ready to tag new version $new."
confirm
sed -i "s/$current/$new/" setup.py
git add setup.py
git commit -m "Bump to version $new"
git push origin master
git tag -a "v$new" -m "Version $new"
git push origin "v$new"
}
function publish() {
generate_readme
echo "Ready publish to PyPI."
confirm
python setup.py sdist upload -r pypi
}
main $@