Adding a support script that can be used to make the checked-out
[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;
6d12a859
WD
10use Date::Format;
11
12my $dest = $ENV{HOME} . '/samba-rsync-ftp';
6d12a859 13
90ac152d 14my $cl_today = time2str('* %a %b %d %Y', time);
6d12a859 15my $ztoday = time2str('%d %b %Y', time);
90ac152d 16(my $today = $ztoday) =~ s/^0//;
6d12a859 17
805d8ac4
WD
18my $curdir = Cwd::cwd;
19
20open(IN, '<', 'prepare-source.mak') or die "Couldn't open prepare-source.mak: $!\n";
21$_ = join('', <IN>);
22close IN;
23
24my @extra_files = m{\n([^\s:]+):.*\n\t\S}g;
25
5fa38cd6
WD
26my $break = <<EOT;
27==========================================================================
6d12a859 28EOT
6d12a859 29
805d8ac4 30print $break, <<EOT, $break, "\n";
5fa38cd6
WD
31== This will release a new version of rsync onto an unsuspecting world. ==
32EOT
519c8de1 33
805d8ac4
WD
34die "$dest does not exist\n" unless -d $dest;
35die "There is no .git dir in the current directory.\n" unless -d '.git';
36die "'a' must not exist in the current directory.\n" if -e 'a';
37die "'b' must not exist in the current directory.\n" if -e 'b';
519c8de1 38
805d8ac4
WD
39open(IN, '-|', 'git-status') or die $!;
40my $status = join('', <IN>);
41close IN;
42die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
43die "The checkout is not on the master branch.\n" unless $status =~ /^# On branch master\n/;
519c8de1 44
805d8ac4 45my $lastversion;
578219be 46open(IN, '<', 'configure.in') or die $!;
519c8de1
WD
47while (<IN>) {
48 if (/^RSYNC_VERSION=(.*)/) {
805d8ac4 49 $lastversion = $1;
519c8de1
WD
50 last;
51 }
52}
53close IN;
805d8ac4 54if ($lastversion =~ /dev$/) {
578219be
WD
55 open(IN, '<', 'OLDNEWS') or die $!;
56 $_ = <IN>;
57 close IN;
58 ($lastversion) = /(\d+\.\d+\.\d+)/;
2e4a3d17
WD
59}
60
805d8ac4
WD
61my $version = $lastversion;
62$version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
519c8de1 63
805d8ac4 64print "Please enter the version number of this release: [$version] ";
519c8de1
WD
65chomp($_ = <STDIN>);
66if ($_ eq '.') {
67 $version =~ s/pre\d+//;
68} elsif ($_ ne '') {
69 $version = $_;
70}
6d12a859
WD
71$version =~ s/[-.]*pre[-.]*/pre/;
72
519c8de1
WD
73print "Enter the previous version to produce a patch against: [$lastversion] ";
74chomp($_ = <STDIN>);
75$lastversion = $_ if $_ ne '';
6d12a859
WD
76$lastversion =~ s/[-.]*pre[-.]*/pre/;
77
519c8de1
WD
78my $release = 1;
79print "Please enter the RPM release number of this release: [$release] ";
80chomp($_ = <STDIN>);
81$release = $_ if $_ ne '';
6d12a859
WD
82
83my $diffdir;
805d8ac4 84my $skipping;
6d12a859
WD
85if ($lastversion =~ /pre/) {
86 if ($version !~ /pre/) {
87 die "You should not diff a release version against a pre-release version.\n";
88 }
89 $diffdir = "$dest/old-previews";
805d8ac4 90 $skipping = ' ** SKIPPING **';
6d12a859
WD
91} elsif ($version =~ /pre/) {
92 $diffdir = $dest;
805d8ac4 93 $skipping = ' ** SKIPPING **';
6d12a859
WD
94} else {
95 $diffdir = "$dest/old-versions";
805d8ac4 96 $skipping = '';
6d12a859
WD
97}
98
5fa38cd6 99print "\n", $break, <<EOT;
6d12a859
WD
100\$version is "$version"
101\$lastversion is "$lastversion"
6d12a859 102\$dest is "$dest"
805d8ac4 103\$curdir is "$curdir"
6d12a859
WD
104\$diffdir is "$diffdir"
105\$release is "$release"
106
107About to:
805d8ac4
WD
108 - make sure that SUBPROTOCOL_VERSION is 0$skipping
109 - tweak the version in configure.in and the spec files
110 - tweak NEWS and OLDNEWS to update the release date$skipping
111 - tweak the date in the *.yo files and generate the man pages
112 - generate configure.sh, config.h.in, and proto.h
113 - page through the differences
6d12a859
WD
114
115EOT
116print "<Press Enter to continue> ";
117$_ = <STDIN>;
118
5fa38cd6 119print $break;
6d12a859
WD
120
121my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'),
805d8ac4
WD
122 glob('*.yo'), qw( configure.in ) );
123
6d12a859 124if ($version !~ /pre/) {
2e4a3d17 125 push(@tweak_files, qw( rsync.h NEWS OLDNEWS ));
6d12a859
WD
126}
127foreach my $fn (@tweak_files) {
128 open(IN, '<', $fn) or die $!;
129 undef $/; $_ = <IN>; $/ = "\n";
130 close IN;
131 if ($fn =~ /configure/) {
200f2d98 132 s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m;
6d12a859
WD
133 } elsif ($fn =~ /\.spec/) {
134 s/^(Version:) .*/$1 $version/m;
135 s/^(Release:) .*/$1 $release/m;
fdad5aad 136 s/^(Released) .*/$1 $version./m;
90ac152d 137 s/^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)/$cl_today $1/m;
6d12a859
WD
138 } elsif ($fn =~ /\.yo/) {
139 s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m;
140 s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m;
178a1d20
WD
141 } elsif ($fn eq 'NEWS') {
142 s/^(NEWS for rsync \Q$version\E) \(UNRELEASED\)\s*\n/$1 ($today)\n/mi
143 or die "Couldn't update NEWS file with release date!\n";
2e4a3d17
WD
144 } elsif ($fn eq 'rsync.h') {
145 s/(#define\s+SUBPROTOCOL_VERSION)\s+\d+/$1 0/;
178a1d20
WD
146 } elsif ($fn eq 'OLDNEWS') {
147 s/^\t\S\S\s\S\S\S\s\d\d\d\d(\t\Q$version\E)/\t$ztoday$1/m
148 or die "Couldn't update OLDNEWS file with release date!\n";
6d12a859 149 } else {
178a1d20 150 die "Unrecognized file in \@tweak_files: $fn\n";
6d12a859
WD
151 }
152 open(OUT, '>', $fn) or die $!;
153 print OUT $_;
154 close OUT;
155}
156
805d8ac4 157system "./prepare-source && touch proto.h";
6d12a859 158
5fa38cd6 159print $break;
805d8ac4 160system "git-diff --color |less -p '^diff .*'";
5fa38cd6 161
805d8ac4
WD
162my $srctar_name = "rsync-$version.tar.gz";
163my $pattar_name = "rsync-patches-$version.tar.gz";
e60bba3f 164my $diff_name = "rsync-$lastversion-$version.diffs.gz";
805d8ac4
WD
165my $srctar_file = "$dest/$srctar_name";
166my $pattar_file = "$dest/$pattar_name";
e60bba3f 167my $diff_file = "$dest/$diff_name";
805d8ac4 168my $lasttar_file = "$dest/rsync-$lastversion.tar.gz";
5fa38cd6
WD
169
170print $break, <<EOT;
6d12a859 171
805d8ac4
WD
172About to:
173 - commit all changes
174 - tag this release as v$version
4d8639eb 175 - move the old tar/diff files into the appropriate old-* dirs
805d8ac4
WD
176 - hard-link the moved tar/diff files on samba.org
177 - create release tar, "$srctar_name"
178 - create patches tar, "$pattar_name"
e60bba3f 179 - create release diffs, "$diff_name"
805d8ac4
WD
180 - update patch branches and generate patch/* files
181 - update README, *NEWS, TODO, and changelog
6d12a859 182 - update rsync*.html man pages
805d8ac4 183 - gpg-sign the release files
6d12a859
WD
184
185EOT
186print "<Press Enter to continue> ";
187$_ = <STDIN>;
188
805d8ac4
WD
189@_ = @extra_files;
190map { s#^#a/# } @_;
191$_[0] =~ s/configure\.sh/configure/; # XXX remove soon
192system "tar xzf $lasttar_file @_";
193rename("a/configure", "a/configure.sh"); # XXX remove soon
6d12a859 194
805d8ac4
WD
195system "rsync -a @extra_files rsync-$version/";
196
86eb9f95
WD
197system "git-commit -a -m 'Preparing for release of $version'" and exit 1;
198system "git-tag -s -m 'Version $version.' v$version" and exit 1;
6d12a859
WD
199
200# When creating a pre-release after a normal release, there's nothing to move.
201if ($diffdir ne $dest) {
202 chdir($dest) or die $!;
203
5fa38cd6
WD
204 print "Shuffling old files ...\n";
205
519c8de1
WD
206 # We need to run this regardless of $lastversion's "pre"ness.
207 my @moved_files;
6d12a859 208 foreach my $fn (glob('rsync*pre*.tar.gz*'), glob('rsync*pre*-NEWS')) {
5f12a07b
WD
209 link($fn, "old-previews/$fn") or die $!;
210 push(@moved_files, $fn);
6d12a859 211 }
6d12a859
WD
212
213 if ($version !~ /pre/) {
214 foreach my $fn (glob('rsync*.tar.gz*'), glob('rsync*-NEWS')) {
4d8639eb 215 next if $fn =~ /^rsync.*pre/;
5f12a07b
WD
216 link($fn, "old-versions/$fn") or die $!;
217 push(@moved_files, $fn);
6d12a859
WD
218 }
219
178a1d20
WD
220 foreach my $fn (glob('rsync*pre*.diffs.gz*')) {
221 unlink($fn);
222 }
223
6d12a859 224 foreach my $fn (glob('rsync*.diffs.gz*')) {
5f12a07b
WD
225 link($fn, "old-patches/$fn") or die $!;
226 push(@moved_files, $fn);
6d12a859
WD
227 }
228 }
229
519c8de1 230 # Optimize our future upload (in the absence of --detect-renamed) by
5f12a07b 231 # using rsync to hard-link the above files on samba.org.
805d8ac4 232 system "rsync -avHOC --include='rsync*.gz*' --include='old-*/' --exclude='*' . samba.org:/home/ftp/pub/rsync";
178a1d20 233 foreach (@moved_files) {
519c8de1
WD
234 unlink($_);
235 }
236
805d8ac4 237 chdir($curdir) or die $!;
6d12a859 238}
6d12a859 239
805d8ac4 240print "Creating $srctar_file ...\n";
ee8a733d
WD
241(my $srctar_tmp = $srctar_file) =~ s/\.gz$//;
242system "git-archive --format=tar --prefix=rsync-$version/ v$version >$srctar_tmp";
243system "fakeroot tar rf $srctar_tmp rsync-$version/*; gzip -9 $srctar_tmp";
5fa38cd6
WD
244
245print "Creating $diff_file ...\n";
805d8ac4 246rename("rsync-$version", 'b');
ee8a733d
WD
247my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
248system "(git-diff v$lastversion v$version; diff -up a b | sed -r '$sed_script') | gzip -9 >$diff_file";
805d8ac4
WD
249system "rm -rf a b";
250
251system "support/patch-update --gen";
252
253symlink('.', "rsync-$version");
254system "tar czf $pattar_file rsync-$version/patches";
255unlink("rsync-$version");
6d12a859 256
5fa38cd6 257print "Updating the other files in $dest ...\n";
805d8ac4 258system "rsync -a README NEWS OLDNEWS TODO $dest";
6d12a859
WD
259unlink("$dest/rsync-$version-NEWS");
260link("$dest/NEWS", "$dest/rsync-$version-NEWS");
805d8ac4 261system "git-log --name-status | gzip -9 >$dest/changelog.gz";
6d12a859 262
805d8ac4
WD
263system "yodl2html -o $dest/rsync.html rsync.yo";
264system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
6d12a859 265
805d8ac4
WD
266chdir($dest) or die $!;
267system "gpg -ba $srctar_name; gpg -ba $pattar_name; gpg -ba $diff_name";
268print $break, <<EOT;
6d12a859
WD
269
270All done. Remember to announce the release on *BOTH*
271rsync-announce\@lists.samba.org and rsync\@lists.samba.org!
272EOT