Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make release status configurable #438

Merged
merged 3 commits into from
Apr 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ remove = Some::Package::That::Does::Not::Exist::Due::To::A::Typo
[Breaks]
Dist::Zilla::Plugin::MakeMaker::Awesome = < 0.22
Dist::Zilla::App::Command::stale = < 0.040
Dist::Zilla::Plugin::TrialVersionComment = <= 0.003
Dist::Zilla::Plugin::Run = <= 0.034
Dist::Zilla::App::Command::update = <= 0.04

[Test::CheckBreaks]
conflicts_module = Moose::Conflicts
89 changes: 81 additions & 8 deletions lib/Dist/Zilla.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use MooseX::Types::Perl qw(DistName LaxVersionStr);
use MooseX::Types::Path::Class qw(Dir File);
use Moose::Util::TypeConstraints;

use Dist::Zilla::Types qw(License);
use Dist::Zilla::Types qw(License ReleaseStatus);

use Log::Dispatchouli 1.100712; # proxy_loggers, quiet_fatal
use Path::Class;
Expand Down Expand Up @@ -121,6 +121,65 @@ sub _build_version {
$version;
}

=attr release_status

This attribute sets the release status to one of the
L<CPAN::META::Spec/https://metacpan.org/pod/CPAN::Meta::Spec#release_status>
values: 'stable', 'testing' or 'unstable'.

If the C<$ENV{RELEASE_STATUS}> environment variable exists, its value will
be used as the release status.

For backwards compatibility, if C<$ENV{RELEASE_STATUS}> does not exist and
the C<$ENV{TRIAL}> variable is true, the release status will be 'testing'.

Otherwise, the release status will be set from a
L<ReleaseStatusProvider|Dist::Zilla::Role::ReleaseStatusProvider>, if one
has been configured.

For backwards compatibility, setting C<is_trial> in F<dist.ini> is equivalent
to using a C<ReleaseStatusProvider>.

Only B<one> C<ReleaseStatusProvider> may be used.

If no providers are used, the release status defaults to 'stable'.

=cut

has release_status => (
is => 'ro',
isa => ReleaseStatus,
lazy => 1,
builder => '_build_release_status',
);

sub _build_release_status {
my ($self) = @_;

# environment variables override completely
return $ENV{RELEASE_STATUS} if defined $ENV{RELEASE_STATUS};
return 'testing' if $ENV{TRIAL};

# other ways of setting status must not conflict
my $status;

# dist.ini is equivalent to a release provider
if ( $self->_has_override_is_trial ) {
$status = $self->_override_is_trial ? 'testing' : 'stable';
}

for my $plugin (@{ $self->plugins_with(-ReleaseStatusProvider) }) {
next unless defined(my $this_status = $plugin->provide_release_status);

$self->log_fatal('attempted to set release status twice')
if defined $status;

$status = $this_status;
}

return $status || 'stable';
}

=attr abstract

