[Lxr-commits] CVS: lxr-tools makerelease.pl,NONE,1.1
Brought to you by:
ajlittoz
From: Malcolm B. <mb...@us...> - 2009-03-25 16:14:10
|
Update of /cvsroot/lxr/lxr-tools In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv16436 Added Files: makerelease.pl Log Message: --- NEW FILE: makerelease.pl --- #!/usr/bin/perl -w # Make a release of the LXR tool. Steps are: # - Run all the tests & ensure they pass # - Tag the release in CVS with a tag of the form release-x-y-z (e.g. release-0-9-4) # - Export the tagged files to a new directory lxr-x-y-z # - Create the Changelog: can use cvs2cl.pl script # - tar up the files # - upload to SF servers # - upload new changelog # - send release notification # - Update the tracker version numbers (bugs etc) so defects can be reported # First establish environment - cwd is head of lxr tree etc, release tag etc use strict; use Getopt::Long; my %option; my $NO; my $cwd = `pwd`; chomp $cwd; my $CVSBIN = 'cvs'; my $CVS_EXPORT = 'cvs -d:ext:mb...@lx...:/cvsroot/lxr'; my $TARBIN = 'tar'; GetOptions(\%option, "help!", "tag=s", "noex"); if ($option{'help'}) { print <<END_HELP; Usage: makerelease [--tag=<tagname>] [--options] Interactively releases the LXR project to SourceForge. Script will tag the repository, create the release tarballs, then upload tarball and changelog to SourceForge. Must be run from the top-level directory of the lxr module (i.e. where the "source" and "INSTALL" files are found). Note this relies on administrator rights to the LXR project, and no password SSH login to the SF cvs servers. Options: --noex Do not do any action that alters SF state (useful for seeing what will happen) --tag Use the supplied string as the release tag name END_HELP exit 0; } if ($option{'noex'}) { $NO = 1; } my $tag; check_environment(); run_tests(); $tag = tag_release(); my $version = $tag; $version =~ s/release-(\d+)-(\d+)-(\d+)/$1\.$2\.$3/; create_changelog($tag, $version); create_release_tarball($tag, $version); upload_release($version); upload_changelog($version); send_release_notification($version); exit 1; sub get_tags() { # Get all tags known for the lxr module my $fileh; my $rtn = open($fileh, "-|", "$CVSBIN rlog lxr 2>&1"); die ("Couldn't start CVS rlog") unless $rtn; my %tags; my $matching = 0; while (<$fileh>) { if (m/^symbolic names:$/) { $matching = 1; } if (m/^keyword sub/) { $matching = 0; } if ($matching && m/^\s([\w\-]+):\s[0-9]\./) { $tags{$1} = 1; } } return keys(%tags); } sub tag_to_val { my $tag = shift; my ($major, $minor, $point) = 0; if ($tag =~ m/release-(\d+)-(\d+)-(\d+)/) { $major = $1; $minor = $2; $point = $3; } return ($major, $minor, $point); } sub make_release_tag { my ($major, $minor, $point) = @_; $tag = "release-".$major."-".$minor."-".$point; return $tag; } sub get_last_release_tag() { # Find last release tag # Release tags of form release-X-Y-Z my @tags = get_tags(); my $lasttag; my $lastmajor = 0; my $lastminor = 0; my $lastpoint = 0; my ($maj, $min, $p); $maj = $min = $p = 0; foreach (@tags) { ($maj, $min, $p) = tag_to_val($_); if ($maj > $lastmajor) { $lasttag = $_; $lastmajor = $maj; $lastminor = $min; $lastpoint = $p; } elsif ($maj == $lastmajor && $min > $lastminor) { $lasttag = $_; $lastmajor = $maj; $lastminor = $min; $lastpoint = $p; } elsif ($maj == $lastmajor && $lastminor == $min && $p > $lastpoint) { $lasttag = $_; $lastmajor = $maj; $lastminor = $min; $lastpoint = $p; } } return $lasttag; } # Check environment for sanity sub check_environment { print "Checking environment..."; if(! -e $cwd."/lib/LXR" || ! -e $cwd."/Local.pm") { print "$cwd does not appear to be a top-level LXR directory\n"; print "Continue in this directory [y/N]:"; my $in = <STDIN>; chomp $in; die "Exiting" unless $in =~ /^[Yy]/; } print "Done\n"; } # Run the tests and make sure they pass sub run_tests { print "Running tests..."; print "Done\n"; } # Tag the release in the repository sub tag_release { my $lasttag; my $nexttag; print "Tagging repository...\n"; # Check for release tag argument, or work out sensible tag if (!$option{'tag'}) { $lasttag = get_last_release_tag(); my ($mj, $min, $p) = tag_to_val($lasttag); $nexttag = make_release_tag($mj, $min, $p+1); print "Tag as \"$nexttag\" (last was \"$lasttag\").\n Enter to accept, or type new tag:"; my $in = <STDIN>; chomp $in; $nexttag = $in if $in; } else { $nexttag = $option{'tag'}; } # Now tag my $cmd = "$CVSBIN tag -cR $nexttag 2>&1"; print "[Not executing]" if $NO; print " $cmd\n"; my ($fileh, $rtn); if (! $NO) { $rtn = open($fileh, "-|", $cmd); die "Couldn't execute $cmd" unless $rtn; while (<$fileh>) { if (m/\[tag aborted\]/) { die "Local files don't match repository, aborting!\n"; } } close $fileh; } print "Done\n"; return $nexttag; } ## Create the release tarball - export the tagged version and tar up sub create_release_tarball { my $tag = shift; my $version = shift; print "Creating release tarball...\n"; # Check for pre-existing directories if (-e "../lxr-$version") { die "Directory ../lxr-$version already exists, won't overwrite"; } if (-e "../lxr-$version.tgz") { die "Tarfile ../lxr-$version.tgz already exists, won't overwrite"; } # Export from CVS chdir('..'); my $cmd = "$CVS_EXPORT export -R -r $tag -d lxr-$version lxr > /dev/null 2>&1"; print "[Not executing]" if $NO; print " $cmd\n"; do {system($cmd) == 0 or die "Command failed $?";} unless $NO; # Copy the Changelog across system ("mv $cwd/ChangeLog lxr-$version") == 0 or die "Couldn't copy ChangeLog"; $cmd = "$TARBIN -czvf lxr-$version.tgz lxr-$version > /dev/null 2>&1"; print "[Not executing]" if $NO; print " $cmd\n"; do {system($cmd) == 0 or die "Command failed $!"; } unless $NO; chdir($cwd); print "Done\n"; } ## Create changelog for publishing sub create_changelog { my ($tag, $version) = @_; print "Creating changelog..."; my $cmd = "cvs2cl -T --gmt"; system($cmd) == 0 or die "Couldn't execute cvs2cl"; print "Done\n"; } |