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