File Coverage

blib/lib/Dist/Zilla/Plugin/TravisYML.pm
Criterion Covered Total %
statement 12 23 52.1
branch 0 4 0.0
condition 0 2 0.0
subroutine 4 8 50.0
pod n/a
total 16 37 43.2


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::TravisYML;
2              
3             our $AUTHORITY = 'cpan:BBYRD'; # AUTHORITY
4             our $VERSION = '1.14'; # VERSION
5             # ABSTRACT: creates a .travis.yml file for Travis CI
6              
7 1     1   488561 use Moose;
  1         2  
  1         5  
8 1     1   4141 use sanity;
  1         2  
  1         6  
9              
10 1     1   252388 use Dist::Zilla::File::InMemory;
  1         54616  
  1         39  
11 1     1   6 use List::AllUtils 'first';
  1         1  
  1         410  
12              
13             # DZIL role ordering gets really weird here...
14              
15             # FilePruner - Since the .travis.yml file doesn't belong in the build
16             # InstallTool - Both cases need to be here after prereqs are built
17             # AfterRelease - So that we have the build version in the build directory for Git::CommitBuild
18              
19             with 'Dist::Zilla::Role::FilePruner';
20             with 'Dist::Zilla::Role::InstallTool';
21             with 'Dist::Zilla::Role::AfterRelease';
22              
23             with 'Dist::Zilla::Role::FileInjector';
24             with 'Dist::Zilla::Role::TravisYML';
25              
26             around mvp_multivalue_args => sub {
27             my ($orig, $self) = @_;
28              
29             my @start = $self->$orig;
30             return (
31             @start, qw(notify_email notify_irc irc_template extra_env),
32             ### XXX: Yes, this ends up being 7*3*3=63 attributes, but such is the price of progress...
33             (
34             map { $_, $_.'_dzil', $_.'_build' }
35             map { $_, 'pre_'.$_, 'post_'.$_ }
36             @Dist::Zilla::Role::TravisYML::phases
37             ),
38             );
39             };
40              
41             sub prune_files {
42 0     0     my ($self) = @_;
43 0     0     my $file = first { $_->name eq '.travis.yml' } @{$self->zilla->files};
  0            
  0            
44              
45             ### !!! NINJA !!! ###
46 0 0         $self->zilla->prune_file($file) if $file;
47             }
48              
49             # Yes, this plugin has nothing to do with installers, but this is the only way to:
50             #
51             # 1. Make sure things like PruneCruft don't interfere with YAML building.
52             # 2. Create the YAML file -after- prereqs have been finalized
53             # 3. Do it in a way that doesn't actually add any files into the build dir or tar.gz.
54             #
55             # See also: https://github.com/SineSwiper/Dist-Zilla-TravisCI/issues/11
56              
57             sub setup_installer {
58 0     0     my $self = shift;
59 0           $self->build_travis_yml; # Not much here... most of the magic is in the role
60             }
61              
62             sub after_release {
63 0     0     my $self = shift;
64 0 0         return unless $self->build_branch;
65 0   0       my $file = $self->build_travis_yml(1) || return;
66              
67             # Now we have to add the file back in
68 0           $self->add_file(
69             # Since we put the file in the build directory, we have to use InMemory to
70             # prevent the file paths from getting mismatched with what is in zilla->files
71             Dist::Zilla::File::InMemory->new({
72             name => '.travis.yml',
73             content => scalar $file->slurp,
74             mode => $file->stat->mode & 0755, # kill world-writeability
75             })
76             );
77             }
78              
79             __PACKAGE__->meta->make_immutable;
80             42;
81              
82             __END__
83              
84             =pod
85              
86             =encoding UTF-8
87              
88             =head1 NAME
89              
90             Dist::Zilla::Plugin::TravisYML - creates a .travis.yml file for Travis CI
91              
92             =head1 SYNOPSIS
93              
94             [TravisYML]
95             ; defaults
96             build_branch = /^build\/.*/
97             notify_email = 1
98             notify_irc = 0
99             mvdt = 0
100             sudo = 0
101            
102             ; These options are probably a good idea
103             ; if you are going to use a build_branch
104             [Git::CommitBuild]
105             release_branch = build/%b
106             release_message = Release build of v%v (on %b)
107            
108             [@Git]
109             allow_dirty = dist.ini
110             allow_dirty = README
111             allow_dirty = .travis.yml
112             push_to = origin master:master
113             push_to = origin build/master:build/master
114              
115             =head1 DESCRIPTION
116              
117             This plugin creates a C<<< .travis.yml >>> file in your distro for CI smoke testing (or what we like
118             to call L<"chain smoking"|Dist::Zilla::App::Command::chainsmoke/CHAIN SMOKING?>). It will also
119             (optionally) create a separate C<<< .travis.yml >>> file for your build directory after a release.
120              
121             Why two files? Because chain smoking via DZIL will work a lot differently than a traditional
122             C<<< Makefile.PL; make >>>. This tests both your distribution repo environment as well as what a
123             CPAN user would see.
124              
125             Of course, you still need to L<turn on Travis CI|http://docs.travis-ci.com/user/getting-started/>
126             and the remote still needs to be a GitHub repo for any of this to work.
127              
128             =head1 OPTIONS
129              
130             =head2 build_branch
131              
132             This is a regular expression indicating which (build) branches are okay for running through
133             Travis CI, per the L<configuration|http://about.travis-ci.org/docs/user/build-configuration/>'s
134             branch whitelist option. The value will be inserted directly as an C<<< only >>> clause. The default
135             is C<<< /^build\/.*/ >>>.
136              
137             This more or less requires L<Git::CommitBuild|Dist::Zilla::Plugin::Git::CommitBuild> to work.
138             (Ordering is important, too. TravisYML comes before Git::CommitBuild.) You should change
139             this to match up with the C<<< release_branch >>> option, if your build branch is not going to reside
140             in a C<<< build/* >>> structure.
141              
142             Also, if you want to disable build branch testing, you can set this to C<<< 0 >>>.
143              
144             =head2 dzil_branch
145              
146             Like C<<< build_branch >>>, this is a regular expression indicating which branches are okay for
147             running through Travis CI for DZIL chainsmoking. The value will be inserted directly as
148             an C<<< only >>> clause on your main DZIL C<<< .travis.yml >>> file. The default is not set, so that it is
149             ran for all of your branches.
150              
151             If you want to disable "after release" testing, because, say, you're using L<Travis::TestRelease|Dist::Zilla::Plugin::Travis::TestRelease>
152             to test things beforehand, you can restrict Travis to only test the release_testing branches:
153              
154             dzil_branch = /^release_testing\/.*/
155              
156             =head2 notify_email
157              
158             This affects the notification options of the resulting YML file. It can either be set to:
159              
160             =over
161              
162             =item *
163              
164             C<<< 0 >>> = Disable email notification
165              
166             =item *
167              
168             C<<< 1 >>> = Enable email notification, using Travis CI's default email scheme
169              
170             =item *
171              
172             C<<< foo@bar.com >>> (can be multiple; one per line) = Enable email notification to these email
173             addresses
174              
175             =back
176              
177             The default is C<<< 1 >>>.
178              
179             =head2 notify_irc
180              
181             This affects the notification options of the resulting YML file. It can either be set to:
182              
183             =over
184              
185             =item *
186              
187             C<<< 0 >>> = Disable IRC notification
188              
189             =item *
190              
191             C<<< 1 >>> = Enable IRC notification, using the C<<< IRC >>> or C<<< x_irc >>> meta resource value
192              
193             =item *
194              
195             C<<< irc://irc.perl.org/#roomname >>> (can be multiple; one per line) = Enable IRC notification
196             to these IRC serverE<sol>rooms
197              
198             =back
199              
200             The default is C<<< 0 >>>. Please ask permission from the room channel operators before enabling
201             bot notification.
202              
203             =head2 irc_template
204              
205             Only applies when IRC notification is on. The default is:
206              
207             %{branch}#%{build_number} by %{author}: %{message} (%{build_url})
208              
209             This option can be specified more than once for multiple lines. See L<Travis-CI's IRC notification docs|http://about.travis-ci.org/docs/user/notifications/#IRC-notification>
210             for a list of variables that can be used.
211              
212             =head2 perl_version
213              
214             This is a space-delimited option with a list of the perl versions to test against. Versions can
215             be prepended with a dash to indicate that the version is allowed to fail.
216              
217             The default is all of the major stable releases of Perl from 5.8 on up, including the
218             bleeding edge of Perl (called 'blead'). This works even if Travis doesn't actually carry
219             that version, thanks to Haarg's L<Perl Travis Helper tools|http://github.com/haarg/perl-travis-helper>,
220             used by this module to auto-install the right version of Perl via L<Perlbrew|http://perlbrew.pl/>.
221              
222             Versions 5.8 and 'blead' are marked as "allowed to fail" versions. The former is because
223             there are various DZIL plugins that require 5.10. The latter because, well, it's bleeding
224             edge, and the tests may be failing because it's Perl's fault.
225              
226             You can restrict it down to only a few like this:
227              
228             perl_version = 5.10 5.12 5.14.3 -5.8
229              
230             Note that any custom settings here will prevent any newer versions from being auto-added (as this
231             distro is updated).
232              
233             =head2 perl_version_build
234              
235             This is just like C<<< perl_version >>>, except for build branches. Both of these options are used in
236             dual DZIL+build YAML files as well. (See the C<<< support_builddir >>> option for more details.)
237              
238             The default is whatever C<<< perl_version >>> is set to. You may want to force 5.8 to disallow failure:
239              
240             perl_version_build = 5.20 5.18 5.16 5.14 5.12 5.10 5.8
241              
242             This, of course, requires that your module is compatible with 5.8.
243              
244             =head2 mvdt
245              
246             Turning this on enables L<Minimum Version Dependency Testing|Dist::Zilla::TravisCI::MVDT>. This
247             will make your YML file less of a static file, as it will now include commands to forcefully
248             B<downgrade> your dependencies to the lowest version that your prereqs said they would be able
249             to use.
250              
251             While going through the MVDT process is recommended, it can be a royal PITA sometimes, so this
252             option isn't on by default. It's HIGHLY recommended that you read the above doc first to get an
253             idea of what you're diving into.
254              
255             This applies to both YML files.
256              
257             =head2 test_authordeps
258              
259             Controls whether author dependencies will be tested while DZIL chainsmoking. This option
260             is also directly linked to verbosity and parallelization of the author deps:
261              
262             =over
263              
264             =item *
265              
266             C<<< 0 >>> = No tests or verbosity, all files are downloadedE<sol>installed in parallel (10 processes at a time)
267              
268             =item *
269              
270             C<<< 1 >>> = Each module is downloaded one at a time, tested, and with verbosity turned on
271              
272             =back
273              
274             The default is C<<< 0 >>>.
275              
276             =head2 test_deps
277              
278             Just like C<<< test_authordeps >>>, but for the real deps that the module needs. This also affects
279             testing for build chainsmoking as well.
280              
281             The default is C<<< 1 >>>.
282              
283             =head2 support_builddir
284              
285             Controls whether to build a dual DZIL+build YAML or a standard DZIL YAML. This is different than a
286             build branch YAML, as that is solely used for build tests.
287              
288             This new config would add a new env variable and double the number of Travis tests. It is expected
289             that a build directory would be found in C<<< .build/testing >>>. If it doesn't exist, the build tests
290             would essentially be a no-op.
291              
292             This is used by L<Travis::TestRelease|Dist::Zilla::Plugin::Travis::TestRelease>'s release testing
293             branches, if its C<<< create_builddir >>> option is also turned on. However, if you have some other
294             mechanism to dump the build release into that directory (and don't mind a combined DZIL+build master
295             branch), this option could be used to test that sort of branch.
296              
297             Because it can make the config (and Travis tests) kind of messy if you're not using them, the default
298             is C<<< 0 >>>.
299              
300             =head2 sudo
301              
302             Tells Travis CI to use its faster to start container-based infrastrucure which only works with non-root
303             access. If you need root access then set this to C<<< 1 >>> and Travis CI will fall back to the tradional
304             infrastructure.
305              
306             The default is C<<< 0 >>>.
307              
308             =head2 Custom Commands
309              
310             For the most part, the default command sets for TravisYML serves its purpose. However, you may
311             have some unusual situation from within your distro that demands a custom command or two. For
312             that purpose, there is a set of "dynamic" options available to add or replace any part of the
313             command list for Travis.
314              
315             They are in the form of:
316              
317             $pos$phase$filetype
318            
319             $pos = Either 'pre_' or 'post_' (optional)
320             $phase = One of the Travis-CI testing phases (required)
321             $filetype = Either '_dzil' or '_build' (optional)
322              
323             See L<Travis-CI's Build Lifecycle|http://docs.travis-ci.com/user/build-lifecycle/>
324             for a list of phases.
325              
326             The positions determine if the commands are to be added at the beginning (C<<< pre_ >>>), the end (C<<< post_ >>>), or
327             replacing (no prefix) the existing code. Replace entire blocks at your own risk; TravisYML may change
328             the original blocks for bug fixes or new features, and you wouldn't see them if they were replaced.
329              
330             The file type determines if these command changes are for the DZIL YML file (C<<< _dzil >>>), the build YML file
331             (C<<< _build >>>), or both (no suffix).
332              
333             For example, this would give you the following combinations for the 'before_install' phase:
334              
335             before_install = Replace all before_install blocks
336             pre_before_install = Unshift lines to all before_install blocks
337             post_before_install = Push lines to all before_install blocks
338             before_install_dzil = Replace DZIL before_install block
339             pre_before_install_dzil = Unshift lines to DZIL before_install block
340             post_before_install_dzil = Push lines to DZIL before_install block
341             before_install_build = Replace build before_install block
342             pre_before_install_build = Unshift lines to build before_install block
343             post_before_install_build = Push lines to build before_install block
344              
345             These options are all multi-lined, so you can add as many commands as you need:
346              
347             pre_install_dzil = export AUTHOR_TESTING=1
348             pre_install_dzil = echo "Author testing is now "$AUTHOR_TESTING
349              
350             =head1 WHY USE THIS?
351              
352             A common question I get with this plugin is: I<"If .travis.yml is a static file, why bother with a plugin?">
353              
354             Three reasons:
355              
356             1. B<DZIL and Travis-CI interactions> - If you look at the YML file itself, you'll notice that it's not a 5-line
357             file. It's not as simple as telling Travis that this is a Perl distro and GO. Both Travis-CI and DZIL are
358             ever changing platforms, and this plugin will keep things in sync with those two platforms. (For example,
359             Travis VMs recently stopped using a valid nameE<sol>email for git's user.* config items, which impacted DZIL smoking
360             with certain Git plugins. So, TravisYML had to compensate.) I personally use this plugin myself, so if there
361             are new issues that come up, I should be one of the first to notice.
362              
363             2. B<Build branches> - Build branches are great for having a perfect copy of your current release, giving non-DZIL
364             folks a chance to submit patches, and for running a Travis-CI test on something that is close to the CPAN
365             release as possible. However, setting that up can be tricky, and it requires a second YML file just for the build
366             branch. TravisYML manages that by hiding the DZIL C<<< .travis.yml >>> file prior to building, and then creating a new
367             one after release (but before the build branch is commited).
368              
369             3. B<MVDT> - If you want to brave through the L<Minimum Version Dependency Testing|Dist::Zilla::TravisCI::MVDT>
370             process, this will automate the YML generation for you.
371              
372             =head1 AVAILABILITY
373              
374             The project homepage is L<https://github.com/SineSwiper/Dist-Zilla-TravisCI>.
375              
376             The latest version of this module is available from the Comprehensive Perl
377             Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
378             site near you, or see L<https://metacpan.org/module/Dist::Zilla::TravisCI/>.
379              
380             =head1 AUTHOR
381              
382             Brendan Byrd <bbyrd@cpan.org>
383              
384             =head1 COPYRIGHT AND LICENSE
385              
386             This software is Copyright (c) 2015 by Brendan Byrd.
387              
388             This is free software, licensed under:
389              
390             The Artistic License 2.0 (GPL Compatible)
391              
392             =cut