| 1 | package Minilla::Release::BumpVersion; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use ExtUtils::MakeMaker qw(prompt); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Minilla::Util qw(find_file require_optional cmd is_interactive); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Minilla::Logger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Module::BumpVersion; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use version (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 0 | require_optional( | |||||||||||||||||||||||||||
| 14 | 'Module/BumpVersion.pm', 'Release engineering' | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | 0 | require_optional( | |||||||||||||||||||||||||||
| 17 | 'Version/Next.pm', 'Release engineering' | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=16 SCAR=30.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 9 | my ($self, $project, $opts) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 9 | ▶ | if ($opts->{skip_prepare}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | my $ver = $project->version; | |||||||||||||||||||||||||||
| 26 | 1 | ▶ | if (!$opts->{dry_run} && exists_tag($project->format_tag($ver))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $opts->{"dry_run"} and exists_tag($project->format_tag($ver))
MC/DC0%0/2
not $opts->{"dry_run"} and exists_tag($project->format_tag($ver))
not $opts->{"dry_run"}
exists_tag($project->format_tag($ver))
Truth table33%1/3
not(A) and B
A= not $opts->{"dry_run"}B= exists_tag($project->format_tag($ver))
| |||||||||||||||||||||||||||||
| 27 | 0 | errorf("Sorry, version '%s' is already tagged. Stopping.\n", $ver); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 1 | return; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 8 | ▶ | if (!defined $opts->{version} && !is_interactive()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $opts->{"version"} or is_interactive()
MC/DC100%2/2
defined $opts->{"version"} or is_interactive()
defined $opts->{"version"}
is_interactive()
Truth table100%3/3
A or B
A= defined $opts->{"version"}B= is_interactive()
| |||||||||||||||||||||||||||||
| 33 | 1 | errorf("A version is required when standard input is not a terminal. Run 'minil prepare VERSION', then 'minil release --skip-prepare'.\n"); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | my $ver = defined $opts->{version} | ||||||||||||||||||||||||||||
| 37 | ? $opts->{version} | ||||||||||||||||||||||||||||
| 38 | 7 | ▶ | : prompt("Next Release?", $self->default_new_version($project)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 7 | ▶ | if (defined $opts->{version} || $ver) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opts->{"version"} or $ver
MC/DC0%0/2
defined $opts->{"version"} or $ver
defined $opts->{"version"}
$ver
Truth table66%2/3
A or B
A= defined $opts->{"version"}B= $ver
| |||||||||||||||||||||||||||||
| 41 | # Do not use is_strict. is_strict rejects '5.00_01' style. | ||||||||||||||||||||||||||||
| 42 | 7 | ▶ | if (!version::is_lax($ver)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 2 | errorf("Sorry, version '%s' is invalid. Stopping.\n", $ver); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 5 | my $curr_ver = $project->metadata->version; | |||||||||||||||||||||||||||
| 47 | 5 | ▶ | if (!check_version_compatibility($curr_ver, $ver)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | unless (is_interactive()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 1 | errorf("The version format doesn't match the current one (%s -> %s), and cannot be confirmed without a terminal.\n", $curr_ver, $ver); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 1 | my $msg = sprintf | |||||||||||||||||||||||||||
| 52 | "version: %s\n" . | ||||||||||||||||||||||||||||
| 53 | "current: %s\n" . | ||||||||||||||||||||||||||||
| 54 | "The version format doesn't match the current one.\n" . | ||||||||||||||||||||||||||||
| 55 | "Continue the release with this version? [y/n]", $ver, $curr_ver; | ||||||||||||||||||||||||||||
| 56 | 1 | ▶ | if (prompt($msg) !~ /y/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | errorf("Stop the release due to version format mismatch\n"); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 4 | my @opts; | |||||||||||||||||||||||||||
| 62 | 4 | push @opts, '-set', $ver; | |||||||||||||||||||||||||||
| 63 | 4 | ▶ | if ($opts->{dry_run}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 4 | push @opts, '-dryrun'; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 4 | ▶ | unless ($opts->{dry_run}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $self->bump_version($project, $ver); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # clear old version information | ||||||||||||||||||||||||||||
| 70 | 0 | $project->clear_metadata(); | |||||||||||||||||||||||||||
| 71 | 0 | my $newver = $project->metadata->version; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (exists_tag($project->format_tag($newver))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | errorf("Sorry, version '%s' is already tagged. Stopping.\n", $newver); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub bump_version { | ||||||||||||||||||||||||||
|
Subroutine
bump_version: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ($self, $project, $version) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | for my $file ($project->perl_files) { | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | next if $file =~ /\.t$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | next if $file =~ m{\Ashare/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | next if $file eq 'Makefile.PL' || $file eq 'Build.PL'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file eq "Makefile.PL" or $file eq "Build.PL"
MC/DC0%0/2
$file eq "Makefile.PL" or $file eq "Build.PL"
$file eq "Makefile.PL"
$file eq "Build.PL"
Truth table0%0/3
A or B
A= $file eq "Makefile.PL"B= $file eq "Build.PL"
| |||||||||||||||||||||||||||||
| 87 | # copy from Menlo::CLI::Compat | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | next if grep { $file =~ m!^$_/! } @{$project->no_index->{directory} || []}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$project->no_index->{'directory'} || []
MC/DC0%0/1
$project->no_index->{'directory'} || []
$project->no_index->{'directory'}
Truth table0%0/2
A
A= $project->no_index->{'directory'}
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | next if grep { $file eq $_ } @{$project->no_index->{file} || []}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$project->no_index->{'file'} || []
MC/DC0%0/1
$project->no_index->{'file'} || []
$project->no_index->{'file'}
Truth table0%0/2
A
A= $project->no_index->{'file'}
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $bump = Module::BumpVersion->load($file); | |||||||||||||||||||||||||||
| 92 | 0 | $bump->set_version($version); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub default_new_version { | ||||||||||||||||||||||||||
|
Subroutine
default_new_version: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | 0 | my ($self, $project) = @_; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | @_==2 or die; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | my $curver = $project->metadata->version; | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (not exists_tag($project->format_tag($curver))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $curver; | |||||||||||||||||||||||||||
| 103 | } else { | ||||||||||||||||||||||||||||
| 104 | # $project->metadata->version returns version.pm object. | ||||||||||||||||||||||||||||
| 105 | # But stringify was needed by Version::Next. | ||||||||||||||||||||||||||||
| 106 | 0 | return Version::Next::next_version("$curver"); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 4 | ▶ | sub check_version_compatibility { | ||||||||||||||||||||||||||
|
Subroutine
check_version_compatibility: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | 4 | my ($curr, $next) = @_; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 4 | return version_format($curr) eq version_format($next) | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 23 | ▶ | sub version_format { | ||||||||||||||||||||||||||
|
Subroutine
version_format: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 117 | 23 | local $_ = shift; | |||||||||||||||||||||||||||
| 118 | # All formats accept an optional alpha notation starting with '_'. | ||||||||||||||||||||||||||||
| 119 | return | ||||||||||||||||||||||||||||
| 120 | # ex. 0.11, 3.14, 9.4_1 | ||||||||||||||||||||||||||||
| 121 | 23 | ▶ | /^(?:0|[1-9][0-9]*)\.[0-9]+(?:_[0-9]+)?$/ ? 'decimal' : | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 122 | # ex. v1.2.3, v1.2.3_4, v3.3, v3.4_5 | ||||||||||||||||||||||||||||
| 123 | /^v(?:0|[1-9][0-9]*)(?:\.[0-9]+){1,2}(?:_[0-9]+)?$/ ? 'dotted' : | ||||||||||||||||||||||||||||
| 124 | # ex. 0.1.2, 3.4.5_67 (to distinguish it from the decimal version, it must have exactly two dots) | ||||||||||||||||||||||||||||
| 125 | /^(?:0|[1-9][0-9]*)(?:\.[0-9]+){2}(?:_[0-9]+)?$/ ? 'lax dotted' : | ||||||||||||||||||||||||||||
| 126 | 'unknown'; | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub exists_tag { | ||||||||||||||||||||||||||
|
Subroutine
exists_tag: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 0 | my ( $tag ) = @_; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | my $x = `git tag -l $tag`; | |||||||||||||||||||||||||||
| 133 | 0 | chomp $x; | |||||||||||||||||||||||||||
| 134 | 0 | return !!$x; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 2 | 1; | |||||||||||||||||||||||||||