-
Notifications
You must be signed in to change notification settings - Fork 11
/
make-release.sh
executable file
·372 lines (337 loc) · 10.8 KB
/
make-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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/bin/bash
release_folder_name=odot
######################################################################
# Options, usage, etc
######################################################################
usage() {
echo "Usage: $0 -hmoptzd -n [NAME]" 1>&2
echo "Prepare a release of the odot package." 1>&2
echo "-h : Help" 1>&2
echo "-m : Copy Max/MSP externals." 1>&2
echo "-p : Copy Pure Data externals." 1>&2
echo "-o : Insert the name of the platform / OS into the archive name." 1>&2
echo "-n [NAME] : Insert [NAME] into the archive name." 1>&2
echo "-t : Produce a tarball of the release." 1>&2
echo "-z : Produce a zip file of the release." 1>&2
echo "-d : Debug" 1>&2
echo "" 1>&2
echo "Running this script will cause a fresh clone of the repo " 1>&2
echo "one level up. If that folder already exists, \`git pull\` will " 1>&2
echo "be run inside it. " 1>&2
echo "" 1>&2
echo "-m and -p will cause the built [m]ax and/or [p]d externals " 1>&2
echo "to be copied into the appropriate directories of the release. " 1>&2
echo "" 1>&2
echo "-t and -z produce a [t]arball and/or [z]ip file from the release folder." 1>&2
echo "The name of the archive will begin with 'odot' and end with the " 1>&2
echo "version string as reported by \`git describe --long\`. " 1>&2
echo "" 1>&2
echo "Specifying -m and/or -p when building an archive will cause 'Max' and/or " 1>&2
echo "'PD' to be inserted between 'odot' and the version string. " 1>&2
echo "-o will cause add the platform name (MacOSX, Windows, or Linux), " 1>&2
echo "and -n [NAME] will insert [NAME] just before the version string." 1>&2
echo "" 1>&2
echo "Process for making a release for the Max Package Manager: " 1>&2
echo "1. Build the objects on macOS. " 1>&2
echo "2. Run this script with -mz to copy the Max externals and make a zip file. " 1>&2
echo "3. Copy that zip file to the Windows build machine and unzip it " 1>&2
echo " in the folder that contains CNMAT-odot. It will produce a folder called odot. " 1>&2
echo "4. On the Windows machine, build the objects, then " 1>&2
echo "5. run this script with the -mz flags again. " 1>&2
echo " This will copy the Windows externals into the correct folders " 1>&2
echo " so that they're side-by-side the Mac externals, " 1>&2
echo " which is what is needed for the PM. " 1>&2
}
max=0
pd=0
os=0
havename=0
name=""
archive_tarball=0
archive_zip=0
debug=0
while getopts ":hmn:optzd" options; do
case "${options}" in
h)
usage
exit 0
;;
m)
max=1
;;
p)
pd=1
;;
o)
os=1
;;
n)
havename=1
name=${OPTARG}
;;
t)
archive_tarball=1
;;
z)
archive_zip=1
;;
d)
debug=1
;;
:)
usage
exit 1
;;
\?)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
######################################################################
# Make sure there is no uncommitted work in the git repo
######################################################################
require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --
then
echo >&2 "you have unstaged changes."
git diff-files --name-status -r --ignore-submodules -- >&2
err=1
fi
# Disallow uncommitted changes in the index
if ! git diff-index --cached --quiet HEAD --ignore-submodules --
then
echo >&2 "your index contains uncommitted changes."
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
err=1
fi
if [ $err = 1 ]; then
echo >&2 "Please commit or stash them."
exit 1
fi
}
if [ "$debug" = 0 ]; then
require_clean_work_tree
set -x
fi
######################################################################
# platform
######################################################################
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
platform="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
platform="MacOSX"
elif [[ "$OSTYPE" == "cygwin" ]]; then
platform="Windows"
elif [[ "$OSTYPE" == "msys" ]]; then
platform="Windows"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
platform="FreeBSD"
else
platform=""
fi
######################################################################
# If the -m or -p swiches are present, clone a fresh copy of the repo
# into a folder called 'odot', and copy the [m]ax or [p]d externs
# into the appropriate locations.
######################################################################
if [ -d "../$release_folder_name" ]; then
remote=`pwd`
(cd "../$release_folder_name" \
&& git remote remove origin \
&& git remote add origin "$remote" \
&& git pull origin master \
&& require_clean_work_tree)
else
git clone . "../$release_folder_name"
fi
copy_externs() {
if [ "$max" = 1 ]; then
echo "copying Max externals"
echo cp -r externals "../$release_folder_name/"
cp -r externals "../$release_folder_name/"
echo cp -r dev/externals "../$release_folder_name/dev/"
cp -r dev/externals "../$release_folder_name/dev/"
echo cp -r deprecated/externals "../$release_folder_name/deprecated/"
cp -r deprecated/externals "../$release_folder_name/deprecated/"
fi
if [ "$pd" = 1 ]; then
echo "copying PD externals"
ext="*.pd_*"
if [ "$platform" = "Windows" ]; then
ext="*.dll"
fi
echo cp -r pd/$ext "../$release_folder_name/pd/"
cp -r pd/$ext "../$release_folder_name/pd/"
echo cp -r pd/dev/$ext "../$release_folder_name/pd/dev/"
cp -r pd/dev/$ext "../$release_folder_name/pd/dev/"
echo cp -r pd/deprecated/$ext "../$release_folder_name/pd/deprecated/"
cp -r pd/deprecated/$ext "../$release_folder_name/pd/deprecated/"
fi
}
copy_externs
######################################################################
# Remove any source code, scripts, internal stuff from the release
######################################################################
# clean_release() {
# echo "cleaning up release"
# if [ "$pd" = 0 ]; then
# files_to_delete+=( "pd" )
# fi
# for i in "${!files_to_delete[@]}"; do
# echo rm -rf "../${release_folder_name}/${files_to_delete[$i]}"
# rm -rf "../${release_folder_name}/${files_to_delete[$i]}"
# done
# }
#clean_release
if [ "$pd" = 0 ]; then
echo "*/pd/*" >> "../${release_folder_name}/release-excludes.txt"
fi
######################################################################
# Make package-info.json
######################################################################
open_obj() { echo "{" >> "$1"; }
close_obj() { echo "}" >> "$1"; }
open_list() { echo -n "[" >> "$1"; }
close_list() { echo -n "]" >> "$1"; }
end_entry() { echo "," >> "$1"; }
write_key() { echo -n "\"$2\" : " >> "$1"; }
write_val() { echo -n "\"$2\"" >> "$1"; }
write_list() {
f="$1"
shift
n="$#"
for ((i = 0; i < $n - 1; i++)); do
echo -n "\"$1\"," >> "$f"
shift
done
echo -n "\"$1\"" >> "$f"
}
write_simple_entry() {
write_key "$1" "$2"
write_val "$1" "$3"
end_entry "$1"
}
write_final_entry() {
write_key "$1" "$2"
write_val "$1" "$3"
echo "" >> "$1"
}
write_list_entry() {
f="$1"
shift
write_key "$f" "$1"
shift
open_list "$f"
write_list "$f" "$@"
close_list "$f"
end_entry "$f"
}
write_package_info() {
echo "writing package-info.json"
f="package-info.json"
(
cd "../$release_folder_name"
touch "$f"
open_obj "$f"
write_simple_entry "$f" "author" "CNMAT"
write_list_entry "$f" "authors" "John MacCallum" "Adrian Freed" "Rama Gottfried" "Ilya Rostovtsev"
write_simple_entry "$f" "description" "Dynamic programming environment for OSC in Max"
write_simple_entry "$f" "homepatcher" "o.start.here.maxpat"
write_simple_entry "$f" "max_version_max" "none"
write_simple_entry "$f" "max_version_min" "7.0"
write_simple_entry "$f" "name" "odot"
write_key "$f" "os"
open_obj "$f"
write_key "$f" "macintosh"
open_obj "$f"
write_list_entry "$f" "platform" "x64"
write_final_entry "$f" "min_version" "10.10.x"
close_obj "$f"
end_entry "$f"
write_key "$f" "windows"
open_obj "$f"
write_list_entry "$f" "platform" "x64"
write_final_entry "$f" "min_version" "7"
close_obj "$f"
close_obj "$f"
end_entry "$f"
write_key "$f" "package_extras"
open_obj "$f"
write_simple_entry "$f" "reverse_domain" "edu.berkeley.cnmat"
write_final_entry "$f" "copyright" "Copyright (c) 2007-21 UC Regents"
close_obj "$f"
end_entry "$f"
write_list_entry "$f" "tags" "Open Sound Control" "OSC" "Dynamic Programming" "CNMAT"
write_simple_entry "$f" "version" "$version"
write_final_entry "$f" "website" "https://github.com/CNMAT/CNMAT-odot"
close_obj "$f"
)
}
write_package_info
######################################################################
# Produce the archive(s) if -z or -t are present
######################################################################
archive_name="odot"
version=`git describe --tags`
if [ "$max" = 1 ]; then
archive_name="${archive_name}-Max"
fi
if [ "$pd" = 1 ]; then
archive_name="${archive_name}-PD"
fi
if [ "$os" = 1 ]; then
archive_name="${archive_name}-${platform}"
fi
if [ "$havename" = 1 ]; then
archive_name="${archive_name}-${name}"
fi
archive_name="${archive_name}-${version}"
if [ "$archive_zip" = 1 ]; then
(
archive_name="${archive_name}.zip"
if [ -e "../$archive_name" ]; then
echo "file $archive_name already exists" 1>&2
else
if [ $max = 0 ] && [ $pd = 1 ]; then
cd ..
mv "$release_folder_name" "${release_folder_name}.___"
cp -r "${release_folder_name}.___/pd" "$release_folder_name"
zip -r -X "$archive_name" "$release_folder_name"
rm -rf "$release_folder_name"
mv "${release_folder_name}.___" "$release_folder_name"
else
cd .. && zip -r -X "$archive_name" "$release_folder_name" "-x@${release_folder_name}/release-excludes.txt"
fi
fi
)
fi
if [ "$archive_tarball" = 1 ]; then
(
archive_name="${archive_name}.tgz"
if [ -e "../$archive_name" ]; then
echo "file $archive_name already exists" 1>&2
else
if [ $max = 0 ] && [ $pd = 1 ]; then
cd ..
mv "$release_folder_name" "${release_folder_name}.___"
cp -r "${release_folder_name}.___/pd" "$release_folder_name"
tar zcvf "$archive_name" "$release_folder_name"
rm -rf "$release_folder_name"
mv "${release_folder_name}.___" "$release_folder_name"
else
cd .. && tar zcvf "$archive_name" "-X${release_folder_name}/release-excludes.txt" "$release_folder_name"
fi
fi
)
fi
# if we didn't do a pd build, we will have appended the pd dir to
# release-excludes.txt, so we check it back out here
(
cd "../$release_folder_name" && git checkout release-excludes.txt
)