From: Graham Knop Date: Sun, 17 Aug 2014 16:08:49 +0000 (-0400) Subject: add version bumping make targets X-Git-Tag: v0.002000~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8ab5ea70c51d8601bdab7a310b9893fed7afc9b2;p=p5sagit%2FDistar.git add version bumping make targets --- diff --git a/helpers/bump-version b/helpers/bump-version new file mode 100755 index 0000000..b9c2092 --- /dev/null +++ b/helpers/bump-version @@ -0,0 +1,86 @@ +#!/usr/bin/env perl + +use strict; +use warnings FATAL => 'all'; +use File::Find; + +sub version_parts { + my @parts = split /\./, shift; + if (@parts == 2) { + my $dec = pop @parts; + push @parts, $dec =~ /(\d{1,3})/g; + } + $_ += 0 for @parts; + push @parts, 0 + until @parts >= 3; + return @parts; +} + +chomp(my $LATEST = qx(grep '^[0-9]' Changes | head -1 | awk '{print \$1}')); + +my @parts = version_parts($LATEST); + +my $OLD_DECIMAL = sprintf('%i.%03i%03i', @parts); + +my %bump_part = (major => 0, minor => 1, bugfix => 2); + +my @new_parts = @parts; + +my $bump_this = $bump_part{$ARGV[0]||'bugfix'}; + +if (defined $bump_this) { + $new_parts[$bump_this]++; + $new_parts[$_] = 0 for ($bump_this+1 .. $#new_parts); +} +elsif ($ARGV[0] =~ /^[0-9]+(?:\.[0-9]+)*$/) { + @new_parts = version_parts($ARGV[0]); +} +else { + die "no idea which part to bump - $ARGV[0] means nothing to me" +} + +my $NEW_DECIMAL = sprintf('%i.%03i%03i', @new_parts); + +warn "Bumping $OLD_DECIMAL -> $NEW_DECIMAL\n"; +my $vstring = join('.', @parts); + +my %files; +find({ + no_chdir => 1, + wanted => sub { + return + unless -f && /\.pod$|\.pm$/; + my $file = $_; + open my $fh, '<', $file + or die "can't open $file: $!"; + my $content = do { local $/; <$fh> }; + close $fh; + + $content =~ s{ + ( \$VERSION \s* = \s* ) + (['"]?) v?([.0-9]+) \2 + ( + \s*; + (?: \s*\#\s* )? + ) + (v?[.0-9]+)? + }{ + die "unable to bump version number in $file from $OLD_DECIMAL, found $3\n" + if $3 ne $OLD_DECIMAL && $3 ne $vstring; + $1 . "'" . $NEW_DECIMAL . "'" . $4 . ( + $5 ? $vstring : '' + ) + }xe + or return; + + $files{$file} = $content; + }, +}, 'lib'); + +for my $file (sort keys %files) { + warn " updating $file\n"; + open my $fh, '>', $file + or die "can't open $file: $!"; + print { $fh } $files{$file}; + close $fh; +} diff --git a/lib/Distar.pm b/lib/Distar.pm index f8e18e7..3fddeb0 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -149,7 +149,14 @@ sub run_preflight { sub dist_test { my $self = shift; - my $dist_test = $self->SUPER::dist_test(@_) . <<'END' + my $dist_test = $self->SUPER::dist_test(@_); + + my $include = ''; + if (open my $fh, '<', 'maint/Makefile.include') { + $include = "\n# --- Makefile.include:\n" . do { local $/; <$fh> }; + } + + $dist_test .= <<'END' # --- Distar section: preflight: @@ -172,11 +179,21 @@ distmanicheck: create_distdir nextrelease: $(ABSPERLRUN) Distar/helpers/add-changelog-heading $(VERSION) Changes git add -p Changes +END + for my $type ('', 'minor', 'major') { + if ($include !~ /^bump$type:/m) { + my $arg = $type || '$(V)'; + $dist_test .= <<"END" +bump$type: + Distar/helpers/bump-version $arg + rm Makefile END - if (open my $fh, '<', 'maint/Makefile.include') { - $dist_test .= do { local $/; <$fh> }; + } } + + $dist_test .= $include . "\n"; + return $dist_test; } }