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