-
-
Notifications
You must be signed in to change notification settings - Fork 996
/
release.sh
executable file
·207 lines (162 loc) · 4.34 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
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
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
set -e
prompt() {
echo "root: ${ROOTDIR} old: ${OLDVERSION} - new: ${NEWVERSION}"
read -n 1 -r -p "Proceed? [Y/n] " P
echo
if [ "$P" == y -o "$P" == Y -o -z "$P" ]; then
return 0
else
exit 1
fi
}
cleanup() {
cd "${ROOTDIR}"
echo Removing old build directory
if [ -d ./build ]; then
rm -rf ./build
fi
}
update() {
cd "${ROOTDIR}"
echo Updating version to ${NEWVERSION}
sed -i "s#\"${PYVERSION}\"#\"${NEWVERSION}\"#" "gallery_dl/version.py"
sed -i "s#v[0-9]\.[0-9]\+\.[0-9]\+#v${NEWVERSION}#" "${README}"
make man
}
update-dev() {
cd "${ROOTDIR}"
IFS="." read MAJOR MINOR BUILD <<< "${NEWVERSION}"
BUILD=$((BUILD+1))
# update version to -dev
sed -i "s#\"${NEWVERSION}\"#\"${MAJOR}.${MINOR}.${BUILD}-dev\"#" "gallery_dl/version.py"
git add "gallery_dl/version.py"
}
build-python() {
cd "${ROOTDIR}"
echo Building sdist and wheel
python -m build
}
build-linux() {
cd "${ROOTDIR}"
echo Building Linux executable
build-vm 'ubuntu22.04' 'gallery-dl.bin' 'linux' 24000000
}
build-windows() {
cd "${ROOTDIR}"
echo Building Windows executable
build-vm 'windows7_x86_sp1' 'gallery-dl.exe' 'windows' 12000000
}
build-vm() {
VMNAME="$1"
BINNAME="$2"
LABEL="$3"
MINSIZE="$4"
TMPPATH="/tmp/gallery-dl/dist/$BINNAME"
# launch VM
vmstart "$VMNAME" &
disown
# copy source files
mkdir -p /tmp/gallery-dl
cp -a -t /tmp/gallery-dl -- \
./gallery_dl ./scripts ./data ./setup.py ./README.rst
# update __variant__
sed -i \
-e "s#\(__variant__ *=\).*#\1 \"stable/${LABEL}\"#" \
/tmp/gallery-dl/gallery_dl/version.py
# remove old executable
rm -f "./dist/$BINNAME"
# wait for new executable
while true; do
sleep 5
if [ ! -e "$TMPPATH" ]; then
continue
fi
sleep 2
SIZE="$(stat -c %s "$TMPPATH")"
if [ "$SIZE" -lt "$MINSIZE" ]; then
echo Size of "'$TMPPATH'" is less than "$MINSIZE" bytes "($SIZE)"
rm -f "$TMPPATH"
continue
fi
break
done
# move
mv "$TMPPATH" "./dist/$BINNAME"
rm -r /tmp/gallery-dl
}
sign() {
cd "${ROOTDIR}/dist"
echo Signing files
gpg --detach-sign --armor gallery_dl-${NEWVERSION}-py3-none-any.whl
gpg --detach-sign --armor gallery_dl-${NEWVERSION}.tar.gz
gpg --detach-sign --yes gallery-dl.exe
gpg --detach-sign --yes gallery-dl.bin
}
changelog() {
cd "${ROOTDIR}"
echo Updating "${CHANGELOG}"
# - replace "#NN" with link to actual issue
# - insert new version and date
sed -i \
-e "s*\([( ]\)#\([0-9]\+\)*\1[#\2](https://github.com/mikf/gallery-dl/issues/\2)*g" \
-e "s*^## \w\+\$*## ${NEWVERSION} - $(date +%Y-%m-%d)*" \
"${CHANGELOG}"
mv "${CHANGELOG}" "${CHANGELOG}.orig"
# - remove all but the latest entries
sed -n \
-e '/^## /,/^$/ { /^$/q; p }' \
"${CHANGELOG}.orig" \
> "${CHANGELOG}"
}
supportedsites() {
cd "${ROOTDIR}"
echo Checking if "${SUPPORTEDSITES}" is up to date
./scripts/supportedsites.py
if ! git diff --quiet "${SUPPORTEDSITES}"; then
echo "updated ${SUPPORTEDSITES} contains changes"
exit 4
fi
}
upload-git() {
cd "${ROOTDIR}"
echo Pushing changes to github
mv "${CHANGELOG}.orig" "${CHANGELOG}" || true
git add "gallery_dl/version.py" "${README}" "${CHANGELOG}"
git commit -S -m "release version ${NEWVERSION}"
git tag -s -m "version ${NEWVERSION}" "v${NEWVERSION}"
git push --atomic origin master "v${NEWVERSION}"
}
upload-pypi() {
cd "${ROOTDIR}/dist"
echo Uploading to PyPI
twine upload gallery_dl-${NEWVERSION}*
}
ROOTDIR="$(realpath "$(dirname "$0")/..")/"
README="README.rst"
CHANGELOG="CHANGELOG.md"
SUPPORTEDSITES="./docs/supportedsites.md"
LASTTAG="$(git describe --abbrev=0 --tags)"
OLDVERSION="${LASTTAG#v}"
PYVERSION="$(python -c "import gallery_dl as g; print(g.__version__)")"
if [[ "$1" ]]; then
NEWVERSION="$1"
else
NEWVERSION="${PYVERSION%-dev}"
fi
if [[ ! $NEWVERSION =~ [0-9]+\.[0-9]+\.[0-9]+(-[a-z]+(\.[0-9]+)?)?$ ]]; then
echo "invalid version: $NEWVERSION"
exit 2
fi
prompt
supportedsites
cleanup
update
changelog
build-python
build-linux
build-windows
sign
upload-pypi
upload-git
update-dev