line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::Version::Git::Flowish; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Dist::Zilla::Plugin::Version::Git::Flowish::VERSION = '0.09'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
59884
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use v5.10; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Get a version number via git and a flow-inspired structure. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with ( |
11
|
|
|
|
|
|
|
'Dist::Zilla::Role::VersionProvider', |
12
|
|
|
|
|
|
|
'Dist::Zilla::Role::TextTemplate' |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has master_regexp => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
isa=>'Str', |
19
|
|
|
|
|
|
|
default => '^master$' |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has release_regexp => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa=>'Str', |
25
|
|
|
|
|
|
|
default => '^release-(\d+.\d+\.\d+)$' |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has tag_regexp => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
isa=>'Str', |
31
|
|
|
|
|
|
|
default => '^(\d.\d+\.\d+)$' |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub provide_version { |
35
|
|
|
|
|
|
|
my ($self) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Get the current branch, so we can decide how to proceed. |
38
|
|
|
|
|
|
|
my ($branch) = `git branch --no-color 2> /dev/null` =~ /^\* (.*)/m; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->log_debug([ 'picked up branch %s', $branch ]); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $version = undef; |
43
|
|
|
|
|
|
|
my $extra_version = $ENV{'FLOWISH_EXTRA_VERSION'}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Let an environment variable override the version. |
46
|
|
|
|
|
|
|
if(exists($ENV{'FLOWISH_VERSION'})) { |
47
|
|
|
|
|
|
|
$self->log_debug([ 'overriden by environment' ]); |
48
|
|
|
|
|
|
|
$version = $ENV{'FLOWISH_VERSION'}; |
49
|
|
|
|
|
|
|
$self->log_debug("Got version from environment"); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Verify that we didn't already get a version from the ENV |
53
|
|
|
|
|
|
|
if(!defined($version)) { |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $master_re = $self->master_regexp; |
56
|
|
|
|
|
|
|
my $release_re = $self->release_regexp; |
57
|
|
|
|
|
|
|
my $tag_re = $self->tag_regexp; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
given($branch) { |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
when(/$master_re/) { |
62
|
|
|
|
|
|
|
# If the branch is master then we'll get the most recent tag and |
63
|
|
|
|
|
|
|
# use it as the version number. |
64
|
|
|
|
|
|
|
$self->log_debug([ 'fetching latest tag due to master branch' ]); |
65
|
|
|
|
|
|
|
my $tag = `git describe --tags --abbrev=0`; |
66
|
|
|
|
|
|
|
$tag =~ /$tag_re/; |
67
|
|
|
|
|
|
|
$version = $1; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
when(/$release_re/) { |
70
|
|
|
|
|
|
|
$self->log_debug([ 'gleaning version from release branch' ]); |
71
|
|
|
|
|
|
|
# If this is a release branch, grab the version number from the |
72
|
|
|
|
|
|
|
# branch name. |
73
|
|
|
|
|
|
|
$version = $1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
default { |
76
|
|
|
|
|
|
|
$self->log_fatal("Couldn't find a version from master or release. Check regexp?"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if(defined($extra_version)) { |
82
|
|
|
|
|
|
|
$self->log_debug("Adding extra version from env"); |
83
|
|
|
|
|
|
|
$version .= '_'.$extra_version; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$self->log_debug([ 'returning version %s', $version ]); |
87
|
|
|
|
|
|
|
return $version; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
92
|
|
|
|
|
|
|
no Moose; |
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |
97
|
|
|
|
|
|
|
=pod |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Dist::Zilla::Plugin::Version::Git::Flowish - Get a version number via git and a flow-inspired structure. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 VERSION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
version 0.09 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# [Version::Git::Flowish] |
110
|
|
|
|
|
|
|
# master_regexp = ^master$ |
111
|
|
|
|
|
|
|
# release_regexp = ^release-(\d+.\d+\.\d+)$ |
112
|
|
|
|
|
|
|
# tag_regexp = ^(\d.\d+\.\d+)$ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 DESCRIPTION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This plugin consumes the Dist::Zilla VersionProvider role and gleans a version |
117
|
|
|
|
|
|
|
number from Git using a structure similar to Vincent Driessen's |
118
|
|
|
|
|
|
|
L<git flow|http://nvie.com/posts/a-successful-git-branching-model/> model. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The idea is to facilitate automated systems, such as continuous integration, |
121
|
|
|
|
|
|
|
to divine version numbers from the branching and release strategies used in |
122
|
|
|
|
|
|
|
our repositories. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Note that, by default, the version numbers used as defaults by this plugin |
125
|
|
|
|
|
|
|
are in the form of C<0.0.0>. This can be changed by manipulating the options |
126
|
|
|
|
|
|
|
shown in the Synopsis. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
It works like this: |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 Environment Variable #1 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The environment variable FLOWISH_VERSION is checked and used if set. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 Branch |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The current branch is attained via a call to git branch and grepping for |
137
|
|
|
|
|
|
|
the leading *. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
git branch --no-color 2> /dev/null |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 Case: Master Branch |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
If the current branch is master, then the most recent tag is attained |
144
|
|
|
|
|
|
|
via: |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
git describe --tags --abbrev=0 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
You can influence how this date is parsed using the C<tag_regexp> option. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 Case: Release Branch |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
If this isn't the master branch, but it begins with "release-" (configurable |
153
|
|
|
|
|
|
|
via C<master_regexp>) then the version number after the release- will be used. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 Environment Variable #2 |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The environment variable FLOWISH_EXTRA_VERSION is checked and appending to the |
158
|
|
|
|
|
|
|
version with an underscore as a separator. This lets you create development |
159
|
|
|
|
|
|
|
versions of whathaveyou. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 And Then? |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
At this point we just give up and return nothing. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Mike Eldridge |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 AUTHOR |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Cory G Watson <gphat@cpan.org> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Infinity Interactive. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
178
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|