82 lines
2.2 KiB
Perl
82 lines
2.2 KiB
Perl
package App::Changelord::Command::Bump;
|
|
|
|
use 5.36.0;
|
|
|
|
use Moo;
|
|
use CLI::Osprey desc => 'bump next version';
|
|
|
|
use Path::Tiny;
|
|
use JSON;
|
|
use YAML qw/ Bless /;
|
|
use List::AllUtils qw/ first min uniq /;
|
|
use Version::Dotted::Semantic;
|
|
|
|
with 'App::Changelord::Role::ChangeTypes';
|
|
|
|
has changelog => ( is => 'lazy' );
|
|
|
|
with 'App::Changelord::Role::Versions';
|
|
with 'App::Changelord::Role::Stats';
|
|
|
|
sub _build_changelog ($self) { $self->parent_command->changelog }
|
|
|
|
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];
|
|
|
|
if( $self->changelog->{project}{with_stats} ) {
|
|
push $self->changelog->{releases}[0]{changes}->@*, {
|
|
type => 'stats', desc => $self->stats
|
|
};
|
|
}
|
|
|
|
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 %$_ ] );
|
|
}
|
|
|
|
path( $self->parent_command->source )->spew( YAML::Dump($change) );
|
|
|
|
say "new version minted: $version";
|
|
}
|
|
|
|
'end of App::Changelog::Command::Bump';
|