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