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