34a23ea037e66018eaf168f38a5a8734600b52c2
[openafs.git] / build-tools / make-release
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Getopt::Long;
6 use Pod::Usage;
7 use File::Path;
8 use File::Temp;
9
10 my $help;
11 my $man;
12 my $tagPoint;
13 my $last;
14 my $outDir = ".";
15
16 GetOptions(
17     "help|?" => \$help,
18     "man" => \$man,
19     "tagpoint=s" => \$tagPoint,
20     "last=s" => \$last,
21     "dir=s" => \$outDir,
22 ) or pod2usage(2);
23
24 pod2usage(1) if $help;
25 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
26
27 my $tagName = shift;
28 my $notused = shift;  # Used to be "version".
29
30 pod2usage(2) if !defined($tagName);
31 if (defined $notused) {
32     warn "Warning: argument '$notused' is ignored.\n";
33 }
34
35 # Tag the repository
36
37 if ($tagPoint) {
38     system ("git tag -s $tagName $tagPoint") == 0
39         or die "git tag failed with : $!";
40
41     # Push the tag upstream
42     system ("git push ssh://gerrit.openafs.org:29418/openafs tag $tagName") == 0
43         or die "git push failed with : $!";
44 }
45
46 my $version = `git describe --abbrev=4 $tagName`;
47 chomp $version;
48 $version=~s/openafs-[^-]*-//;
49 $version=~s/_/./g;
50
51 # Grab the tagged code into a temporary directory
52
53 my $name = "openafs-".$version;
54
55 my $tempDir = File::Temp::tempdir();
56 system ("git archive --format=tar --prefix=$name/ $tagName ".
57         " | tar -C $tempDir -x") == 0
58     or die "Git archive failed with: $?";
59
60 # Construct the ChangeLog
61 if ($last) {
62     system("git log $last..$tagName > $outDir/ChangeLog");
63 } else {
64     system("git log $tagName > $outDir/ChangeLog");
65 }
66
67 # Describe the tree
68 system("git describe --abbrev=4 $tagName > $tempDir/$name/.version");
69
70 # Run regen.sh to create the rest of the tree
71 system ("cd $tempDir/$name && ./regen.sh") == 0
72     or die $!;
73
74 # A list of files to compress
75 my @toCompress;
76
77 # Create the documentation tarball
78 system("tar -cf $outDir/$name-doc.tar -C $tempDir $name/doc") == 0
79     or die "Unable to create documentation tarball : $!";
80 push @toCompress, "$outDir/$name-doc.tar";
81
82 # Remove the docs directory (we've already build a tarball for it)
83 File::Path::rmtree("$tempDir/$name/doc");
84
85 # Create the source tarball (both .gz and .bz2)
86 system("tar -cf $outDir/$name-src.tar -C $tempDir $name") == 0
87     or die "Unable to create source code tarball : $!";
88 push @toCompress, "$outDir/$name-src.tar";
89
90 # Construct the diffs, and zip them
91 if ($last) {
92     system("git diff $last..$tagName > $outDir/$name.diff") == 0
93        or die "Unable to create diff : $!";
94     push @toCompress, "$outDir/$name.diff";
95 }
96
97 my @toMD5;
98
99 # Compress everything that needs squashing,
100 # and also set up a list for md5 checksumming.
101 foreach my $file (@toCompress) {
102     system("gzip < $file > $file.gz") == 0
103         or die "Unable to create gzip file of '$file' : $!";
104     push @toMD5, "$file.gz";
105
106     system("bzip2 < $file > $file.bz2") == 0
107         or die "Unable to create bzip file of '$file' : $!";
108     push @toMD5, "$file.bz2";
109
110     # Delete the uncompressed tar files.
111     if ($file =~ /\.tar$/) {
112       unlink($file);
113     } else {
114       # Otherwise, queue this file for md5 checksumming.
115       push @toMD5, $file;
116     }
117 }
118
119 foreach my $file (@toMD5) {
120     if (-x "/sbin/md5") {
121         system("/sbin/md5 -q $file > $file.md5");
122     } elsif (-x "/usr/bin/md5sum") {
123         system("/usr/bin/md5sum $file > $file.md5");
124     } else {
125         print STDERR "No md5 utility found. Not producing checksums\n";
126     }
127 }
128
129
130 __END__
131
132 =head1 NAME
133
134 make-release - Make an OpenAFS release from git
135
136 =head1 SYNOPSIS
137
138 make-release [options] <tag>
139
140  Options:
141     --help               brief help message
142     --man                full documentation
143     --tagpoint <object>  create new tag
144     --last <object>      generate changelog and diffs from this point
145     --dir <dir>          output results into this directory
146
147 =head1 DESCRIPTION
148
149 make-release constructs an OpenAFS release from a local git clone. If run
150 with just the standard arguments, it will extract the contents of the
151 specified tag into the current directory, creating src and doc tarballs,
152 gzipping and bzipping them, and generating md5 hashes. It will also create a
153 ChangeLog file, listing all of the changes in that release.
154
155 This standard behaviour may be modified by the following options
156
157 =head1 OPTIONS
158
159 =over 8
160
161 =item B<--last> I<object>
162
163 Generate the ChangeLog starting from I<object>. Also generate a
164 openafs-$version.diff file in the output directory containing all of the
165 changes between I<object> and the current tag
166
167 =item B<--dir> I<directory>
168
169 Instead of generating all of the output in the current directory, place it
170 in <directory>, which must already exist.
171
172 =item B<--tagpoint> I<commit|branch>
173
174 Rather than using an existing tag, create a new one on the specified commit,
175 or on the tip of the specified branch. This will GPG sign the new tag, and
176 push it into gerrit.
177
178 =back
179
180 =cut