blib/lib/App/Project/Doctor/Check/CI.pm

filter: Statementstmt 85.1% 40 / 47 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 5 / 5 totaltotal 88.8% 64 / 72 CC 5 SCAR 7.1
CC
5
Cov
85%
check
4.7
__ANON__
2.9
BEGIN
1.0
CRAP 2.0
« blib/lib/App/Project/Doctor/Context.pm ↑ Summary blib/lib/App/Project/Doctor/Finding.pm »
1 package App::Project::Doctor::Check::CI;
2  
3 # This check answers a single question: does the distribution have any CI
4 # configuration at all? The detailed per-file validation of GitHub Actions
5 # YAML is handled separately by Check::GitHubActions.
6  
7 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use autodie qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Inherit the standard check interface (name, description, order, can_fix, check).
12 4 ▶use parent -norequire, 'App::Project::Doctor::Check::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # croak dies with the caller's file/line instead of this module's line.
15 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 # File::Spec builds OS-portable paths so the fix works on Windows too.
17 4 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 # Readonly creates true constants; assigning to them throws at runtime.
19 4 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 our $VERSION = '0.02';
22  
23 # Map human-readable CI system names to the path that indicates each one.
24 # The check passes as soon as any of these paths exists under the distro root.
25 4 Readonly::Hash my %CI_PATHS => (
26 'GitHub Actions' => '.github/workflows',
27 'Travis CI' => '.travis.yml',
28 'CircleCI' => '.circleci/config.yml',
29 'AppVeyor' => 'appveyor.yml',
30 );
31  
32 # Return the canonical name used in Finding check_name and report headings.
33 2 ▶sub name { 'CI' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
34 # One-line description shown in --help and verbose output.
35 2 ▶sub description { 'At least one CI configuration is present.' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
36 # Signal that this check can offer an automated fix.
37 2 ▶sub can_fix { 1 }
Subroutine can_fix: called CC=1 SCAR=0.0
Pod documented
38 # Lower number = runs earlier; CI runs after Tests (10) but before GitHubActions (25).
39 5 ▶sub order { 20 }
Subroutine order: called CC=1 SCAR=0.0
Pod documented
40  
41 12 ▶sub check {
Subroutine check: called CC=4 SCAR=15.4
Pod documented
42 12 my ($self, $ctx) = @_;
43 # Guard: $ctx must be an object with file-system helpers.
44 12 ▶ croak 'check requires an App::Project::Doctor::Context' unless ref $ctx;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ctx 1 11 12
45  
46 # Walk through each known CI system and return a pass finding as soon as
47 # we spot one. We sort the keys so the result is deterministic.
48 11 for my $label (sort keys %CI_PATHS) {
49 33 ▶ if ($ctx->has_file($CI_PATHS{$label})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->has_file($CI_PATHS{$label})) 7 26 33
50 # Found a CI config: report success and stop checking.
51 7 return _f(
52 severity => 'pass',
53 message => "CI configuration found ($label).",
54 );
55 }
56 }
57  
58 # No CI config was found at all; offer to generate a GitHub Actions workflow.
59 return _f(
60 severity => 'error',
61 message => 'No CI configuration found (GitHub Actions, Travis, CircleCI, AppVeyor).',
62 1 ▶ fix => sub {
Subroutine __ANON__: called CC=2 SCAR=10.8
63 # The fix creates .github/workflows/perl-ci.yml using the
64 # App::GHGen::Generator functional API.
65 1 my $root = $_[0]->root;
66 1 require App::GHGen::Generator;
67 # generate_workflow returns a YAML string or undef if it fails.
68 1 my $yaml = App::GHGen::Generator::generate_workflow('perl');
69 1 ▶ return unless $yaml; # Nothing to write if generation failed.
Branch: 1 branch
BranchTrueFalseTotal
unless $yaml 1 0 1
70 # Build the target directory path in a cross-platform way.
71 0 my $wf_dir = File::Spec->catdir($root, '.github', 'workflows');
72 0 require File::Path;
73 # make_path creates the directory and all missing parents.
74 0 File::Path::make_path($wf_dir);
75 # Write the generated YAML to the standard workflow file.
76 0 open my $fh, '>', File::Spec->catfile($wf_dir, 'perl-ci.yml');
77 0 print {$fh} $yaml;
78 0 close $fh;
79 },
80 4 );
81 }
82  
83 # ---------------------------------------------------------------------------
84 # Private helper
85 # ---------------------------------------------------------------------------
86  
87 # Purpose: Build a Finding object pre-filled with check_name => 'CI'.
88 # Entry: %args is a valid Finding constructor argument list.
89 # Exit: App::Project::Doctor::Finding object.
90 # Side effects: None.
91 11 ▶sub _f {
Subroutine _f: called CC=1 SCAR=0.0
92 11 require App::Project::Doctor::Finding;
93 # Prepend check_name so callers don't have to repeat it every time.
94 11 return App::Project::Doctor::Finding->new(check_name => 'CI', @_);
95 }
96  
97 4 1;
98  
99 __END__
« blib/lib/App/Project/Doctor/Context.pm ↑ Summary blib/lib/App/Project/Doctor/Finding.pm »