Enhanced the release scripts to be able to handle a branch release.
[rsync/rsync.git] / packaging / release-rsync
... / ...
CommitLineData
1#!/usr/bin/perl
2use strict;
3
4# This script expects the directory ~/samba-rsync-ftp to exist and to be a
5# copy of the /home/ftp/pub/rsync dir on samba.org. When the script is done,
6# the git repository in the current directory will be updated, and the local
7# ~/samba-rsync-ftp dir will be ready to be rsynced to samba.org.
8
9use Cwd;
10use Getopt::Long;
11use Term::ReadKey;
12use Date::Format;
13
14my $dest = $ENV{HOME} . '/samba-rsync-ftp';
15my $passfile = $ENV{HOME} . '/.rsyncpass';
16my $path = $ENV{PATH};
17
18&Getopt::Long::Configure('bundling');
19&usage if !&GetOptions(
20 'branch|b=s' => \( my $master_branch = 'master' ),
21 'help|h' => \( my $help_opt ),
22);
23&usage if $help_opt;
24
25my $now = time;
26my $cl_today = time2str('* %a %b %d %Y', $now);
27my $year = time2str('%Y', $now);
28my $ztoday = time2str('%d %b %Y', $now);
29(my $today = $ztoday) =~ s/^0//;
30
31my $curdir = Cwd::cwd;
32
33END {
34 unlink($passfile);
35}
36
37my @extra_files;
38open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
39while (<IN>) {
40 if (s/^GENFILES=//) {
41 while (s/\\$//) {
42 $_ .= <IN>;
43 }
44 @extra_files = split(' ', $_);
45 last;
46 }
47}
48close IN;
49
50my $break = <<EOT;
51==========================================================================
52EOT
53
54print $break, <<EOT, $break, "\n";
55== This will release a new version of rsync onto an unsuspecting world. ==
56EOT
57
58die "$dest does not exist\n" unless -d $dest;
59die "There is no .git dir in the current directory.\n" unless -d '.git';
60die "'a' must not exist in the current directory.\n" if -e 'a';
61die "'b' must not exist in the current directory.\n" if -e 'b';
62
63open(IN, '-|', 'git status') or die $!;
64my $status = join('', <IN>);
65close IN;
66die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
67die "The checkout is not on the $master_branch branch.\n" unless $status =~ /^# On branch $master_branch\n/;
68
69my $confversion;
70open(IN, '<', 'configure.in') or die $!;
71while (<IN>) {
72 if (/^RSYNC_VERSION=(.*)/) {
73 $confversion = $1;
74 last;
75 }
76}
77close IN;
78die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion;
79
80open(IN, '<', 'OLDNEWS') or die $!;
81$_ = <IN>;
82close IN;
83my($lastversion) = /(\d+\.\d+\.\d+)/;
84
85my $version = $confversion;
86$version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
87
88print "Please enter the version number of this release: [$version] ";
89chomp($_ = <STDIN>);
90if ($_ eq '.') {
91 $version =~ s/pre\d+//;
92} elsif ($_ ne '') {
93 $version = $_;
94}
95die "Invalid version: `$version'\n" unless $version =~ /^[\d.]+(pre\d+)?$/;
96
97if (`git tag -l v$version` ne '') {
98 print "Tag v$version already exists.\n\nDelete tag or quit? [q/del] ";
99 $_ = <STDIN>;
100 exit 1 unless /^del/i;
101 system "git tag -d v$version";
102}
103
104if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) {
105 $lastversion = $confversion;
106}
107
108print "Enter the previous version to produce a patch against: [$lastversion] ";
109chomp($_ = <STDIN>);
110$lastversion = $_ if $_ ne '';
111$lastversion =~ s/[-.]*pre[-.]*/pre/;
112
113my $pre = $version =~ /(pre\d+)/ ? $1 : '';
114
115my $release = $pre ? '0.1' : '1';
116print "Please enter the RPM release number of this release: [$release] ";
117chomp($_ = <STDIN>);
118$release = $_ if $_ ne '';
119$release .= ".$pre" if $pre;
120
121my($srcdir,$srcdiffdir,$lastsrcdir,$skipping);
122if ($lastversion =~ /pre/) {
123 if (!$pre) {
124 die "You should not diff a release version against a pre-release version.\n";
125 }
126 $srcdir = $srcdiffdir = $lastsrcdir = 'src-previews';
127 $skipping = ' ** SKIPPING **';
128} elsif ($pre) {
129 $srcdir = $srcdiffdir = 'src-previews';
130 $lastsrcdir = 'src';
131 $skipping = ' ** SKIPPING **';
132} else {
133 $srcdir = $lastsrcdir = 'src';
134 $srcdiffdir = 'src-diffs';
135 $skipping = '';
136}
137
138print "\n", $break, <<EOT;
139\$version is "$version"
140\$lastversion is "$lastversion"
141\$dest is "$dest"
142\$curdir is "$curdir"
143\$srcdir is "$srcdir"
144\$srcdiffdir is "$srcdiffdir"
145\$lastsrcdir is "$lastsrcdir"
146\$release is "$release"
147
148About to:
149 - make sure that SUBPROTOCOL_VERSION is 0$skipping
150 - tweak the version in configure.in and the spec files
151 - tweak NEWS and OLDNEWS to update the release date$skipping
152 - tweak the date in the *.yo files and generate the manpages
153 - generate configure.sh, config.h.in, and proto.h
154 - page through the differences
155
156EOT
157print "<Press Enter to continue> ";
158$_ = <STDIN>;
159
160(my $finalversion = $version) =~ s/pre\d+//;
161my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release,
162 '%define fullversion' => "\%{version}$pre", 'Released' => "$version.",
163 '%define srcdir' => $srcdir );
164my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'),
165 qw( configure.in rsync.h NEWS OLDNEWS options.c ) );
166
167foreach my $fn (@tweak_files) {
168 open(IN, '<', $fn) or die $!;
169 undef $/; $_ = <IN>; $/ = "\n";
170 close IN;
171 if ($fn =~ /configure/) {
172 s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m
173 or die "Unable to update RSYNC_VERSION in $fn\n";
174 } elsif ($fn =~ /\.spec/) {
175 while (my($str, $val) = each %specvars) {
176 s/^\Q$str\E .*/$str $val/m
177 or die "Unable to update $str in $fn\n";
178 }
179 s/^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)/$cl_today $1/m
180 or die "Unable to update ChangeLog header in $fn\n";
181 } elsif ($fn =~ /\.yo/) {
182 s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m
183 or die "Unable to update date in manpage() header in $fn\n";
184 s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m
185 or die "Unable to update current version info in $fn\n";
186 } elsif ($fn eq 'rsync.h') {
187 s/(#define\s+SUBPROTOCOL_VERSION)\s+\d+/$1 0/
188 or die "Unable to find SUBPROTOCOL_VERSION define in $fn\n";
189 next if $pre;
190 } elsif ($fn eq 'NEWS') {
191 s/^(NEWS for rsync \Q$finalversion\E) \(UNRELEASED\)\s*\n/$1 ($today)\n/mi
192 or die "The first line of $fn is not in the right format. It must be:\n"
193 . "NEWS for rsync $finalversion (UNRELEASED)\n";
194 next if $pre;
195 } elsif ($fn eq 'OLDNEWS') {
196 s/^\t\S\S\s\S\S\S\s\d\d\d\d(\t\Q$finalversion\E)/\t$ztoday$1/m
197 or die "Unable to find \"?? ??? $year\t$finalversion\" line in $fn\n";
198 next if $pre;
199 } elsif ($fn eq 'options.c') {
200 if (s/(Copyright \(C\) 2002-)(\d+)( Wayne Davison)/$1$year$3/
201 && $2 ne $year) {
202 die "Copyright comments need to be updated to $year in all files!\n";
203 }
204 # Adjust the year in the --version output.
205 s/(rprintf\(f, "Copyright \(C\) 1996-)(\d+)/$1$year/
206 or die "Unable to find Copyright string in --version output of $fn\n";
207 next if $2 eq $year;
208 } else {
209 die "Unrecognized file in \@tweak_files: $fn\n";
210 }
211 open(OUT, '>', $fn) or die $!;
212 print OUT $_;
213 close OUT;
214}
215
216print $break;
217system "git diff --color | less -p '^diff .*'";
218
219my $srctar_name = "rsync-$version.tar.gz";
220my $pattar_name = "rsync-patches-$version.tar.gz";
221my $diff_name = "rsync-$lastversion-$version.diffs.gz";
222my $srctar_file = "$dest/$srcdir/$srctar_name";
223my $pattar_file = "$dest/$srcdir/$pattar_name";
224my $diff_file = "$dest/$srcdiffdir/$diff_name";
225my $news_file = "$dest/$srcdir/rsync-$version-NEWS";
226my $lasttar_file = "$dest/$lastsrcdir/rsync-$lastversion.tar.gz";
227
228print $break, <<EOT;
229
230About to:
231 - commit all version changes
232 - merge the $master_branch branch into the patch/* branches
233 - update the files in the "patches" dir and OPTIONALLY
234 (if you type 'y') to launch a shell for each patch
235
236EOT
237print "<Press Enter OR 'y' to continue> ";
238my $ans = <STDIN>;
239
240system "git commit -a -m 'Preparing for release of $version'" and exit 1;
241
242print "Updating files in \"patches\" dir ...\n";
243system "packaging/patch-update --branch=$master_branch";
244
245if ($ans =~ /^y/i) {
246 print "\nVisiting all \"patch/*\" branches ...\n";
247 system "packaging/patch-update --branch=$master_branch --shell";
248}
249
250print $break, <<EOT;
251
252About to:
253 - create signed tag for this release: v$version
254 - create release diffs, "$diff_name"
255 - create release tar, "$srctar_name"
256 - generate rsync-$version/patches/* files
257 - create patches tar, "$pattar_name"
258 - update top-level README, *NEWS, TODO, and ChangeLog
259 - update top-level rsync*.html manpages
260 - gpg-sign the release files
261 - update hard-linked top-level release files$skipping
262
263EOT
264print "<Press Enter to continue> ";
265$_ = <STDIN>;
266
267my $passphrase;
268while (1) {
269 ReadMode('noecho');
270 print "\nEnter your GPG pass-phrase: ";
271 chomp($passphrase = <STDIN>);
272 ReadMode(0);
273 print "\n";
274
275 # Briefly create a temp file with the passphrase for git's tagging use.
276 my $oldmask = umask 077;
277 unlink($passfile);
278 open(OUT, '>', $passfile) or die $!;
279 print OUT $passphrase, "\n";
280 close OUT;
281 umask $oldmask;
282 $ENV{'GPG_PASSFILE'} = $passfile;
283
284 # We want to use our passphrase-providing "gpg" script, so modify the PATH.
285 $ENV{PATH} = "packaging/bin:$path";
286 $_ = `git tag -s -m 'Version $version.' v$version 2>&1`;
287 $ENV{PATH} = $path;
288 unlink($passfile);
289 print $_;
290 next if /bad passphrase/;
291 last unless /failed/;
292 exit 1;
293}
294
295# Extract the generated files from the old tar.
296@_ = @extra_files;
297map { s#^#rsync-$lastversion/# } @_;
298system "tar xzf $lasttar_file @_";
299rename("rsync-$lastversion", 'a');
300
301print "Creating $diff_file ...\n";
302system "./config.status Makefile; make gen; rsync -a @extra_files b/";
303my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
304system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file";
305system "rm -rf a";
306rename('b', "rsync-$version");
307
308print "Creating $srctar_file ...\n";
309system "git archive --format=tar --prefix=rsync-$version/ v$version | tar xf -";
310system "support/git-set-file-times --prefix=rsync-$version/";
311system "fakeroot tar czf $srctar_file rsync-$version; rm -rf rsync-$version";
312
313print "Updating files in \"rsync-$version/patches\" dir ...\n";
314mkdir("rsync-$version", 0755);
315mkdir("rsync-$version/patches", 0755);
316system "packaging/patch-update --skip-check --branch=$master_branch --gen=rsync-$version/patches";
317
318print "Creating $pattar_file ...\n";
319system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version";
320
321print "Updating the other files in $dest ...\n";
322system "rsync -a README NEWS OLDNEWS TODO $dest";
323unlink($news_file);
324link("$dest/NEWS", $news_file);
325system "git log --name-status | gzip -9 >$dest/ChangeLog.gz";
326
327system "yodl2html -o $dest/rsync.html rsync.yo";
328system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
329
330foreach my $fn ($srctar_file, $pattar_file, $diff_file) {
331 unlink("$fn.asc");
332 open(GPG, '|-', "gpg --batch --passphrase-fd=0 -ba $fn") or die $!;
333 print GPG $passphrase, "\n";
334 close GPG;
335}
336
337if (!$pre) {
338 system "rm $dest/rsync-*.gz $dest/rsync-*.asc $dest/rsync-*-NEWS $dest/src-previews/rsync-*diffs.gz*";
339
340 foreach my $fn ($srctar_file, "$srctar_file.asc",
341 $pattar_file, "$pattar_file.asc",
342 $diff_file, "$diff_file.asc", $news_file) {
343 (my $top_fn = $fn) =~ s#/src(-\w+)?/#/#;
344 link($fn, $top_fn);
345 }
346}
347
348print $break, <<'EOT';
349
350Local changes are done. When you're satisfied, push the git repository
351and rsync the release files. Remember to announce the release on *BOTH*
352rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)!
353EOT
354
355exit;
356
357sub usage
358{
359 die <<EOT;
360Usage: release-rsync [OPTIONS]
361
362-b, --branch=BRANCH The branch to release (default: master)
363-h, --help Display this help message
364EOT
365}