Skip to content

add trial_num attribute to Dist::Zilla and --trial-num option to dzil build and dzil release #730

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions lib/Dist/Zilla.pm
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,21 @@ sub _build_is_trial {
return $self->release_status =~ /\A(?:testing|unstable)\z/ ? 1 : 0;
}

=attr trial_num

This attribute designates an optional trial number if the dist will be a
trial release.

=cut

has trial_num => (
is => 'rw',
isa => 'Maybe[Int]',
init_arg => undef,
lazy => 1,
default => undef,
);

=attr plugins

This is an arrayref of plugins that have been plugged into this Dist::Zilla
Expand Down
11 changes: 9 additions & 2 deletions lib/Dist/Zilla/App/Command/build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Dist::Zilla::App -command;

=head1 SYNOPSIS

dzil build [ --trial ] [ --tgz | --no-tgz ] [ --in /path/to/build/dir ]
dzil build [ --trial ] [ --trial-num=# ] [ --tgz | --no-tgz ] [ --in /path/to/build/dir ]

=head1 DESCRIPTION

Expand Down Expand Up @@ -62,6 +62,7 @@ sub abstract { 'build your dist' }

sub opt_spec {
[ 'trial' => 'build a trial release that PAUSE will not index' ],
[ 'trial-num=i' => 'optional trial release number (implies --trial)' ],
[ 'tgz!' => 'build a tarball (default behavior)', { default => 1 } ],
[ 'in=s' => 'the directory in which to build the distribution' ]
}
Expand All @@ -73,6 +74,11 @@ sub opt_spec {
This will build a trial distribution. Among other things, it will generally
mean that the built tarball's basename ends in F<-TRIAL>.

=head2 --trial-num

Specifies an optional trial release number and implies C<--trial>. This will
be appended to the built tarball's trial designation, e.g. F<-TRIAL9>.

=head2 --tgz | --no-tgz

Builds a .tar.gz in your project directory after building the distribution.
Expand Down Expand Up @@ -101,9 +107,10 @@ sub execute {
{
# isolate changes to RELEASE_STATUS to zilla construction
local $ENV{RELEASE_STATUS} = $ENV{RELEASE_STATUS};
$ENV{RELEASE_STATUS} = 'testing' if $opt->trial;
$ENV{RELEASE_STATUS} = 'testing' if $opt->trial or defined $opt->trial_num;
$zilla = $self->zilla;
}
$zilla->trial_num($opt->trial_num) if defined $opt->trial_num;
$zilla->$method;
}

Expand Down
8 changes: 7 additions & 1 deletion lib/Dist/Zilla/App/Command/release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use Dist::Zilla::App -command;

dzil release --trial

dzil release --trial-num 3

# long form, jobs takes an integer
dzil release --jobs 9

Expand All @@ -27,6 +29,8 @@ Available options are:

=item C<--trial>, will cause it to build a trial build.

=item C<--trial-num=i>, optional trial release number (implies --trial).

=item C<--jobs|-j=i>, number of test jobs run in parallel using L<Test::Harness|Test::Harness>.

=back
Expand All @@ -43,6 +47,7 @@ sub abstract { 'release your dist' }

sub opt_spec {
[ 'trial' => 'build a trial release that PAUSE will not index' ],
[ 'trial-num=i' => 'optional trial release number (implies --trial)' ],
[ 'jobs|j=i' => 'number of parallel test jobs to run' ],
}

Expand All @@ -53,10 +58,11 @@ sub execute {
{
# isolate changes to RELEASE_STATUS to zilla construction
local $ENV{RELEASE_STATUS} = $ENV{RELEASE_STATUS};
$ENV{RELEASE_STATUS} = 'testing' if $opt->trial;
$ENV{RELEASE_STATUS} = 'testing' if $opt->trial or defined $opt->trial_num;
$zilla = $self->zilla;
}

$self->zilla->trial_num($opt->trial_num) if defined $opt->trial_num;
local $ENV{HARNESS_OPTIONS} = join ':', split(':', $ENV{HARNESS_OPTIONS} // ''), 'j'.$opt->jobs if $opt->jobs;
$self->zilla->release;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Dist/Zilla/Dist/Builder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,11 @@ This method will return the filename, without the format extension

sub archive_basename {
my ($self) = @_;
my $trial_slug = '-TRIAL';
$trial_slug .= $self->trial_num if defined $self->trial_num;
return join q{},
$self->dist_basename,
( $self->is_trial && $self->version !~ /_/ ? '-TRIAL' : '' ),
( $self->is_trial && $self->version !~ /_/ ? $trial_slug : '' ),
;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Dist/Zilla/Plugin/NextRelease.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ use String::Formatter 0.100680 stringf => {
E => sub { $_[0]->_user_info('email') },
U => sub { $_[0]->_user_info('name') },
T => sub { $_[0]->zilla->is_trial
? ($_[1] // '-TRIAL') : '' },
? ($_[1] // ('-TRIAL' . ($_[0]->zilla->trial_num // '') ) ) : '' },
V => sub { $_[0]->zilla->version
. ($_[0]->zilla->is_trial
? ($_[1] // '-TRIAL') : '') },
? ($_[1] // ('-TRIAL' . ($_[0]->zilla->trial_num // '') ) ) : '') },
P => sub {
my $releaser = first { $_->can('cpanid') } @{ $_[0]->zilla->plugins_with('-Releaser') };
$_[0]->log_fatal('releaser doesn\'t provide cpanid, but %P used') unless $releaser;
Expand Down Expand Up @@ -231,10 +231,10 @@ The distribution version
= C<%{-TRIAL}T>
Expands to -TRIAL (or any other supplied string) if this
is a trial release, or the empty string if not. A bare C<%T> means
C<%{-TRIAL}T>.
C<%{-TRIAL}T>, with the distribution trial number appended if set.

= C<%{-TRIAL}V>
Equivalent to C<%v%{-TRIAL}T>, to allow for the application of modifiers such
Equivalent to C<%v%T>, to allow for the application of modifiers such
as space padding to the entire version string produced.

= C<%{CLDR format}d>
Expand Down
4 changes: 3 additions & 1 deletion t/plugins/archive_builder.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ my $tzil = Builder->from_config(
},
);

$tzil->trial_num(42);
my $fooball = $tzil->build_archive;

note "fooball = $fooball";
note "is_trial = @{[ $tzil->is_trial ]}";
note "trial_num = @{[ $tzil->trial_num ]}";

my @payload = JSON::MaybeXS->new->decode( $fooball->slurp_raw )->@*;

is $payload[0], 'DZT-Sample-0.001-TRIAL';
is $payload[0], 'DZT-Sample-0.001-TRIAL42';
ok -d $payload[1];
is $payload[2], 'DZT-Sample-0.001';

Expand Down
52 changes: 52 additions & 0 deletions t/plugins/nextrelease.t
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,32 @@ END_CHANGES
);
}

{
local $ENV{TRIAL} = 1;

my $tzil_trial = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
{
add_files => {
'source/Changes' => $changes,
'source/dist.ini' => simple_ini(
'GatherDir',
[ NextRelease => { format => "%v%T", } ],
),
},
},
);

$tzil_trial->trial_num(0);
$tzil_trial->build;

like(
$tzil_trial->slurp_file('build/Changes'),
qr{0.001-TRIAL0},
"adding -TRIAL with trial num works",
);
}

{
local $ENV{TRIAL} = 1;

Expand All @@ -248,6 +274,32 @@ END_CHANGES
);
}

{
local $ENV{TRIAL} = 1;

my $tzil_trial = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
{
add_files => {
'source/Changes' => $changes,
'source/dist.ini' => simple_ini(
'GatherDir',
[ NextRelease => { format => "%-14V ohhai", } ],
),
},
},
);

$tzil_trial->trial_num(6);
$tzil_trial->build;

like(
$tzil_trial->slurp_file('build/Changes'),
qr{0.001-TRIAL6 ohhai},
"adding -TRIAL with trial num works",
);
}

{
my $tzil = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
Expand Down
42 changes: 42 additions & 0 deletions t/plugins/release_status.t
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,46 @@ subtest "from version (testing)" => sub {
unlike($tzil->archive_filename, qr/-TRIAL/, "no -TRIAL in archive filename");
};

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

$tzil->trial_num(1);
$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 number set (testing)" => sub {
local $ENV{RELEASE_STATUS} = 'testing';
my $tzil = Builder->from_config(
{ dist_root => 'corpus/dist/DZT' },
{
add_files => {
'source/dist.ini' => simple_ini(
'GatherDir',
),
},
},
);

$tzil->trial_num(1);
$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/-TRIAL1/, "-TRIAL1 in archive filename");
};

done_testing;
Loading