add command 'bump'

This commit is contained in:
Yanick Champoux 2022-07-17 13:24:43 -04:00
parent b3972b1062
commit 080add003c
4 changed files with 165 additions and 39 deletions

View File

@ -1,25 +1,30 @@
# yaml-language-server: $schema=./changelog-schema.yaml ---
project: project:
name: App::Changeman name: App::Changeman
homepage: https://git.babyl.ca/yanick/App-Changelord homepage: https://git.babyl.ca/yanick/App-Changelord
change_types:
- feat:
title: Features
level: minor
- fix:
title: Bug fixes
level: patch
releases: releases:
- version: v3.0.2
date: 2022-06-17
changes: ~
- version: v3.0.1
date: 2022-06-17
changes: ~
- version: v3.0.0
date: 2022-06-17
changes: ~
- version: v2.0.0
date: 2022-06-17
changes: ~
- version: v1.2.3 - version: v1.2.3
date: 2022-01-02 date: 2022-01-02
changes: changes:
- type: feat - desc: doing the thing
desc: doing the thing type: feat
- | - |
## [2.0.0](https://github.com/yanick/json-schema-shorthand/compare/v1.0.0...v2.0.0) (2020-08-24) ## [2.0.0](https://github.com/yanick/json-schema-shorthand/compare/v1.0.0...v2.0.0) (2020-08-24)
### ⚠ BREAKING CHANGES ### BREAKING CHANGES
* things should continue to work as normal, but since to * things should continue to work as normal, but since to
typescript is kinda of a big deal, I'm taking no chance. typescript is kinda of a big deal, I'm taking no chance.
@ -64,14 +69,21 @@ releases:
## 0.2.0 2017-01-03 ## 0.2.0 2017-01-03
* Properties can be made required via a '!' suffix. * Properties can be made required via a '!' suffix.
* Drop Mocha and Chai for TAP for testing. * Drop Mocha and Chai for TAP for testing.
- version: 0.1.0
- date: 2016-08-01 date: 2016-08-01
version: 0.1.0
changes: changes:
- Recurse down 'allOf', 'oneOf', 'anyOf', 'not'. - "Recurse down 'allOf', 'oneOf', 'anyOf', 'not'."
- Add 'install' and 'synopsis' sections in doc. - Add 'install' and 'synopsis' sections in doc.
- version: 0.0.1
- date: 2016-07-31 date: 2016-07-31
version: 0.0.1
changes: changes:
- Initial release - Initial release
change_types:
- feat:
level: minor
title: Features
keywords: []
- fix:
level: patch
title: Bug fixes
keywords: []

View File

@ -145,5 +145,6 @@ sub run($self) {
subcommand 'schema' => 'App::Changelord::Command::Schema'; subcommand 'schema' => 'App::Changelord::Command::Schema';
subcommand 'validate' => 'App::Changelord::Command::Validate'; subcommand 'validate' => 'App::Changelord::Command::Validate';
subcommand 'version' => 'App::Changelord::Command::Version'; subcommand 'version' => 'App::Changelord::Command::Version';
subcommand 'bump' => 'App::Changelord::Command::Bump';
'end of App::Changeman'; 'end of App::Changeman';

View File

@ -0,0 +1,74 @@
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';
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];
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';

View File

@ -0,0 +1,39 @@
package App::Changelord::Role::Versions;
use v5.36.0;
use List::AllUtils qw/ first min /;
use Version::Dotted::Semantic;
use Moo::Role;
use feature 'try';
requires 'changelog';
sub latest_version($self){
first { $_ } grep { $_ ne 'NEXT' } map { eval { $_->{version} } } $self->changelog->{releases}->@*;
}
sub next_version($self) {
my $version = Version::Dotted::Semantic->new($self->latest_version // '0.0.0');
my $upcoming = $self->changelog->{releases}[0];
if( $upcoming->{version} and $upcoming->{version} ne 'NEXT') {
$upcoming = { changes => [] };
}
my %mapping = map {
my $level = $_->{level};
map { $_ => $level } $_->{keywords}->@*
} $self->change_types->@*;
my $bump =min 2, map { $_ eq 'major' ? 0 : $_ eq 'minor' ? 1 : 2 } map { $mapping{$_->{type}} || 'patch' } $upcoming->{changes}->@*;
$version->bump($bump);
return $version->normal;
}
1;