-
Notifications
You must be signed in to change notification settings - Fork 46
/
release
executable file
·195 lines (158 loc) · 5.62 KB
/
release
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/zsh
# The Release Script
# Part of the Python Project Template.
# Copyright © 2013-2018, Chris Warrick.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the author of this software nor the names of
# contributors to this software may be used to endorse or promote
# products derived from this software without specific prior written
# consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. .pypt/config
function status {
echo $@
}
function warning {
echo 'WARNING: '$@
}
function error {
echo 'ERROR: '$@
}
function cleanup {
rm -rf $PROJECTLC.egg-info build || true
rm -rf **/__pycache__ || true
}
function cleanup_cmfn {
[[ -e $cmfn ]] && rm $cmfn || true
[[ -e $cmfn2 ]] && rm $cmfn2 || true
}
status '*** Chris Warrick’s Release Scripts (PyPT)'
echo -n "Version number: "
read version
echo $version | grep '^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}$' > /dev/null
if [[ $? != 0 ]]; then
echo $version | grep '^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}\-[0-9A-Za-z-]\{1,\}$' > /dev/null
if [[ $? != 0 ]]; then
warning 'version number is not compliant with versioning scheme (Semantic Versioning 2.0)'
echo -n 'Continue? [y/N] '
read vercont
if [[ $vercont == 'y' || $vercont == 'Y' ]]; then
echo 'Continuing.'
else
exit 2
fi
else
status 'NOTICE: pre-release version number in use.'
echo -n 'Continue? [Y/n] '
read vercont
if [[ $vercont == 'n' || $vercont == 'N' ]]; then
exit 2
else
echo 'Continuing.'
fi
fi
fi
# Creating all the dates at the exact same time.
date=$(date '+%Y-%m-%d')
datel=$(date '+%Y-%m-%d %H:%M%z')
#datep=$(date '+%Y%m%d')
dates=$(date '+%s')
cmfn=$PWD/.git/kwrs-$dates
cmfn2=$cmfn"-commit"
cleanup
cleanup_cmfn
git add -A --ignore-errors .
cat > $cmfn <<EOF
#~ Chris Warrick’s Release Scripts (PyPT)
#~ Please write your commit and changelog messages.
#~ You may use reST formatting in the latter.
#~ Please make the first line of your commit message short.
#~ The second line of multi-line commits should be empty.
#~ COMMIT MESSAGE START ~#
#~version~#
#~ COMMIT MESSAGE END ~#
#~ CHANGELOG MESSAGE START ~#
#~ CHANGELOG MESSAGE END ~#
#~~~#
EOF
sed -i "s/#~version~#/v$version: /" $cmfn
git status >> $cmfn
if [[ "$EDITOR" == 'vim' || "$EDITOR" == '/usr/bin/vim' ]]; then
$EDITOR -c 'set filetype=gitcommit' $cmfn
elif [[ $EDITOR == '' ]]; then
vim -c 'set filetype=gitcommit' $cmfn
else
$EDITOR $cmfn
fi
.pypt/commitlog $cmfn $PWD $version
status 'Replacing versions and dates in files...'
sed "s/version=.*/version='$version',/g" setup.py -i
sed "s/version = .*/version = '$version'/g" docs/conf.py -i
sed "s/release = .*/release = '$version'/g" docs/conf.py -i
sed "s/:Version: .*/:Version: $version/g" docs/**/*.rst -i
sed "s/# $PROJECT v.*/# $PROJECT v$version/" $PROJECTLC/**/*.py -i
sed "s/__version__ = .*/__version__ = '$version'/g" $PROJECTLC/__init__.py -i
sed "s/:Date: .*/:Date: $date/g" docs/*.rst -i
[[ -e "PKGBUILD" ]] && sed "s/pkgver=.*/pkgver=$version/g" PKGBUILD -i || true
[[ -e "PKGBUILD-git" ]] && sed "s/pkgver=.*/pkgver=$version/g" PKGBUILD-git -i || true
cp docs/README.rst docs/CHANGELOG.rst docs/CONTRIBUTING.rst .
cp docs/README.rst README
status 'Generating locales...'
./.pypt/localegen
status 'Importing...'
python -c "import $PROJECTLC"
if [[ $? != 0 ]]; then
error "Import failed. Fix your code or don't come back."
exit 1
fi
if [[ -e tests ]]; then
status 'Running tests...'
pytest tests/
if [[ $? != 0 ]]; then
error "Tests failed. Fix your code or don't come back."
exit 1
fi
fi
status 'Running pre-sdist.hook...'
. .pypt/hooks/pre-sdist.hook
status 'This is the last chance to quit. Hit ^C now if you want to.'
read bailout
./setup.py sdist bdist_wheel || exit $?
twine upload -s dist/$PROJECTLC-$version.tar.gz dist/$PROJECTLC-$version*.whl || exit $?
if [[ -e PKGBUILD ]]; then
status 'Updating AUR PKGBUILDs...'
md5out=$(md5sum 'dist/'$PROJECTLC'-'$version'.tar.gz'|awk '{print $1}')
sed "s/md5sums=.*/md5sums=('$md5out')/" PKGBUILD -i
fi
cleanup
git add -A --ignore-errors . || exit $?
git commit -S -asF $cmfn2 || exit $?
git tag -sm "Version $version" v$version || exit $?
git push --follow-tags origin master || exit $?
.pypt/ghrel $cmfn $PWD $GITUSER/$GITREPO v$version
cleanup_cmfn
status "Done!"
. .pypt/hooks/post-release.hook