| File: | blib/lib/Git/ReleaseRepo/Command/release.pm |
| Coverage: | 89.7% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Git::ReleaseRepo::Command::release; | ||||||
| 2 | # ABSTRACT: Perform a release | ||||||
| 3 | |||||||
| 4 | 2 2 2 | 14470 2 31 | use strict; | ||||
| 5 | 2 2 2 | 4 2 25 | use warnings; | ||||
| 6 | 2 2 2 | 4 2 6 | use Moose; | ||||
| 7 | 2 2 2 | 7092 3 6 | use Git::ReleaseRepo -command; | ||||
| 8 | 2 2 2 | 264 2 11 | use Git::Repository; | ||||
| 9 | |||||||
| 10 | with 'Git::ReleaseRepo::WithVersionPrefix'; | ||||||
| 11 | |||||||
| 12 | sub description { | ||||||
| 13 | 0 | 1 | 0 | return 'Perform a release'; | |||
| 14 | } | ||||||
| 15 | |||||||
| 16 | around opt_spec => sub { | ||||||
| 17 | my ( $orig, $self ) = @_; | ||||||
| 18 | return ( | ||||||
| 19 | $self->$orig(), | ||||||
| 20 | [ 'bugfix' => 'Release a bugfix release from the release branch' ], | ||||||
| 21 | ); | ||||||
| 22 | }; | ||||||
| 23 | |||||||
| 24 | augment execute => sub { | ||||||
| 25 | my ( $self, $opt, $args ) = @_; | ||||||
| 26 | my ( $version, $branch_version ); | ||||||
| 27 | my $git = $self->git; | ||||||
| 28 | my $prefix = $self->release_prefix; | ||||||
| 29 | if ( $args->[0] ) { | ||||||
| 30 | $version = $args->[0]; | ||||||
| 31 | ( $branch_version ) = $args->[0] =~ m/^($prefix\d+[.]\d+)/; | ||||||
| 32 | } | ||||||
| 33 | else { | ||||||
| 34 | my $latest_version = $git->latest_version; | ||||||
| 35 | my @parts = $latest_version ? split /[.]/, $latest_version | ||||||
| 36 | : ( "${prefix}0", 0, 0 ); # Our first release! | ||||||
| 37 | if ( $opt->{bugfix} ) { | ||||||
| 38 | # Bugfix releases increment the third number | ||||||
| 39 | $parts[2]++; | ||||||
| 40 | } | ||||||
| 41 | else { | ||||||
| 42 | # Normal releases increment the second number | ||||||
| 43 | $parts[1]++; | ||||||
| 44 | $parts[2] = 0; | ||||||
| 45 | } | ||||||
| 46 | # Remove anything after the 3rd number. If they wanted more, they | ||||||
| 47 | # should have given us an argument! | ||||||
| 48 | $version = join ".", @parts[0..2]; | ||||||
| 49 | $branch_version = join ".", @parts[0..1]; | ||||||
| 50 | } | ||||||
| 51 | print "Release version $version\n"; | ||||||
| 52 | print "Starting release cycle $branch_version\n" if !$opt->{bugfix}; | ||||||
| 53 | if ( $opt->bugfix ) { | ||||||
| 54 | $git->checkout( $git->latest_release_branch ); | ||||||
| 55 | } | ||||||
| 56 | else { | ||||||
| 57 | $git->checkout; | ||||||
| 58 | } | ||||||
| 59 | # Release all modules too! | ||||||
| 60 | for my $module ( keys $git->submodule ) { | ||||||
| 61 | my $subgit = $git->submodule_git( $module ); | ||||||
| 62 | if ( !$opt->{bugfix} ) { | ||||||
| 63 | $self->branch_release( $subgit, $branch_version ); | ||||||
| 64 | } | ||||||
| 65 | $self->tag_release( $subgit, $version ); | ||||||
| 66 | } | ||||||
| 67 | if ( !$opt->{bugfix} ) { | ||||||
| 68 | $self->branch_release( $git, $branch_version ); | ||||||
| 69 | } | ||||||
| 70 | $self->tag_release( $git, $version ); | ||||||
| 71 | }; | ||||||
| 72 | |||||||
| 73 | sub branch_release { | ||||||
| 74 | 5 | 0 | 12 | my ( $self, $git, $version ) = @_; | |||
| 75 | 5 | 15 | $git->run( branch => $version ); | ||||
| 76 | 5 | 33601 | if ( $git->has_remote( 'origin' ) ) { | ||||
| 77 | 3 | 16 | $git->command( push => origin => "$version:$version" ); | ||||
| 78 | } | ||||||
| 79 | } | ||||||
| 80 | |||||||
| 81 | sub tag_release { | ||||||
| 82 | 10 | 0 | 22 | my ( $self, $git, $version ) = @_; | |||
| 83 | 10 | 26 | $git->run( tag => $version ); | ||||
| 84 | 10 | 57810 | if ( $git->has_remote( 'origin' ) ) { | ||||
| 85 | 6 | 30 | $git->command( push => origin => '--tags' ); | ||||
| 86 | } | ||||||
| 87 | } | ||||||
| 88 | |||||||
| 89 | 1; | ||||||