2022-07-17 17:24:43 +00:00
|
|
|
package App::Changelord::Command::Bump;
|
|
|
|
|
|
|
|
use 5.36.0;
|
|
|
|
|
|
|
|
use Moo;
|
2022-07-25 15:40:56 +00:00
|
|
|
use CLI::Osprey desc => 'bump next version',
|
|
|
|
description_pod => <<'END';
|
|
|
|
Set a version for the NEXT release based on the types of its changes.
|
|
|
|
Also set the release date of that release to today.
|
|
|
|
END
|
2022-07-17 17:24:43 +00:00
|
|
|
|
|
|
|
use Path::Tiny;
|
|
|
|
use JSON;
|
|
|
|
use YAML qw/ Bless /;
|
|
|
|
use List::AllUtils qw/ first min uniq /;
|
|
|
|
use Version::Dotted::Semantic;
|
|
|
|
|
2022-07-25 15:40:56 +00:00
|
|
|
with 'App::Changelord::Role::Changelog';
|
2022-07-17 17:24:43 +00:00
|
|
|
with 'App::Changelord::Role::ChangeTypes';
|
|
|
|
with 'App::Changelord::Role::Versions';
|
2022-07-20 18:27:53 +00:00
|
|
|
with 'App::Changelord::Role::Stats';
|
2022-07-17 17:24:43 +00:00
|
|
|
|
|
|
|
sub run ($self) {
|
|
|
|
my $bump = shift @ARGV;
|
|
|
|
|
|
|
|
if ( $bump and !grep { $_ eq $bump } qw/ minor major patch / ) {
|
|
|
|
die "invalid bump type '$bump', must be major, minor, or patch\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $version;
|
|
|
|
|
|
|
|
if ($bump) {
|
|
|
|
$version = Version::Dotted::Semantic->new( $self->latest_version );
|
|
|
|
$version->bump($bump);
|
|
|
|
$version = $version->stringify;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$version = $self->next_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $self->changelog->{releases}[0]{version}
|
|
|
|
and $self->changelog->{releases}[0]{version} ne 'NEXT' ) {
|
|
|
|
warn
|
|
|
|
"No change detected since last version, hope you know what you're doing.\n";
|
|
|
|
unshift $self->changelog->{releases}->@*, { version => 'NEXT', };
|
|
|
|
}
|
|
|
|
|
|
|
|
my @time = localtime;
|
|
|
|
|
|
|
|
$self->changelog->{releases}[0]{version} = $version;
|
|
|
|
$self->changelog->{releases}[0]{date} = sprintf "%d-%02d-%02d",
|
|
|
|
$time[5] + 1900, $time[4], $time[3];
|
|
|
|
|
2022-07-20 18:27:53 +00:00
|
|
|
if( $self->changelog->{project}{with_stats} ) {
|
|
|
|
push $self->changelog->{releases}[0]{changes}->@*, {
|
|
|
|
type => 'stats', desc => $self->stats
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-17 17:24:43 +00:00
|
|
|
my $change = $self->changelog;
|
|
|
|
Bless($change)->keys(
|
|
|
|
[ uniq qw/
|
|
|
|
project releases change_types
|
|
|
|
/, sort keys %$change
|
|
|
|
] );
|
|
|
|
Bless( $change->{project} )->keys(
|
|
|
|
[ uniq qw/
|
|
|
|
name homepage
|
|
|
|
/, sort keys $change->{project}->%*
|
|
|
|
] );
|
|
|
|
|
|
|
|
for ( grep { ref } $change->{releases}->@* ) {
|
|
|
|
Bless($_)->keys( [ uniq qw/ version date changes /, sort keys %$_ ] );
|
|
|
|
}
|
|
|
|
|
2022-07-25 15:40:56 +00:00
|
|
|
path( $self->source )->spew( YAML::Dump($change) );
|
2022-07-17 17:24:43 +00:00
|
|
|
|
|
|
|
say "new version minted: $version";
|
|
|
|
}
|
|
|
|
|
|
|
|
'end of App::Changelog::Command::Bump';
|