Enhanced the release scripts to be able to handle a branch release.
[rsync/rsync.git] / packaging / release-rsync
CommitLineData
6d12a859
WD
1#!/usr/bin/perl
2use strict;
3
805d8ac4
WD
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.
6d12a859 8
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};
6d12a859 17
56fc9f70
WD
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
fede3785
WD
25my $now = time;
26my $cl_today = time2str('* %a %b %d %Y', $now);
27my $year = time2str('%Y', $now);
28my $ztoday = time2str('%d %b %Y', $now);
90ac152d 29(my $today = $ztoday) =~ s/^0//;
6d12a859 30
805d8ac4
WD
31my $curdir = Cwd::cwd;
32
798a9e4e
WD
33END {
34 unlink($passfile);
35}
36
67b9b26f
WD
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}
805d8ac4
WD
48close IN;
49
5fa38cd6
WD
50my $break = <<EOT;
51==========================================================================
6d12a859 52EOT
6d12a859 53
805d8ac4 54print $break, <<EOT, $break, "\n";
5fa38cd6
WD
55== This will release a new version of rsync onto an unsuspecting world. ==
56EOT
519c8de1 57
805d8ac4
WD
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';
519c8de1 62
6a2456c5 63open(IN, '-|', 'git status') or die $!;
805d8ac4
WD
64my $status = join('', <IN>);
65close IN;
66die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
56fc9f70 67die "The checkout is not on the $master_branch branch.\n" unless $status =~ /^# On branch $master_branch\n/;
519c8de1 68
fede3785 69my $confversion;
578219be 70open(IN, '<', 'configure.in') or die $!;
519c8de1
WD
71while (<IN>) {
72 if (/^RSYNC_VERSION=(.*)/) {
fede3785 73 $confversion = $1;
519c8de1
WD
74 last;
75 }
76}
77close IN;
fede3785 78die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion;
2e4a3d17 79
62ca3826
WD
80open(IN, '<', 'OLDNEWS') or die $!;
81$_ = <IN>;
82close IN;
fede3785 83my($lastversion) = /(\d+\.\d+\.\d+)/;
62ca3826 84
fede3785 85my $version = $confversion;
805d8ac4 86$version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
519c8de1 87
805d8ac4 88print "Please enter the version number of this release: [$version] ";
519c8de1
WD
89chomp($_ = <STDIN>);
90if ($_ eq '.') {
91 $version =~ s/pre\d+//;
92} elsif ($_ ne '') {
93 $version = $_;
94}
798a9e4e
WD
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}
fede3785
WD
103
104if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) {
105 $lastversion = $confversion;
106}
6d12a859 107
519c8de1
WD
108print "Enter the previous version to produce a patch against: [$lastversion] ";
109chomp($_ = <STDIN>);
110$lastversion = $_ if $_ ne '';
6d12a859
WD
111$lastversion =~ s/[-.]*pre[-.]*/pre/;
112
99ba99c7
WD
113my $pre = $version =~ /(pre\d+)/ ? $1 : '';
114
115my $release = $pre ? '0.1' : '1';
519c8de1
WD
116print "Please enter the RPM release number of this release: [$release] ";
117chomp($_ = <STDIN>);
118$release = $_ if $_ ne '';
99ba99c7 119$release .= ".$pre" if $pre;
6d12a859 120
e63d3a29 121my($srcdir,$srcdiffdir,$lastsrcdir,$skipping);
6d12a859 122if ($lastversion =~ /pre/) {
99ba99c7 123 if (!$pre) {
6d12a859
WD
124 die "You should not diff a release version against a pre-release version.\n";
125 }
e63d3a29 126 $srcdir = $srcdiffdir = $lastsrcdir = 'src-previews';
805d8ac4 127 $skipping = ' ** SKIPPING **';
99ba99c7 128} elsif ($pre) {
e63d3a29
WD
129 $srcdir = $srcdiffdir = 'src-previews';
130 $lastsrcdir = 'src';
805d8ac4 131 $skipping = ' ** SKIPPING **';
6d12a859 132} else {
e63d3a29
WD
133 $srcdir = $lastsrcdir = 'src';
134 $srcdiffdir = 'src-diffs';
805d8ac4 135 $skipping = '';
6d12a859
WD
136}
137
5fa38cd6 138print "\n", $break, <<EOT;
6d12a859
WD
139\$version is "$version"
140\$lastversion is "$lastversion"
6d12a859 141\$dest is "$dest"
805d8ac4 142\$curdir is "$curdir"
e63d3a29
WD
143\$srcdir is "$srcdir"
144\$srcdiffdir is "$srcdiffdir"
145\$lastsrcdir is "$lastsrcdir"
6d12a859
WD
146\$release is "$release"
147
148About to:
805d8ac4
WD
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
798a9e4e 152 - tweak the date in the *.yo files and generate the manpages
805d8ac4
WD
153 - generate configure.sh, config.h.in, and proto.h
154 - page through the differences
6d12a859
WD
155
156EOT
157print "<Press Enter to continue> ";
158$_ = <STDIN>;
159
800a4485 160(my $finalversion = $version) =~ s/pre\d+//;
99ba99c7 161my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release,
6fd2c27f
WD
162 '%define fullversion' => "\%{version}$pre", 'Released' => "$version.",
163 '%define srcdir' => $srcdir );
800a4485
WD
164my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'),
165 qw( configure.in rsync.h NEWS OLDNEWS options.c ) );
805d8ac4 166
6d12a859
WD
167foreach my $fn (@tweak_files) {
168 open(IN, '<', $fn) or die $!;
169 undef $/; $_ = <IN>; $/ = "\n";
170 close IN;
171 if ($fn =~ /configure/) {
800a4485
WD
172 s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m
173 or die "Unable to update RSYNC_VERSION in $fn\n";
6d12a859 174 } elsif ($fn =~ /\.spec/) {
800a4485
WD
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";
6d12a859 181 } elsif ($fn =~ /\.yo/) {
800a4485
WD
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";
2e4a3d17 186 } elsif ($fn eq 'rsync.h') {
800a4485
WD
187 s/(#define\s+SUBPROTOCOL_VERSION)\s+\d+/$1 0/
188 or die "Unable to find SUBPROTOCOL_VERSION define in $fn\n";
99ba99c7 189 next if $pre;
800a4485
WD
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";
99ba99c7 194 next if $pre;
178a1d20 195 } elsif ($fn eq 'OLDNEWS') {
800a4485
WD
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";
99ba99c7 198 next if $pre;
fede3785 199 } elsif ($fn eq 'options.c') {
800a4485
WD
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;
6d12a859 208 } else {
178a1d20 209 die "Unrecognized file in \@tweak_files: $fn\n";
6d12a859
WD
210 }
211 open(OUT, '>', $fn) or die $!;
212 print OUT $_;
213 close OUT;
214}
215
5fa38cd6 216print $break;
6a2456c5 217system "git diff --color | less -p '^diff .*'";
5fa38cd6 218
805d8ac4
WD
219my $srctar_name = "rsync-$version.tar.gz";
220my $pattar_name = "rsync-patches-$version.tar.gz";
e60bba3f 221my $diff_name = "rsync-$lastversion-$version.diffs.gz";
e63d3a29
WD
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";
5fa38cd6
WD
227
228print $break, <<EOT;
6d12a859 229
805d8ac4 230About to:
798a9e4e 231 - commit all version changes
56fc9f70 232 - merge the $master_branch branch into the patch/* branches
798a9e4e
WD
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";
56fc9f70 243system "packaging/patch-update --branch=$master_branch";
798a9e4e
WD
244
245if ($ans =~ /^y/i) {
246 print "\nVisiting all \"patch/*\" branches ...\n";
56fc9f70 247 system "packaging/patch-update --branch=$master_branch --shell";
798a9e4e
WD
248}
249
250print $break, <<EOT;
251
252About to:
253 - create signed tag for this release: v$version
254 - create release diffs, "$diff_name"
805d8ac4 255 - create release tar, "$srctar_name"
798a9e4e 256 - generate rsync-$version/patches/* files
805d8ac4 257 - create patches tar, "$pattar_name"
798a9e4e
WD
258 - update top-level README, *NEWS, TODO, and ChangeLog
259 - update top-level rsync*.html manpages
805d8ac4 260 - gpg-sign the release files
798a9e4e 261 - update hard-linked top-level release files$skipping
6d12a859
WD
262
263EOT
264print "<Press Enter to continue> ";
265$_ = <STDIN>;
266
798a9e4e
WD
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}
6d12a859 294
e63d3a29 295# Extract the generated files from the old tar.
4bb319c6
WD
296@_ = @extra_files;
297map { s#^#rsync-$lastversion/# } @_;
298system "tar xzf $lasttar_file @_";
299rename("rsync-$lastversion", 'a');
300
5fa38cd6 301print "Creating $diff_file ...\n";
4da9fcd4 302system "./config.status Makefile; make gen; rsync -a @extra_files b/";
ee8a733d 303my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
62ca3826 304system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file";
9217ce30
WD
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";
805d8ac4 312
798a9e4e 313print "Updating files in \"rsync-$version/patches\" dir ...\n";
4da9fcd4
WD
314mkdir("rsync-$version", 0755);
315mkdir("rsync-$version/patches", 0755);
56fc9f70 316system "packaging/patch-update --skip-check --branch=$master_branch --gen=rsync-$version/patches";
798a9e4e
WD
317
318print "Creating $pattar_file ...\n";
4da9fcd4 319system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version";
6d12a859 320
5fa38cd6 321print "Updating the other files in $dest ...\n";
805d8ac4 322system "rsync -a README NEWS OLDNEWS TODO $dest";
e63d3a29
WD
323unlink($news_file);
324link("$dest/NEWS", $news_file);
eaa28e65 325system "git log --name-status | gzip -9 >$dest/ChangeLog.gz";
6d12a859 326
805d8ac4
WD
327system "yodl2html -o $dest/rsync.html rsync.yo";
328system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
6d12a859 329
e63d3a29 330foreach my $fn ($srctar_file, $pattar_file, $diff_file) {
798a9e4e
WD
331 unlink("$fn.asc");
332 open(GPG, '|-', "gpg --batch --passphrase-fd=0 -ba $fn") or die $!;
333 print GPG $passphrase, "\n";
334 close GPG;
e0fe5231 335}
e63d3a29 336
99ba99c7 337if (!$pre) {
2551c47e 338 system "rm $dest/rsync-*.gz $dest/rsync-*.asc $dest/rsync-*-NEWS $dest/src-previews/rsync-*diffs.gz*";
e63d3a29
WD
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
e0fe5231 348print $break, <<'EOT';
6d12a859 349
e0fe5231
WD
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)!
6d12a859 353EOT
56fc9f70
WD
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}