This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
forked from libratbag/libratbag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·459 lines (404 loc) · 14 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
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#!/bin/bash
#
# Generate the announce template
#
# Completely copy/paste of Xorg/util/modular/release.sh:
#
# Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
export LC_ALL=C
#------------------------------------------------------------------------------
# Function: check_local_changes
#------------------------------------------------------------------------------
#
check_local_changes() {
git diff --quiet HEAD > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo ""
echo "Uncommitted changes found. Did you forget to commit? Aborting."
echo ""
echo "You can perform a 'git stash' to save your local changes and"
echo "a 'git stash apply' to recover them after the tarball release."
echo "Make sure to rebuild and run 'make distcheck' again."
echo ""
echo "Alternatively, you can clone the module in another directory"
echo "and run ./configure. No need to build if testing was finished."
echo ""
return 1
fi
return 0
}
#------------------------------------------------------------------------------
# Function: check_option_args
#------------------------------------------------------------------------------
#
# perform sanity checks on cmdline args which require arguments
# arguments:
# $1 - the option being examined
# $2 - the argument to the option
# returns:
# if it returns, everything is good
# otherwise it exit's
check_option_args() {
option=$1
arg=$2
# check for an argument
if [ x"$arg" = x ]; then
echo ""
echo "Error: the '$option' option is missing its required argument."
echo ""
usage
exit 1
fi
# does the argument look like an option?
echo $arg | $GREP "^-" > /dev/null
if [ $? -eq 0 ]; then
echo ""
echo "Error: the argument '$arg' of option '$option' looks like an option itself."
echo ""
usage
exit 1
fi
}
#------------------------------------------------------------------------------
# Function: check_modules_specification
#------------------------------------------------------------------------------
#
check_modules_specification() {
if [ x"${INPUT_MODULES}" = x ]; then
echo ""
echo "Error: no modules specified (blank command line)."
usage
exit 1
fi
}
#------------------------------------------------------------------------------
# Function: generate_announce
#------------------------------------------------------------------------------
#
generate_announce()
{
cat <<RELEASE
Subject: [ANNOUNCE] $pkg_name $pkg_version
To: $list_to
Cc: $list_cc
$pkg_name $tag_name is out.
The list of interesting changes are:
See the full log at the end if you are interested in the details.
`git log --no-merges "$tag_range" | git shortlog`
git tag: $tag_name
RELEASE
for tarball in $tarbz2 $targz $tarxz; do
cat <<RELEASE
The libratbag project does not generate tarballs for releases, you can
grab one directly from github:
https://github.com/libratbag/$pkg_name/archive/$tag_name/$tarball
RELEASE
done
}
#------------------------------------------------------------------------------
# Function: print_epilog
#------------------------------------------------------------------------------
#
print_epilog() {
epilog="======== Successful Completion"
if [ x"$NO_QUIT" != x ]; then
if [ x"$failed_modules" != x ]; then
epilog="======== Partial Completion"
fi
elif [ x"$failed_modules" != x ]; then
epilog="======== Stopped on Error"
fi
echo ""
echo "$epilog `date`"
# Report about modules that failed for one reason or another
if [ x"$failed_modules" != x ]; then
echo " List of failed modules:"
for mod in $failed_modules; do
echo " $mod"
done
echo "========"
echo ""
fi
}
#------------------------------------------------------------------------------
# Function: process_modules
#------------------------------------------------------------------------------
#
# Loop through each module to release
# Exit on error if --no-quit was not specified
#
process_modules() {
for MODULE_RPATH in ${INPUT_MODULES}; do
if ! process_module ; then
echo "Error: processing module \"$MODULE_RPATH\" failed."
failed_modules="$failed_modules $MODULE_RPATH"
if [ x"$NO_QUIT" = x ]; then
print_epilog
exit 1
fi
fi
done
}
#------------------------------------------------------------------------------
# Function: process_module
#------------------------------------------------------------------------------
# Code 'return 0' on success to process the next module
# Code 'return 1' on error to process next module if invoked with --no-quit
#
process_module() {
top_src=`pwd`
echo ""
echo "======== Processing \"$top_src/$MODULE_RPATH\""
# This is the location where the script has been invoked
if [ ! -d $MODULE_RPATH ] ; then
echo "Error: $MODULE_RPATH cannot be found under $top_src."
return 1
fi
# Change directory to be in the git module
cd $MODULE_RPATH
if [ $? -ne 0 ]; then
echo "Error: failed to cd to $MODULE_RPATH."
return 1
fi
# ----- Now in the git module *root* directory ----- #
# Check that this is indeed a git module
if [ ! -d .git ]; then
echo "Error: there is no git module here: `pwd`"
return 1
fi
# Check for uncommitted/queued changes.
check_local_changes
if [ $? -ne 0 ]; then
cd $top_src
return 1
fi
# Determine what is the current branch and the remote name
current_branch=`git branch | $GREP "\*" | sed -e "s/\* //"`
remote_name=`git config --get branch.$current_branch.remote`
remote_branch=`git config --get branch.$current_branch.merge | cut -d'/' -f3,4`
echo "Info: working off the \"$current_branch\" branch tracking the remote \"$remote_name/$remote_branch\"."
# Find out the tarname from meson.build
pkg_name=$($GREP '^project(' meson.build | sed 's|project(\([^\s,]*\).*|\1|' | sed "s/'//g")
pkg_version=$($GREP -m 1 '^[ ]*version \?: ' meson.build | sed 's|[ ]*version \?: \([^\s,]*\).*|\1|' | sed "s/'//g")
tar_name="$pkg_name-$pkg_version"
targz=$tar_name.tar.gz
# libratbag tags with v0.3 but piper user just 0.3
case `git describe` in
v*)
tag_name=$(echo "v$pkg_version" | sed 's|\.0$||')
;;
*)
tag_name=$(echo "$pkg_version" | sed 's|\.0$||')
;;
esac
remote_url_root="https://github.com/libratbag/$pkg_name/archive"
# Now get the tarballs from github directly to compute their checksum
remote_targz_url=$remote_url_root/$tag_name/$targz
echo "downloading the tarball from $remote_targz_url"
curl $remote_targz_url > $targz
# Obtain the top commit SHA which should be the version bump
# It should not have been tagged yet (the script will do it later)
local_top_commit_sha=`git rev-list --max-count=1 HEAD`
if [ $? -ne 0 ]; then
echo "Error: unable to obtain the local top commit id."
cd $top_src
return 1
fi
# Check that the top commit looks like a version bump
git diff --unified=0 HEAD^ | $GREP -F $pkg_version >/dev/null 2>&1
if [ $? -ne 0 ]; then
# Wayland repos use m4_define([wayland_major_version], [0])
git diff --unified=0 HEAD^ | $GREP -E "(major|minor|micro)_version" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: the local top commit does not look like a version bump."
echo " the diff does not contain the string \"$pkg_version\"."
local_top_commit_descr=`git log --oneline --max-count=1 $local_top_commit_sha`
echo " the local top commit is: \"$local_top_commit_descr\""
cd $top_src
return 1
fi
fi
# Check that the top commit has been pushed to remote
remote_top_commit_sha=`git rev-list --max-count=1 $remote_name/$remote_branch`
if [ $? -ne 0 ]; then
echo "Error: unable to obtain top commit from the remote repository."
cd $top_src
return 1
fi
if [ x"$remote_top_commit_sha" != x"$local_top_commit_sha" ]; then
echo "Error: the local top commit has not been pushed to the remote."
local_top_commit_descr=`git log --oneline --max-count=1 $local_top_commit_sha`
echo " the local top commit is: \"$local_top_commit_descr\""
cd $top_src
return 1
fi
# If a tag exists with the the tar name, ensure it is tagging the top commit
# It may happen if the version set in configure.ac has been previously released
tagged_commit_sha=`git rev-list --max-count=1 $tag_name 2>/dev/null`
if [ $? -eq 0 ]; then
# Check if the tag is pointing to the top commit
if [ x"$tagged_commit_sha" != x"$remote_top_commit_sha" ]; then
echo "Error: the \"$tag_name\" already exists."
echo " this tag is not tagging the top commit."
remote_top_commit_descr=`git log --oneline --max-count=1 $remote_top_commit_sha`
echo " the top commit is: \"$remote_top_commit_descr\""
local_tag_commit_descr=`git log --oneline --max-count=1 $tagged_commit_sha`
echo " tag \"$tag_name\" is tagging some other commit: \"$local_tag_commit_descr\""
cd $top_src
return 1
else
echo "Info: module already tagged with \"$tag_name\"."
fi
else
# Tag the top commit with the tar name
if [ x"$DRY_RUN" = x ]; then
git tag -s -m $tag_name $tag_name
if [ $? -ne 0 ]; then
echo "Error: unable to tag module with \"$tag_name\"."
cd $top_src
return 1
else
echo "Info: module tagged with \"$tag_name\"."
fi
else
echo "Info: skipping the commit tagging in dry-run mode."
fi
fi
# Mailing lists where to post the all [Announce] e-mails
list_to="input-tools@lists.freedesktop.org"
# Pushing the top commit tag to the remote repository
if [ x$DRY_RUN = x ]; then
echo "Info: pushing tag \"$tag_name\" to remote \"$remote_name\":"
git push $remote_name $tag_name
if [ $? -ne 0 ]; then
echo "Error: unable to push tag \"$tag_name\" to the remote repository."
echo " it is recommended you fix this manually and not run the script again"
cd $top_src
return 1
fi
else
echo "Info: skipped pushing tag \"$tag_name\" to the remote repository in dry-run mode."
fi
# --------- Generate the announce e-mail ------------------
# Failing to generate the announce is not considered a fatal error
# Git-describe returns only "the most recent tag", it may not be the expected one
# However, we only use it for the commit history which will be the same anyway.
tag_previous=`git describe --abbrev=0 HEAD^ 2>/dev/null`
# Git fails with rc=128 if no tags can be found prior to HEAD^
if [ $? -ne 0 ]; then
if [ $? -ne 0 ]; then
echo "Warning: unable to find a previous tag."
echo " perhaps a first release on this branch."
echo " Please check the commit history in the announce."
fi
fi
if [ x"$tag_previous" != x ]; then
# The top commit may not have been tagged in dry-run mode. Use commit.
tag_range=$tag_previous..$local_top_commit_sha
else
tag_range=$tag_name
fi
generate_announce > "$tar_name.announce"
echo "Info: [ANNOUNCE] template generated in \"$tar_name.announce\" file."
echo " Please pgp sign and send it."
# --------- Successful completion --------------------------
cd $top_src
return 0
}
#------------------------------------------------------------------------------
# Function: usage
#------------------------------------------------------------------------------
# Displays the script usage and exits successfully
#
usage() {
basename="`expr "//$0" : '.*/\([^/]*\)'`"
cat <<HELP
Usage: $basename [options] path...
Where "path" is a relative path to a git module, including '.'.
Options:
--dry-run Does everything except tagging and uploading tarballs
--force Force overwriting an existing release
--help Display this help and exit successfully
--no-quit Do not quit after error; just print error message
HELP
}
#------------------------------------------------------------------------------
# Script main line
#------------------------------------------------------------------------------
#
# Choose which grep program to use (on Solaris, must be gnu grep)
if [ "x$GREP" = "x" ] ; then
if [ -x /usr/gnu/bin/grep ] ; then
GREP=/usr/gnu/bin/grep
else
GREP=grep
fi
fi
# Process command line args
while [ $# != 0 ]
do
case $1 in
# Does everything except uploading tarball
--dry-run)
DRY_RUN=yes
;;
# Force overwriting an existing release
# Use only if nothing changed in the git repo
--force)
FORCE=yes
;;
# Display this help and exit successfully
--help)
usage
exit 0
;;
# Do not quit after error; just print error message
--no-quit)
NO_QUIT=yes
;;
--*)
echo ""
echo "Error: unknown option: $1"
echo ""
usage
exit 1
;;
-*)
echo ""
echo "Error: unknown option: $1"
echo ""
usage
exit 1
;;
*)
INPUT_MODULES="${INPUT_MODULES} $1"
;;
esac
shift
done
# If no modules specified (blank cmd line) display help
check_modules_specification
# Loop through each module to release
# Exit on error if --no-quit no specified
process_modules
# Print the epilog with final status
print_epilog