]> Dogcows Code - chaz/p5-Dist-Zilla-PluginBundle-Author-CCM/blob - lib/Dist/Zilla/PluginBundle/Author/CCM.pm
automatically figure out perl_versions for Travis
[chaz/p5-Dist-Zilla-PluginBundle-Author-CCM] / lib / Dist / Zilla / PluginBundle / Author / CCM.pm
1 package Dist::Zilla::PluginBundle::Author::CCM;
2 # ABSTRACT: A plugin bundle for distributions built by CCM
3 # KEYWORDS: dzil author bundle distribution tool
4
5 =head1 SYNOPSIS
6
7 # In your dist.ini file:
8 [@Author::CCM]
9
10 =head1 DESCRIPTION
11
12 You probably don't want to use this.
13
14 ; VERSION
15 [Git::NextVersion]
16 [ReversionOnRelease]
17 prompt = 1
18
19 ; GATHER
20 [Git::GatherDir]
21 exclude_filename = LICENSE
22 exclude_filename = README.md
23 [PruneCruft]
24 [PruneFiles]
25 filename = dist.ini
26
27 [CopyFilesFromBuild]
28 copy = LICENSE
29 [ExecDir]
30
31 ; PREREQS
32 [AutoPrereqs]
33 [Prereqs::FromCPANfile] ; if a cpanfile exists in root
34 [Prereqs::AuthorDeps]
35
36 ; TESTS
37 [MetaTests]
38 [Test::CPAN::Changes]
39 [PodCoverageTests]
40 [PodSyntaxTests]
41 [Test::Pod::No404s]
42 [Test::Compile]
43 [Test::MinimumVersion]
44 max_target_perl = 5.10.1
45 [Test::EOL]
46 [Test::NoTabs]
47 [Test::Perl::Critic]
48 [Test::Portability]
49 [Test::CleanNamespaces]
50 [Test::ReportPrereqs]
51
52 ; METADATA
53 [Authority]
54 do_munging = 0
55 [MetaJSON]
56 [MetaYAML]
57 [MetaNoIndex]
58 directory = eg
59 directory = share
60 directory = shares
61 directory = t
62 directory = xt
63 [MetaProvides::Package]
64 [Keywords]
65 [Git::Contributors]
66 order_by = commits
67 [GithubMeta]
68 issues = 1
69
70 ; MUNGE
71 [PodWeaver]
72 config_plugin = @Author::CCM
73 [OverridePkgVersion]
74
75 ; GENERATE FILES
76 [License]
77 [ReadmeAnyFromPod]
78 filename = README.md
79 locaton = root
80 type = markdown
81 phase = release
82 [ReadmeAnyFromPod]
83 filename = README
84 location = build
85 type = text
86 [TravisYML]
87 build_branch = /^(dist|build\/.*)$/
88 [Manifest]
89 [ManifestSkip]
90
91 [MakeMaker] ; override with the "installer" attribute
92
93 ; RELEASE
94 [NextRelease]
95 [CheckChangesHasContent]
96 [Git::Check]
97 [RunExtraTests]
98 [TestRelease]
99 [ConfirmRelease]
100 [UploadToCPAN] ; disable with the "no_upload" attribute
101 [Git::Commit]
102 commit_msg = Release %N %v%t%n%n%c
103 [Git::CommitBuild]
104 branch =
105 release_branch = dist
106 release_message = Version %v%t
107 [Git::Tag]
108 tag_message = Version %v%t%n%n%c
109 [Git::Push]
110 push_to = origin master +master:refs/heads/release +dist
111 remotes_must_exist = 0
112
113 =head1 SEE ALSO
114
115 =for :list
116 * L<Dist::Zilla>
117 * L<Dist::Zilla::PluginBundle::Author::ETHER>
118
119 =cut
120
121 use 5.014;
122 use warnings;
123 use strict;
124
125 our $VERSION = '999.999'; # VERSION
126
127 use Dist::Zilla::Util;
128 use Moose;
129 use Perl::Version;
130 use namespace::autoclean;
131
132 =attr max_target_perl
133
134 Specify the minimum perl version. Defaults to C<5.10.1>.
135
136 =cut
137
138 has max_target_perl => (
139 is => 'ro',
140 isa => 'Str',
141 lazy => 1,
142 default => sub {
143 my $self = shift;
144 $self->payload->{'Test::MinimumVersion.max_target_perl'} // $self->payload->{max_target_perl} // '5.10.1';
145 },
146 );
147
148 =attr authority
149
150 Specify the release authority. Defaults to C<cpan:CCM>.
151
152 =cut
153
154 has authority => (
155 is => 'ro',
156 isa => 'Str',
157 lazy => 1,
158 default => sub {
159 my $self = shift;
160 $self->payload->{'Authority.authority'} // $self->payload->{authority} // 'cpan:CCM';
161 },
162 );
163
164 =attr installer
165
166 Specify which installer to use, such as:
167
168 =for :list
169 * C<MakeMaker> (default)
170 * C<MakeMaker::Custom>
171
172 =cut
173
174 has installer => (
175 is => 'ro',
176 isa => 'Str',
177 lazy => 1,
178 default => sub { shift->payload->{installer} // 'MakeMaker' },
179 );
180
181 =attr airplane
182
183 Disable plugins that use the network, and prevent releasing.
184
185 =cut
186
187 has airplane => (
188 is => 'ro',
189 isa => 'Bool',
190 lazy => 1,
191 default => sub { $ENV{DZIL_AIRPLANE} // shift->payload->{airplane} // 0 },
192 );
193
194 =attr no_upload
195
196 Do not upload to CPAN or git push.
197
198 =cut
199
200 has no_upload => (
201 is => 'ro',
202 isa => 'Bool',
203 lazy => 1,
204 default => sub { $ENV{DZIL_NO_UPLOAD} // shift->payload->{no_upload} // 0 },
205 );
206
207 =method configure
208
209 Required by L<Dist::Zilla::Role::PluginBundle::Easy>.
210
211 =cut
212
213 sub configure {
214 my $self = shift;
215
216 my @copy_from_build = qw(LICENSE);
217 my @network_plugins = qw(Git::Push Test::Pod::No404s UploadToCPAN);
218 my @gather_exclude = (@copy_from_build, qw(README.md));
219 my @gather_prune = qw(dist.ini);
220 my @no_index = qw(eg share shares t xt);
221 my @allow_dirty = (@copy_from_build, qw(.travis.yml Changes LICENSE README.md));
222 my @git_remotes = qw(github origin);
223 my @check_files = qw(:InstallModules :ExecFiles :TestFiles :ExtraTestFiles);
224 my $perl_version_target = $self->max_target_perl;
225 my ($perl_version, $perl_version_build) = $self->_travis_perl_versions($perl_version_target);
226
227 if ($self->no_upload) {
228 say '[@Author::CCM] WARNING! WARNING! WARNING! *** You are in no_upload mode!! ***';
229 }
230
231 if (!$self->payload->{'TravisYML.support_builddir'}) {
232 # swap perl_version and perl_version_build because DZP::TravisYML got it backwards!
233 # https://github.com/SineSwiper/Dist-Zilla-TravisCI/pull/40
234
235 my $tmp = $self->payload->{'TravisYML.perl_version_build'};
236 if (defined $self->payload->{'TravisYML.perl_version'}) {
237 $self->payload->{'TravisYML.perl_version_build'} = $self->payload->{'TravisYML.perl_version'}
238 }
239 else {
240 delete $self->payload->{'TravisYML.perl_version_build'};
241 }
242 if (defined $tmp) {
243 $self->payload->{'TravisYML.perl_version'} = $tmp;
244 }
245 else {
246 delete $self->payload->{'TravisYML.perl_version'};
247 }
248
249 ($perl_version, $perl_version_build) = ($perl_version_build, $perl_version);
250 }
251
252 my @plugins = (
253
254 # VERSION
255 ['Git::NextVersion'],
256 ['ReversionOnRelease' => {prompt => 1}],
257
258 # GATHER
259 ['Git::GatherDir' => {exclude_filename => [@gather_exclude]}],
260 ['PruneCruft'],
261 ['PruneFiles' => {filename => [@gather_prune]}],
262
263 ['CopyFilesFromBuild' => {copy => [@copy_from_build]}],
264 ['ExecDir'],
265
266 # PREREQS
267 ['AutoPrereqs'],
268 -f 'cpanfile' ? ['Prereqs::FromCPANfile'] : (),
269 ['Prereqs::AuthorDeps'],
270
271 # TESTS
272 ['MetaTests'],
273 ['Test::CPAN::Changes'],
274 ['PodCoverageTests'],
275 ['PodSyntaxTests'],
276 ['Test::Pod::No404s'],
277 ['Test::Compile'],
278 ['Test::MinimumVersion' => {max_target_perl => $perl_version_target}],
279 ['Test::EOL' => {finder => [@check_files]}],
280 ['Test::NoTabs' => {finder => [@check_files]}],
281 ['Test::Perl::Critic'],
282 ['Test::Portability'],
283 ['Test::CleanNamespaces'],
284 ['Test::ReportPrereqs'],
285
286 # METADATA
287 ['Authority' => {authority => $self->authority, do_munging => 0}],
288 ['MetaJSON'],
289 ['MetaYAML'],
290 ['MetaNoIndex' => {directory => [@no_index]}],
291 ['MetaProvides::Package'],
292 ['Keywords'],
293 ['Git::Contributors' => {order_by => 'commits'}],
294 ['GithubMeta' => {remote => [@git_remotes], issues => 1}],
295
296 # MUNGE
297 ['PodWeaver' => {config_plugin => '@Author::CCM'}],
298 ['OverridePkgVersion'],
299
300 # GENERATE FILES
301 ['License'],
302 ['ReadmeAnyFromPod' => 'RepoReadme' => {filename => 'README.md', location => 'root', type => 'markdown', phase => 'release'}],
303 ['ReadmeAnyFromPod' => 'DistReadme' => {filename => 'README', location => 'build', type => 'text'}],
304 ['TravisYML' => {build_branch => '/^(dist|build\/.*)$/', perl_version => $perl_version, perl_version_build => $perl_version_build}],
305 ['Manifest'],
306 ['ManifestSkip'],
307
308 $self->installer, # e.g. MakeMaker
309
310 # RELEASE
311 ['NextRelease'],
312 ['CheckChangesHasContent'],
313 ['Git::Check' => {allow_dirty => [@allow_dirty], untracked_files => 'ignore'}],
314 ['RunExtraTests'],
315 ['TestRelease'],
316 # ['ConfirmRelease'],
317 $self->no_upload ? ['FakeRelease'] : ['UploadToCPAN'],
318 ['Git::Commit' => {allow_dirty => [@allow_dirty], commit_msg => 'Release %N %v%t%n%n%c'}],
319 ['Git::CommitBuild' => {branch => '', release_branch => 'dist', release_message => 'Version %v%t'}],
320 ['Git::Tag' => {tag_message => 'Version %v%t%n%n%c'}],
321 $self->no_upload ? () : ['Git::Push' => {push_to => 'origin master +master:refs/heads/release +dist', remotes_must_exist => 0}],
322
323 );
324
325 if ($self->airplane) {
326 my %network_plugins = map { Dist::Zilla::Util->expand_config_package_name($_) => 1 } @network_plugins;
327
328 @plugins = grep { !$network_plugins{Dist::Zilla::Util->expand_config_package_name(ref eq 'ARRAY' ? $_->[0] : $_)} } @plugins;
329 push @plugins, 'BlockRelease';
330 }
331
332 push @plugins, 'ConfirmRelease';
333
334 $self->add_plugins(@plugins);
335 }
336
337 sub _travis_perl_versions {
338 my $self = shift;
339
340 my $perl_version_target = Perl::Version->new(shift or die 'Missing target version');
341 my $min_version = Perl::Version->new('5.14');
342 my $min_version_build = Perl::Version->new($perl_version_target);
343 $min_version_build->subversion(0);
344
345 my @versions;
346 my @versions_build;
347
348 for my $v (qw{5.26 5.24 5.22 5.20 5.18 5.16 5.14 5.12 5.10 5.8}) {
349 my $version = Perl::Version->new($v);
350 push @versions, "$version" if $version >= $min_version_build && $version >= $min_version;
351 push @versions_build, "$version" if $version >= $min_version_build;
352 }
353
354 my $perl_version = join(' ', @versions);
355 my $perl_version_build = join(' ', @versions_build);
356
357 return ($perl_version, $perl_version_build);
358 }
359
360 with 'Dist::Zilla::Role::PluginBundle::Easy';
361 with 'Dist::Zilla::Role::PluginBundle::PluginRemover';
362 with 'Dist::Zilla::Role::PluginBundle::Config::Slicer';
363
364 __PACKAGE__->meta->make_immutable;
365 1;
This page took 0.056443 seconds and 4 git commands to generate.