This is a one-line summary of the distribution. If none is given, one will be
Expand Down Expand Up @@ -448,16 +507,33 @@ has root => (

=attr is_trial

This attribute tells us whether or not the dist will be a trial release.
This attribute tells us whether or not the dist will be a trial release,
i.e. whether it has C<release_status> 'testing' or 'unstable' and will
have '-TRIAL' in the tarball name.

Do not set this directly, it will be derived from C<release_status>.

=cut

has is_trial => (
is => 'rw', # XXX: make SetOnce -- rjbs, 2010-03-23
is => 'ro',
isa => Bool,
default => sub { $ENV{TRIAL} ? 1 : 0 }
init_arg => undef,
lazy => 1,
builder => '_build_is_trial',
);

has _override_is_trial => (
is => 'ro',
init_arg => 'is_trial',
predicate => '_has_override_is_trial',
);

sub _build_is_trial {
my ($self) = @_;
return $self->release_status =~ /\A(?:testing|unstable)\z/;
}

=attr plugins

This is an arrayref of plugins that have been plugged into this Dist::Zilla
Expand Down Expand Up @@ -507,10 +583,7 @@ sub _build_distmeta {
author => $self->authors,
license => [ $self->license->meta2_name ],

# XXX: what about unstable?
release_status => ($self->is_trial or $self->version =~ /_/)
? 'testing'
: 'stable',
release_status => $self->release_status,

dynamic_config => 0, # problematic, I bet -- rjbs, 2010-06-04
generated_by => $self->_metadata_generator_id
Expand Down
9 changes: 7 additions & 2 deletions lib/Dist/Zilla/App/Command/build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ sub execute {
$self->zilla->build_in($opt->in);
} else {
my $method = $opt->tgz ? 'build_archive' : 'build';
my $zilla = $self->zilla;
$zilla->is_trial(1) if $opt->trial;
my $zilla;
{
local $ENV{RELEASE_STATUS} = $ENV{RELEASE_STATUS};
$ENV{RELEASE_STATUS} ||= $opt->trial ? "testing" : "stable";
$zilla = $self->zilla;
$zilla->release_status; # initialize before running method
}
$zilla->$method;
}

Expand Down
10 changes: 7 additions & 3 deletions lib/Dist/Zilla/App/Command/release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ sub opt_spec {
sub execute {
my ($self, $opt, $arg) = @_;

my $zilla = $self->zilla;

$zilla->is_trial(1) if $opt->trial;
my $zilla;
{
local $ENV{RELEASE_STATUS} = $ENV{RELEASE_STATUS};
$ENV{RELEASE_STATUS} ||= $opt->trial ? "testing" : "stable";
$zilla = $self->zilla;
$zilla->release_status; # initialize before running method
}

$self->zilla->release;
}
Expand Down
27 changes: 27 additions & 0 deletions lib/Dist/Zilla/Role/ReleaseStatusProvider.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package Dist::Zilla::Role::ReleaseStatusProvider;
# ABSTRACT: something that provides a release status for the dist

use Moose::Role;
with 'Dist::Zilla::Role::Plugin';

use namespace::autoclean;

=head1 DESCRIPTION

Plugins implementing this role must provide a C<provide_release_status>
method that will be called when setting the dist's version.

If C<provides_release_status> returns undef, it will be ignored.

=cut

requires 'provide_release_status';

1;

=head1 SEE ALSO

Core Dist::Zilla plugins implementing this role:
L<AutoVersion|Dist::Zilla::Plugin::AutoVersion>.

=cut
4 changes: 3 additions & 1 deletion lib/Dist/Zilla/Types.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ that's what you want.

=cut

use MooseX::Types -declare => [qw(License OneZero YesNoStr)];
use MooseX::Types -declare => [qw(License OneZero YesNoStr ReleaseStatus)];
use MooseX::Types::Moose qw(Str Int);

subtype License, as class_type('Software::License');
Expand All @@ -22,6 +22,8 @@ subtype OneZero, as Str, where { $_ eq '0' or $_ eq '1' };

subtype YesNoStr, as Str, where { /\A(?:y|ye|yes)\Z/i or /\A(?:n|no)\Z/i };

subtype ReleaseStatus, as Str, where { /\A(?:stable|testing|unstable)\z/ };

coerce OneZero, from YesNoStr, via { /\Ay/i ? 1 : 0 };

1;
11 changes: 11 additions & 0 deletions t/lib/Dist/Zilla/Plugin/TestReleaseProvider.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package Dist::Zilla::Plugin::TestReleaseProvider;

use Moose;
with(
'Dist::Zilla::Role::ReleaseStatusProvider',
);

sub provide_release_status { 'unstable' }

__PACKAGE__->meta->make_immutable;
1;
135 changes: 135 additions & 0 deletions t/plugins/release_status.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
use strict;
use warnings;
use Test::More 0.88;
use Test::Fatal;

use lib 't/lib';

use Test::DZil;
use JSON::MaybeXS;

# protect from dzil's own release environment
local $ENV{RELEASE_STATUS};
local $ENV{TRIAL};

# TestReleaseProvider sets 'unstable'
subtest "TestReleaseProvider" => sub {
my $tzil = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
{
add_files => {
'source/dist.ini' => simple_ini(
'GatherDir',
'MetaJSON',
'TestReleaseProvider',
),
},
},
);

$tzil->build;

is($tzil->release_status, 'unstable', "release status set from provider");
ok($tzil->is_trial, "is_trial is true");
like($tzil->archive_filename, qr/-TRIAL/, "-TRIAL in archive filename");

my $json = $tzil->slurp_file('build/META.json');
my $meta = JSON::MaybeXS->new(utf8 => 0)->decode($json);
is( $meta->{release_status}, 'unstable', "release status set in META" );
};

for my $c ( qw/true false/ ) {
subtest "is_trial in dist.ini $c" => sub {
my $tzil = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
{
add_files => {
'source/dist.ini' => simple_ini(
{ is_trial => $c eq 'true' ? '1' : '0' },
'GatherDir',
),
},
},
);

$tzil->build;

my $expect = $c eq 'true' ? 'testing' : 'stable';
my $is_trial = $expect eq 'testing' ? 1 : 0;

is($tzil->release_status, $expect, "release status set from is_trial");
if ( $is_trial ) {
ok($tzil->is_trial, "is_trial is true");
like($tzil->archive_filename, qr/-TRIAL/, "-TRIAL in archive filename");
}
else {
ok(! $tzil->is_trial, "is_trial is not true");
unlike($tzil->archive_filename, qr/-TRIAL/, "-TRIAL not in archive filename");
}

};
}

subtest "RELEASE_STATUS" => sub {
local $ENV{RELEASE_STATUS} = 'stable';
local $ENV{TRIAL} = 1;
my $tzil = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
{
add_files => {
'source/dist.ini' => simple_ini(
'GatherDir',
'TestReleaseProvider',
),
},
},
);

$tzil->build;

is($tzil->release_status, 'stable', "release status set from environment");
ok(! $tzil->is_trial, "is_trial is not true");
unlike($tzil->archive_filename, qr/-TRIAL/, "-TRIAL not in archive filename");
};

subtest "TRIAL" => sub {
local $ENV{TRIAL} = 1;
my $tzil = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
{
add_files => {
'source/dist.ini' => simple_ini(
'GatherDir',
'TestReleaseProvider',
),
},
},
);

$tzil->build;

is($tzil->release_status, 'testing', "release status set from environment");
ok($tzil->is_trial, "is_trial is true");
like($tzil->archive_filename, qr/-TRIAL/, "-TRIAL in archive filename");
};

subtest "too many providers" => sub {
my $tzil = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
{
add_files => {
'source/dist.ini' => simple_ini(
{ is_trial => '1' }, 'GatherDir', 'TestReleaseProvider',
),
},
},
);

like(
exception { $tzil->build },
qr/attempted to set release status twice/,
"setting too many times is fatal",
);
};

done_testing;