diff --git a/CHANGELOG-sample.yml b/CHANGELOG-sample.yml index 1ed0a75..7a5b7d1 100644 --- a/CHANGELOG-sample.yml +++ b/CHANGELOG-sample.yml @@ -1,77 +1,89 @@ -# yaml-language-server: $schema=./changelog-schema.yaml +--- project: name: App::Changeman homepage: https://git.babyl.ca/yanick/App-Changelord -change_types: - - feat: - title: Features - level: minor - - fix: - title: Bug fixes - level: patch 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 date: 2022-01-02 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) - - - ### ⚠ BREAKING CHANGES - + + + ### BREAKING CHANGES + * things should continue to work as normal, but since to typescript is kinda of a big deal, I'm taking no chance. - + ### Features - + * move project to typescript ([ca3429d](https://github.com/yanick/json-schema-shorthand/commit/ca3429db04ebc183d2b5c000e8d3d2b297a1e001)) - + ## [1.0.0](https://github.com/yanick/json-schema-shorthand/compare/v0.3.2...v1.0.0) (2020-07-30) - - + + ### Features - + * add allOf, anyOf, oneOf, not shorthands ([b47ee27](https://github.com/yanick/json-schema-shorthand/commit/b47ee27671a4861756a74f4ad6b0dc10d10f1a3c)) - + ### [0.3.2](https://github.com/yanick/json-schema-shorthand/compare/v0.3.1...v0.3.2) (2020-01-31) - - + + ### Bug Fixes - + * remove shrinkwrap.yaml from repo ([baf6ca5](https://github.com/yanick/json-schema-shorthand/commit/baf6ca5c27f9f7723afa48796da0627160579839)) - + ## 0.3.1 (https://github.com/yanick/json-schema-shorthand/compare/v0.3.0...v0.3.1) (2020-01-31) - + ### Bug Fixes - + * bump dependency versions to latest (685e13e (https://github.com/yanick/json-schema-shorthand/commit/685e13eba976fda5ba956a105ac2fb039e232860)) - + ## v0.3.0 2018-02-14 - + ## Improvements * New shortcut: '$foo' expands to be `$ref: foo`. * New 'range' shortcut. * New shortcut functions for types `object`, `array`, `number`, `integer`, and `string`. * Add `add_definition` helper function. - + ### Bug Fixes * `shorthand()` deals gracefully with `null` argument. - - + + ## 0.2.0 2017-01-03 * Properties can be made required via a '!' suffix. * Drop Mocha and Chai for TAP for testing. - - - date: 2016-08-01 - version: 0.1.0 + - version: 0.1.0 + date: 2016-08-01 changes: - - Recurse down 'allOf', 'oneOf', 'anyOf', 'not'. + - "Recurse down 'allOf', 'oneOf', 'anyOf', 'not'." - Add 'install' and 'synopsis' sections in doc. - - - date: 2016-07-31 - version: 0.0.1 + - version: 0.0.1 + date: 2016-07-31 changes: - Initial release +change_types: + - feat: + level: minor + title: Features + keywords: [] + - fix: + level: patch + title: Bug fixes + keywords: [] diff --git a/lib/App/Changelord.pm b/lib/App/Changelord.pm index 3a0fdb6..2b21767 100644 --- a/lib/App/Changelord.pm +++ b/lib/App/Changelord.pm @@ -145,5 +145,6 @@ sub run($self) { subcommand 'schema' => 'App::Changelord::Command::Schema'; subcommand 'validate' => 'App::Changelord::Command::Validate'; subcommand 'version' => 'App::Changelord::Command::Version'; +subcommand 'bump' => 'App::Changelord::Command::Bump'; 'end of App::Changeman'; diff --git a/lib/App/Changelord/Command/Bump.pm b/lib/App/Changelord/Command/Bump.pm new file mode 100644 index 0000000..27a2f73 --- /dev/null +++ b/lib/App/Changelord/Command/Bump.pm @@ -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'; diff --git a/lib/App/Changelord/Role/Versions.pm b/lib/App/Changelord/Role/Versions.pm new file mode 100644 index 0000000..1cc7caf --- /dev/null +++ b/lib/App/Changelord/Role/Versions.pm @@ -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;