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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
#!/bin/sh
#
# Creates and upload a git module tarball
#
# Note on portability:
# This script is intended to run on any platform supported by X.Org.
# Basically, it should be able to run in a Bourne shell.
#
#
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"$MODFILE" = x ]; then
if [ x"${INPUT_MODULES}" = x ]; then
echo ""
echo "Error: no modules specified (blank command line)."
usage
exit 1
fi
fi
}
#------------------------------------------------------------------------------
# Function: generate_announce
#------------------------------------------------------------------------------
#
generate_announce()
{
cat <<RELEASE
Subject: [ANNOUNCE] $pkg_name $pkg_version
To: $list_to
CC: $list_cc
`git log --no-merges "$tag_range" | git shortlog`
git tag: $tar_name
http://$host_current/$section_path/$tarbz2
MD5: `$MD5SUM $tarbz2`
SHA1: `$SHA1SUM $tarbz2`
SHA256: `$SHA256SUM $tarbz2`
http://$host_current/$section_path/$targz
MD5: `$MD5SUM $targz`
SHA1: `$SHA1SUM $targz`
SHA256: `$SHA256SUM $targz`
RELEASE
}
#------------------------------------------------------------------------------
# Function: read_modfile
#------------------------------------------------------------------------------
#
# Read the module names from the file and set a variable to hold them
# This will be the same interface as cmd line supplied modules
#
read_modfile() {
if [ x"$MODFILE" != x ]; then
# Make sure the file is sane
if [ ! -r "$MODFILE" ]; then
echo "Error: module file '$MODFILE' is not readable or does not exist."
exit 1
fi
# read from input file, skipping blank and comment lines
while read line; do
# skip blank lines
if [ x"$line" = x ]; then
continue
fi
# skip comment lines
if echo "$line" | $GREP -q "^#" ; then
continue;
fi
INPUT_MODULES="$INPUT_MODULES $line"
done <"$MODFILE"
fi
return 0
}
#------------------------------------------------------------------------------
# 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
# Change directory to be in the git build directory (could be out-of-source)
# More than one can be found when distcheck has run and failed
configNum=`find . -name config.status -type f | wc -l | sed 's:^ *::'`
if [ $? -ne 0 ]; then
echo "Error: failed to locate config.status."
echo "Has the module been configured?"
return 1
fi
if [ x"$configNum" = x0 ]; then
echo "Error: failed to locate config.status, has the module been configured?"
return 1
fi
if [ x"$configNum" != x1 ]; then
echo "Error: more than one config.status file was found,"
echo " clean-up previously failed attempts at distcheck"
return 1
fi
status_file=`find . -name config.status -type f`
if [ $? -ne 0 ]; then
echo "Error: failed to locate config.status."
echo "Has the module been configured?"
return 1
fi
build_dir=`dirname $status_file`
cd $build_dir
if [ $? -ne 0 ]; then
echo "Error: failed to cd to $MODULE_RPATH/$build_dir."
cd $top_src
return 1
fi
# ----- Now in the git module *build* directory ----- #
# 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`
echo "Info: working off the \"$current_branch\" branch tracking the remote \"$remote_name\"."
# Run 'make dist/distcheck' to ensure the tarball matches the git module content
# Important to run make dist/distcheck before looking in Makefile, may need to reconfigure
echo "Info: running \"make $MAKE_DIST_CMD\" to create tarballs:"
${MAKE} $MAKEFLAGS $MAKE_DIST_CMD > /dev/null
if [ $? -ne 0 ]; then
echo "Error: \"$MAKE $MAKEFLAGS $MAKE_DIST_CMD\" failed."
cd $top_src
return 1
fi
# Find out the tarname from the makefile
pkg_name=`$GREP '^PACKAGE = ' Makefile | sed 's|PACKAGE = ||'`
pkg_version=`$GREP '^VERSION = ' Makefile | sed 's|VERSION = ||'`
tar_name="$pkg_name-$pkg_version"
targz=$tar_name.tar.gz
tarbz2=$tar_name.tar.bz2
ls -l $targz
ls -l $tarbz2
# 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
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
# Check that the top commit has been pushed to remote
remote_top_commit_sha=`git rev-list --max-count=1 $remote_name/$current_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 $tar_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 \"$tar_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 \"$tar_name\" is tagging some other commit: \"$local_tag_commit_descr\""
cd $top_src
return 1
else
echo "Info: module already tagged with \"$tar_name\"."
fi
else
# Tag the top commit with the tar name
if [ x"$DRY_RUN" = x ]; then
git tag -m $tar_name $tar_name
if [ $? -ne 0 ]; then
echo "Error: unable to tag module with \"$tar_name\"."
cd $top_src
return 1
else
echo "Info: module tagged with \"$tar_name\"."
fi
else
echo "Info: skipping the commit tagging in dry-run mode."
fi
fi
# --------- Now the tarballs are ready to upload ----------
# The hostname which is used to connect to the development resources
hostname="annarchy.freedesktop.org"
# Some hostnames are also used as /srv subdirs
host_xorg="xorg.freedesktop.org"
host_dri="dri.freedesktop.org"
# Mailing lists where to post the all [Announce] e-mails
list_to="xorg-announce@lists.freedesktop.org"
# Mailing lists to be CC according to the project (xorg|dri|xkb)
list_xorg_user="xorg@lists.freedesktop.org"
list_dri_devel="dri-devel@lists.freedesktop.net"
list_xkb="xkb@listserv.bat.ru"
list_xcb="xcb@lists.freedesktop.org"
# Obtain the git url in order to find the section to which this module belongs
full_module_url=`git config --get remote.$remote_name.url | sed 's:\.git$::'`
if [ $? -ne 0 ]; then
echo "Error: unable to obtain git url for remote \"$remote_name\"."
cd $top_src
return 1
fi
# The last part of the git url will tell us the section. Look for xorg first
echo "$full_module_url"
module_url=`echo "$full_module_url" | $GREP -o "/xorg/.*"`
if [ $? -eq 0 ]; then
module_url=`echo $module_url | cut -d'/' -f3,4`
else
# The look for mesa, xcb, etc...
module_url=`echo "$full_module_url" | $GREP -o -e "/mesa/.*" -e "/xcb/.*" -e "/xkeyboard-config"`
if [ $? -eq 0 ]; then
module_url=`echo $module_url | cut -d'/' -f2,3`
else
echo "Error: unable to locate a valid project url from \"$full_module_url\"."
echo "Cannot establish url as one of xorg, mesa, xcb or xkeyboard-config."
cd $top_src
return 1
fi
fi
# Find the section (subdirs) where the tarballs are to be uploaded
# The module relative path can be app/xfs, xserver, or mesa/drm for example
section=`echo $module_url | cut -d'/' -f1`
if [ $? -ne 0 ]; then
echo "Error: unable to extract section from $module_url first field."
cd $top_src
return 1
else
host_current=$host_xorg
section_path=archive/individual/$section
srv_path="/srv/$host_current/$section_path"
list_cc=$list_xorg_user
fi
# Handle special cases such as non xorg projects or migrated xorg projects
# Xcb has a separate mailing list
if [ x"$section" = xxcb ]; then
list_cc=$list_xcb
fi
# Module mesa/drm goes in the dri "libdrm" section
if [ x"$section" = xmesa ]; then
section=`echo $module_url | cut -d'/' -f2`
if [ $? -ne 0 ]; then
echo "Error: unable to extract section from $module_url second field."
cd $top_src
return 1
elif [ x"$section" = xdrm ]; then
host_current=$host_dri
section_path=www/libdrm
srv_path="/srv/$host_current/$section_path"
list_cc=$list_dri_devel
else
echo "Error: section $section is not supported, only libdrm is."
cd $top_src
return 1
fi
fi
# Module xkeyboard-config goes in a subdir of the xorg "data" section
if [ x"$section" = xxkeyboard-config ]; then
host_current=$host_xorg
section_path=archive/individual/data/$section
srv_path="/srv/$host_current/$section_path"
list_cc=$list_xkb
fi
# Use personal web space on the host for unit testing (leave commented out)
# srv_path="~/public_html$srv_path"
# Check that the server path actually does exist
ssh $USER_NAME$hostname ls $srv_path >/dev/null 2>&1 ||
if [ $? -ne 0 ]; then
echo "Error: the path \"$srv_path\" on the web server does not exist."
cd $top_src
return 1
fi
# Check for already existing tarballs
ssh $USER_NAME$hostname ls $srv_path/$targz >/dev/null 2>&1 ||
ssh $USER_NAME$hostname ls $srv_path/$tarbz2 >/dev/null 2>&1
if [ $? -eq 0 ]; then
if [ "x$FORCE" = "xyes" ]; then
echo "Warning: overwriting released tarballs due to --force option."
else
echo "Error: tarball $tar_name already exists. Use --force to overwrite."
cd $top_src
return 1
fi
fi
# Upload to host using the 'scp' remote file copy program
if [ x"$DRY_RUN" = x ]; then
echo "Info: uploading tarballs to web server:"
scp $targz $tarbz2 $USER_NAME@$hostname:$srv_path
if [ $? -ne 0 ]; then
echo "Error: the tarballs uploading failed."
cd $top_src
return 1
fi
else
echo "Info: skipping tarballs uploading in dry-run mode."
echo " \"$srv_path\"."
fi
# Pushing the top commit tag to the remote repository
if [ x$DRY_RUN = x ]; then
echo "Info: pushing tag \"$tar_name\" to remote \"$remote_name\":"
git push $remote_name $tar_name
if [ $? -ne 0 ]; then
echo "Error: unable to push tag \"$tar_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 \"$tar_name\" to the remote repository in dry-run mode."
fi
MD5SUM=`which md5sum || which gmd5sum`
SHA1SUM=`which sha1sum || which gsha1sum`
SHA256SUM=`which sha256sum || which gsha256sum`
# --------- 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=$tar_name
fi
generate_announce > "$tar_name.announce"
echo "Info: [ANNOUNCE] template generated in \"$tar_name.announce\" file."
echo " Please pgp sign and send it."
# --------- Update the JH Build moduleset -----------------
# Failing to update the jh moduleset is not considered a fatal error
if [ x"$JH_MODULESET" != x ]; then
if [ x$DRY_RUN = x ]; then
sha1sum=`$SHA1SUM $targz | cut -d' ' -f1`
$top_src/util/modular/update-moduleset.sh $JH_MODULESET $sha1sum $targz
echo "Info: updated jh moduleset: \"$JH_MODULESET\""
else
echo "Info: skipping jh moduleset \"$JH_MODULESET\" update in dry-run mode."
fi
fi
# --------- 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:
--distcheck Use 'distcheck' rather than 'dist' to create tarballs
--dry-run Does everything except tagging and uploading tarballs
--force Force overwriting an existing release
--help Display this help and exit successfully
--modfile <file> Release the git modules specified in <file>
--moduleset <file> The jhbuild moduleset full pathname to be updated
--no-quit Do not quit after error; just print error message
--user <name> Username of your fdo account if not configured in ssh
Environment variables defined by the "make" program and used by release.sh:
MAKE The name of the make command [make]
MAKEFLAGS: Options to pass to all \$(MAKE) invocations
HELP
}
#------------------------------------------------------------------------------
# Script main line
#------------------------------------------------------------------------------
#
# Choose which make program to use (could be gmake)
MAKE=${MAKE:="make"}
# 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
# Set the default make tarball creation command
MAKE_DIST_CMD=dist
# Process command line args
while [ $# != 0 ]
do
case $1 in
# Use 'distcheck' rather than 'dist' to create tarballs
--distcheck)
MAKE_DIST_CMD=distcheck
;;
# 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
;;
# Release the git modules specified in <file>
--modfile)
check_option_args $1 $2
shift
MODFILE=$1
;;
# The jhbuild moduleset to update with relase info
--moduleset)
check_option_args $1 $2
shift
JH_MODULESET=$1
;;
# Do not quit after error; just print error message
--no-quit)
NO_QUIT=yes
;;
# Username of your fdo account if not configured in ssh
--user)
check_option_args $1 $2
shift
USER_NAME=$1
;;
--*)
echo ""
echo "Error: unknown option: $1"
echo ""
usage
exit 1
;;
-*)
echo ""
echo "Error: unknown option: $1"
echo ""
usage
exit 1
;;
*)
if [ x"${MODFILE}" != x ]; then
echo ""
echo "Error: specifying both modules and --modfile is not permitted"
echo ""
usage
exit 1
fi
INPUT_MODULES="${INPUT_MODULES} $1"
;;
esac
shift
done
# If no modules specified (blank cmd line) display help
check_modules_specification
# Read the module file and normalize input in INPUT_MODULES
read_modfile
# Loop through each module to release
# Exit on error if --no-quit no specified
process_modules
# Print the epilog with final status
print_epilog
|