Dist::Zilla::Plugin::Git::NextVersion - provide a version number by bumping the last git release tag


Dist-Zilla-Plugin-Git documentation Contained in the Dist-Zilla-Plugin-Git distribution.

Index


Code Index:

NAME

Top

Dist::Zilla::Plugin::Git::NextVersion - provide a version number by bumping the last git release tag

VERSION

Top

version 1.111590

SYNOPSIS

Top

In your dist.ini:

    [Git::NextVersion]
    first_version = 0.001       ; this is the default
    version_regexp  = ^v(.+)$   ; this is the default

DESCRIPTION

Top

This does the Dist::Zilla::Role::VersionProvider role. It finds the last version number from your git tags, increments it using Version::Next, and uses the result as the version parameter for your distribution.

The plugin accepts the following options:

You can also set the V environment variable to override the new version. This is useful if you need to bump to a specific version. For example, if the last tag is 0.005 and you want to jump to 1.000 you can set V = 1.000.

  $ V=1.000 dzil release

AUTHOR

Top

Jerome Quelin

COPYRIGHT AND LICENSE

Top


Dist-Zilla-Plugin-Git documentation Contained in the Dist-Zilla-Plugin-Git distribution.

#
# This file is part of Dist-Zilla-Plugin-Git
#
# This software is copyright (c) 2009 by Jerome Quelin.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;

package Dist::Zilla::Plugin::Git::NextVersion;
BEGIN {
  $Dist::Zilla::Plugin::Git::NextVersion::VERSION = '1.111590';
}
# ABSTRACT: provide a version number by bumping the last git release tag

use Dist::Zilla 4 ();
use Git::Wrapper;
use Version::Next ();
use version 0.80 ();

use Moose;
use namespace::autoclean 0.09;

with 'Dist::Zilla::Role::VersionProvider';

# -- attributes

has version_regexp  => ( is => 'ro', isa=>'Str', default => '^v(.+)$' );

has first_version  => ( is => 'ro', isa=>'Str', default => '0.001' );

# -- role implementation

sub provide_version {
  my ($self) = @_;

  # override (or maybe needed to initialize)
  return $ENV{V} if exists $ENV{V};

  local $/ = "\n"; # Force record separator to be single newline

  my $git  = Git::Wrapper->new('.');
  my $regexp = $self->version_regexp;

  my @tags = $git->tag;
  @tags = map { /$regexp/ ? $1 : () } @tags;
  return $self->first_version unless @tags;

  # find highest version from tags
  my ($last_ver) =  sort { version->parse($b) <=> version->parse($a) }
  grep { eval { version->parse($_) }  } @tags;

  $self->log_fatal("Could not determine last version from tags")
  unless defined $last_ver;

  my $new_ver = Version::Next::next_version($last_ver);
  $self->log("Bumping version from $last_ver to $new_ver");

  $self->zilla->version("$new_ver");
}

__PACKAGE__->meta->make_immutable;
no Moose;
1;




__END__