Lint/Rule/UnpinnedActions.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 42 CC 4 SCAR 20.8
CC
4
Cov
0%
check_step
20.0
id
2.0
description
2.0
CRAP 8.0
1 package App::Workflow::Lint::Rule::UnpinnedActions;
2  
3 use strict;
4 use warnings;
5 use Carp qw(croak carp);
6 use parent 'App::Workflow::Lint::Rule';
7  
8 sub id { 'unpinned-actions' }
9 sub description { 'Actions should be pinned to a specific version or SHA' }
10 sub applies_to { 'step' }
11 sub level { 'warning' }
12  
13 sub check_step {
14 my ($self, $step, $ctx) = @_;
15  
16 return () unless exists $step->{uses};
17  
18 my $uses = $step->{uses};
19  
20 # Must contain @version
21 return $self->diag(
22 message => "Action '$uses' is not pinned to a version",
23 path => "/jobs/$ctx->{job_name}/steps/$ctx->{step_index}",
24 file => $ctx->{file},
25 ) unless $uses =~ /\@/;
26  
27 # Disallow @master, @main, @latest
28 return $self->diag(
29 message => "Action '$uses' uses an unsafe tag",
30 path => "/jobs/$ctx->{job_name}/steps/$ctx->{step_index}",
31 file => $ctx->{file},
32 ) if $uses =~ /\@(master|main|latest)$/;
33  
34 return ();
35 }
36  
37 1;
38