openafs/build-tools/make-release
Michael Meffie 188ca8bf52 make-release: Run git describe once
Run git describe once at the beginning of make-release to find the
version information used to derive the tarball file names and saved in
the .version file.

This is a cleanup and refactoring change to prepare for a future commit.

Change-Id: I0debeeffa5d2c63ab1498588766cb36424d15cd5
Reviewed-on: https://gerrit.openafs.org/14150
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2020-06-18 21:15:15 -04:00

190 lines
4.9 KiB
Perl
Executable File

#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
use File::Path;
use File::Temp;
my $help;
my $man;
my $tagPoint;
my $last;
my $outDir = ".";
GetOptions(
"help|?" => \$help,
"man" => \$man,
"tagpoint=s" => \$tagPoint,
"last=s" => \$last,
"dir=s" => \$outDir,
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
my $tagName = shift;
my $notused = shift; # Used to be "version".
pod2usage(2) if !defined($tagName);
if (defined $notused) {
warn "Warning: argument '$notused' is ignored.\n";
}
# Tag the repository
if ($tagPoint) {
system ("git tag -s $tagName $tagPoint") == 0
or die "git tag failed with : $!";
# Push the tag upstream
system ("git push ssh://gerrit.openafs.org:29418/openafs tag $tagName") == 0
or die "git push failed with : $!";
}
my $version = `git describe --abbrev=4 $tagName`;
chomp $version;
if (!$version) {
die "Failed to describe $tagName.\n";
}
my $suffix = $version;
$suffix =~ s/openafs-[^-]*-//;
$suffix =~ s/_/./g;
my $name = "openafs-$suffix";
# Grab the tagged code into a temporary directory
my $tempDir = File::Temp::tempdir();
system ("git archive --format=tar --prefix=$name/ $tagName ".
" | tar -C $tempDir -x") == 0
or die "Git archive failed with: $?";
# Make the output path, if not already present.
File::Path::mkpath($outDir);
# Construct the ChangeLog
if ($last) {
system("git log $last..$tagName > $outDir/ChangeLog");
} else {
system("git log $tagName > $outDir/ChangeLog");
}
# Describe the tree
open(my $fh, ">", "$tempDir/$name/.version") or
die "Failed to open $tempDir/$name/.version: $!\n";
print $fh "$version\n";
close($fh);
# Run regen.sh to create the rest of the tree
system ("cd $tempDir/$name && ./regen.sh") == 0
or die $!;
# A list of files to compress
my @toCompress;
# Create the documentation tarball
system("tar -cf $outDir/$name-doc.tar -C $tempDir $name/doc") == 0
or die "Unable to create documentation tarball : $!";
push @toCompress, "$outDir/$name-doc.tar";
# Remove the docs directory (we've already build a tarball for it)
File::Path::rmtree("$tempDir/$name/doc");
# Create the source tarball (both .gz and .bz2)
system("tar -cf $outDir/$name-src.tar -C $tempDir $name") == 0
or die "Unable to create source code tarball : $!";
push @toCompress, "$outDir/$name-src.tar";
# Construct the diffs, and zip them
if ($last) {
system("git diff $last..$tagName > $outDir/$name.diff") == 0
or die "Unable to create diff : $!";
push @toCompress, "$outDir/$name.diff";
}
my @toMD5;
# Compress everything that needs squashing,
# and also set up a list for md5 checksumming.
foreach my $file (@toCompress) {
system("gzip < $file > $file.gz") == 0
or die "Unable to create gzip file of '$file' : $!";
push @toMD5, "$file.gz";
system("bzip2 < $file > $file.bz2") == 0
or die "Unable to create bzip file of '$file' : $!";
push @toMD5, "$file.bz2";
# Delete the uncompressed tar files.
if ($file =~ /\.tar$/) {
unlink($file);
} else {
# Otherwise, queue this file for md5 checksumming.
push @toMD5, $file;
}
}
foreach my $file (@toMD5) {
if (-x "/sbin/md5") {
system("/sbin/md5 -q $file > $file.md5");
} elsif (-x "/usr/bin/md5sum") {
system("/usr/bin/md5sum $file > $file.md5");
} else {
print STDERR "No md5 utility found. Not producing checksums\n";
}
}
__END__
=head1 NAME
make-release - Make an OpenAFS release from git
=head1 SYNOPSIS
make-release [options] <tag>
Options:
--help brief help message
--man full documentation
--tagpoint <object> create new tag
--last <object> generate changelog and diffs from this point
--dir <dir> output results into this directory
=head1 DESCRIPTION
make-release constructs an OpenAFS release from a local git clone. If run
with just the standard arguments, it will extract the contents of the
specified tag into the current directory, creating src and doc tarballs,
gzipping and bzipping them, and generating md5 hashes. It will also create a
ChangeLog file, listing all of the changes in that release.
This standard behaviour may be modified by the following options
=head1 OPTIONS
=over 8
=item B<--last> I<object>
Generate the ChangeLog starting from I<object>. Also generate a
openafs-$version.diff file in the output directory containing all of the
changes between I<object> and the current tag
=item B<--dir> I<directory>
Instead of generating all of the output in the current directory, place it
in <directory>, which is created if it does not already exist.
=item B<--tagpoint> I<commit|branch>
Rather than using an existing tag, create a new one on the specified commit,
or on the tip of the specified branch. This will GPG sign the new tag, and
push it into gerrit.
=back
=cut