lib/App/GHGen/Analyzer.pm

filter: Statementstmt 100% 106 / 106 Branchbran 88.2% 60 / 68 Conditioncond 91.6% 22 / 24 MC/DCmcdc 85.7% 12 / 14 Subroutinesub 100% 17 / 17 Podpod 40.0% 4 / 10 totaltotal 92.4% 221 / 239 CC 55 SCAR 19.8
CC
55
Cov
95%
detect_project_type
11.0
analyze_workflow
10.0
has_broad_triggers
9.0
CRAP 7.3
« blib/lib/App/GHGen/Reporter.pm ↑ Summary lib/App/GHGen/Fixer.pm »
1 package App::GHGen::Analyzer;
2  
3 9 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use YAML::XS qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use App::GHGen::Fixer qw(%ACTION_UPDATES);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 our @EXPORT_OK = qw(
13 analyze_workflow
14 find_workflows
15 get_cache_suggestion
16 );
17  
18 8 our $VERSION = '0.12';
19  
20 =head1 NAME
21  
22 App::GHGen::Analyzer - Analyze GitHub Actions workflows
23  
24 =head1 SYNOPSIS
25  
26 use App::GHGen::Analyzer qw(analyze_workflow);
27  
28 my @issues = analyze_workflow($workflow_hashref, 'ci.yml');
29  
30 =head1 FUNCTIONS
31  
32 =head2 find_workflows()
33  
34 Find all workflow files in .github/workflows directory.
35 Returns a sorted list of L<Path::Tiny> objects.
36  
37 =head3 Purpose
38  
39 Discover every GitHub Actions workflow file under C<.github/workflows> in
40 the current working directory.
41  
42 =head3 Arguments
43  
44 None.
45  
46 =head3 Returns
47  
48 A sorted list of L<Path::Tiny> objects, one per C<.yml> or C<.yaml> file
49 found. Returns an empty list when the directory does not exist or is empty.
50  
51 =head3 Side Effects
52  
53 None. Performs read-only filesystem access.
54  
55 =head3 Usage Example
56  
57 use App::GHGen::Analyzer qw(find_workflows);
58 chdir '/path/to/repo';
59 my @wfs = find_workflows();
60 say $_->basename for @wfs;
61  
62 =head3 API SPECIFICATION
63  
64 =head4 Input
65  
66 # No parameters.
67  
68 =head4 Output
69  
70 { type => 'array', element => { isa => 'Path::Tiny' } }
71  
72 =head3 FORMAL SPECIFICATION
73  
74 FindWorkflows : → seq Path
75  
76 dir ≔ .github/workflows
77 FindWorkflows ≡
78 ¬dir.exists ∨ ¬dir.is_dir → ⟨⟩
79 | otherwise → sort(lex) { f ∈ dir.children ∣ f.name =~ /\.ya?ml$/i }
80  
81 =cut
82  
83 6 ▶sub find_workflows() {
Subroutine find_workflows: called CC=3 SCAR=11.0
Pod documented
84 6 my $workflows_dir = path('.github/workflows');
85  
86 6 ▶ return () unless $workflows_dir->exists && $workflows_dir->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $workflows_dir->exists and $workflows_dir->is_dir 2 4 6
Condition66%2/3
$workflows_dir->exists and $workflows_dir->is_dir
!ll&&!rl&&r
204
MC/DC50%1/2
$workflows_dir->exists and $workflows_dir->is_dir
$workflows_dir->exists $workflows_dir->is_dir
Truth table66%2/3
A and B
A= $workflows_dir->existsB= $workflows_dir->is_dir
ABresult
0X0
100
111
87 4 return sort $workflows_dir->children(qr/\.ya?ml$/i);
88 }
89  
90 =head2 analyze_workflow($workflow, $filename)
91  
92 Analyze a workflow hash for issues. Returns array of issue hashes.
93  
94 Each issue has: C<type>, C<severity>, C<message>, and an optional C<fix>.
95  
96 =head3 Purpose
97  
98 Inspect a parsed GitHub Actions workflow and return a list of detected
99 issues covering performance, security, cost, and maintenance concerns.
100  
101 =head3 Arguments
102  
103 =over 4
104  
105 =item C<$workflow> (HashRef, required)
106  
107 A hash reference representing the parsed workflow (e.g. from C<YAML::XS::LoadFile>).
108 Must contain at least a C<jobs> key whose value is a hash of job definitions.
109  
110 =item C<$filename> (Str, required)
111  
112 The filename of the workflow, used only as context in issue messages.
113  
114 =back
115  
116 =head3 Returns
117  
118 A list (not an array reference) of issue hash references. Each issue has:
119  
120 {
121 type => Str, # 'performance' | 'security' | 'cost' | 'maintenance'
122 severity => Str, # 'high' | 'medium' | 'low'
123 message => Str,
124 fix => Str, # optional: suggested YAML snippet
125 }
126  
127 Returns an empty list when no issues are detected.
128  
129 =head3 Side Effects
130  
131 None. Pure function; does not modify its arguments.
132  
133 =head3 Usage Example
134  
135 use App::GHGen::Analyzer qw(analyze_workflow);
136 use YAML::XS qw(LoadFile);
137  
138 my $wf = LoadFile('.github/workflows/ci.yml');
139 my @issues = analyze_workflow($wf, 'ci.yml');
140 for my $issue (@issues) {
141 say "$issue->{severity}: $issue->{message}";
142 }
143  
144 =head3 API SPECIFICATION
145  
146 =head4 Input
147  
148 {
149 workflow => { type => 'hashref', required => 1 },
150 filename => { type => 'scalar', required => 1 },
151 }
152  
153 =head4 Output
154  
155 {
156 type => 'array',
157 element => {
158 type => 'hashref',
159 keys => {
160 type => { type => 'scalar' },
161 severity => { type => 'scalar' },
162 message => { type => 'scalar' },
163 fix => { type => 'scalar', optional => 1 },
164 },
165 },
166 }
167  
168 =head3 FORMAL SPECIFICATION
169  
170 Issue ≔ { type: IssueType, severity: Severity, message: ℤ*, fix?: ℤ* }
171 IssueType ≔ performance | security | cost | maintenance
172 Severity ≔ high | medium | low
173  
174 analyze_workflow : Workflow × ℤ* → seq Issue
175  
176 ∀ w: Workflow, f: ℤ*:
177 ¬has_caching(w) ⇒ performance∈medium ∈ result(w,f)
178 find_unpinned_actions(w)≠∅ ⇒ security∈high ∈ result(w,f)
179 find_outdated_actions(w)≠∅ ⇒ maintenance∈medium ∈ result(w,f)
180 has_broad_triggers(w) ⇒ cost∈medium ∈ result(w,f)
181 ¬w.concurrency ⇒ cost∈low ∈ result(w,f)
182 has_outdated_runners(w) ⇒ maintenance∈low ∈ result(w,f)
183 ∃ j∈w.jobs: ¬j.timeout-minutes ⇒ performance∈low ∈ result(w,f)
184  
185 =cut
186  
187 37 ▶sub analyze_workflow($workflow, $filename) {
Subroutine analyze_workflow: called CC=10 SCAR=23.0
Pod documented
188 37 my @issues;
189  
190 # Check 1: Missing dependency caching
191 37 ▶ unless (has_caching($workflow)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (has_caching($workflow)) 22 15 37
192 22 my $cache_suggestion = get_cache_suggestion($workflow);
193 22 push @issues, {
194 type => 'performance',
195 severity => 'medium',
196 message => 'No dependency caching found - increases build times and costs',
197 fix => $cache_suggestion
198 };
199 }
200  
201 # Check 2: Using unpinned action versions
202 37 my @unpinned = find_unpinned_actions($workflow);
203 37 ▶ if (@unpinned) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unpinned) 11 26 37
204 push @issues, {
205 type => 'security',
206 severity => 'high',
207 message => 'Found ' . scalar(@unpinned) . " action(s) using \@master or \@main",
208 fix => "Replace \@master/\@main with specific version tags:\n" .
209 11 join("\n", map { " $_" } map { s/\@(master|main)$/\@v5/r } @unpinned[0..min(2, $#unpinned)])
210 };
211 }
212  
213 # Check for outdated action versions
214 37 my @outdated = find_outdated_actions($workflow);
215 37 ▶ if (@outdated) {
Branch: 1 branch
BranchTrueFalseTotal
if (@outdated) 3 34 37
216 push @issues, {
217 type => 'maintenance',
218 severity => 'medium',
219 message => "Found " . scalar(@outdated) . " outdated action(s)",
220 fix => "Update to latest versions:\n" .
221 3 join("\n", map { " $_" } @outdated[0..min(2, $#outdated)])
222 };
223 }
224  
225 # Check 3: Overly broad triggers
226 37 ▶ if (has_broad_triggers($workflow)) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_broad_triggers($workflow)) 12 25 37
227 12 push @issues, {
228 type => 'cost',
229 severity => 'medium',
230 message => 'Workflow triggers on all pushes - consider path/branch filters',
231 fix => "Add trigger filters:\n" .
232 " on:\n" .
233 " push:\n" .
234 " branches: [main, develop]\n" .
235 " paths:\n" .
236 " - 'src/**'\n" .
237 " - 'package.json'"
238 };
239 }
240  
241 # Check 4: Missing concurrency controls
242 37 ▶ unless ($workflow->{concurrency}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($workflow->{"concurrency"}) 18 19 37
243 18 push @issues, {
244 type => 'cost',
245 severity => 'low',
246 message => 'No concurrency group - old runs continue when superseded',
247 fix => "Add concurrency control:\n" .
248 " concurrency:\n" .
249 " group: \${{ github.workflow }}-\${{ github.ref }}\n" .
250 " cancel-in-progress: true"
251 };
252 }
253  
254 # Check 5: Outdated runner versions
255 37 ▶ if (has_outdated_runners($workflow)) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_outdated_runners($workflow)) 8 29 37
256 8 push @issues, {
257 type => 'maintenance',
258 severity => 'low',
259 message => 'Using older runner versions - consider updating',
260 fix => 'Update to ubuntu-latest, macos-latest, or windows-latest'
261 };
262 }
263  
264 # Check 6: Missing timeout-minutes
265 37 ▶my $jobs = $workflow->{jobs} // {};
Condition50%1/2
$workflow->{"jobs"} // {}
l!l
370
MC/DC0%0/1
$workflow->{"jobs"} // {}
$workflow->{"jobs"}
Truth table50%1/2
A
A= $workflow->{"jobs"}
Aresult
11
00
266 37 for my $job_name (keys %$jobs) {
267 36 my $job = $jobs->{$job_name};
268  
269 36 ▶ unless (exists $job->{'timeout-minutes'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $job->{"timeout-minutes"}) 18 18 36
270 18 push @issues, {
271 type => 'performance',
272 severity => 'low',
273 message => "Job '$job_name' is missing timeout-minutes",
274 fix => "Add:\n timeout-minutes: 30",
275 };
276 }
277 }
278  
279 37 return @issues;
280 }
281  
282 =head2 get_cache_suggestion($workflow)
283  
284 Generate a caching suggestion based on detected project type.
285  
286 =head3 Purpose
287  
288 Inspect a workflow for known package-manager commands and return a ready-to-paste
289 C<actions/cache> YAML snippet that matches the detected ecosystem.
290  
291 =head3 Arguments
292  
293 =over 4
294  
295 =item C<$workflow> (HashRef, required)
296  
297 A parsed workflow hash. The function inspects each job's C<steps[].run>
298 commands to detect C<npm>, C<pip>, C<cargo>, or C<bundle>.
299  
300 =back
301  
302 =head3 Returns
303  
304 A non-empty string. When the ecosystem is recognised the string is an
305 C<actions/cache> YAML step snippet; otherwise a generic guidance message.
306  
307 =head3 Side Effects
308  
309 None. Pure function.
310  
311 =head3 Usage Example
312  
313 my $suggestion = get_cache_suggestion($workflow);
314 say $suggestion;
315  
316 =head3 API SPECIFICATION
317  
318 =head4 Input
319  
320 { workflow => { type => 'hashref', required => 1 } }
321  
322 =head4 Output
323  
324 { type => 'scalar' }
325  
326 =head3 FORMAL SPECIFICATION
327  
328 Ecosystem ≔ npm | pip | cargo | bundler | unknown
329  
330 get_cache_suggestion : Workflow → ℤ*
331  
332 ecosystem(w) = npm ⇒ result contains ~/.npm cache path
333 ecosystem(w) = pip ⇒ result contains ~/.cache/pip path
334 ecosystem(w) = cargo ⇒ result contains ~/.cargo path
335 ecosystem(w) = bundler ⇒ result contains vendor/bundle path
336 ecosystem(w) = unknown ⇒ result is a generic guidance message
337  
338 =cut
339  
340 37 ▶sub get_cache_suggestion($workflow) {
Subroutine get_cache_suggestion: called CC=2 SCAR=6.9
Pod documented
341 37 my $detected_type = detect_project_type({ jobs => $workflow->{jobs} });
342  
343 37 my %cache_configs = (
344 npm => "- uses: actions/cache\@v5\n" .
345 " with:\n" .
346 " path: ~/.npm\n" .
347 " key: \${{ runner.os }}-node-\${{ hashFiles('**/package-lock.json') }}\n" .
348 " restore-keys: |\n" .
349 " \${{ runner.os }}-node-",
350  
351 pip => "- uses: actions/cache\@v5\n" .
352 " with:\n" .
353 " path: ~/.cache/pip\n" .
354 " key: \${{ runner.os }}-pip-\${{ hashFiles('**/requirements.txt') }}\n" .
355 " restore-keys: |\n" .
356 " \${{ runner.os }}-pip-",
357  
358 cargo => "- uses: actions/cache\@v5\n" .
359 " with:\n" .
360 " path: |\n" .
361 " ~/.cargo/bin/\n" .
362 " ~/.cargo/registry/index/\n" .
363 " ~/.cargo/registry/cache/\n" .
364 " target/\n" .
365 " key: \${{ runner.os }}-cargo-\${{ hashFiles('**/Cargo.lock') }}",
366  
367 bundler => "- uses: actions/cache\@v5\n" .
368 " with:\n" .
369 " path: vendor/bundle\n" .
370 " key: \${{ runner.os }}-gems-\${{ hashFiles('**/Gemfile.lock') }}\n" .
371 " restore-keys: |\n" .
372 " \${{ runner.os }}-gems-",
373 );
374  
375 37 ▶ return $cache_configs{$detected_type} //
Condition100%2/2
$cache_configs{$detected_type} // "Add caching based on your dependency manager:\n See: https://docs.github.com/en/actions/using-workflows/caching-dependencies"
l!l
1720
MC/DC100%1/1
$cache_configs{$detected_type} // "Add caching based on your dependency manager:\n See: https://docs.github.com/en/actions/using-workflows/caching-dependencies"
$cache_configs{$detected_type}
Truth table100%2/2
A
A= $cache_configs{$detected_type}
Aresult
11
00
376 "Add caching based on your dependency manager:\n" .
377 " See: https://docs.github.com/en/actions/using-workflows/caching-dependencies";
378 }
379  
380 # Helper functions
381  
382 37 ▶sub has_caching($workflow) {
Subroutine has_caching: called CC=7 SCAR=19.5
Pod undocumented
383 37 ▶ my $jobs = $workflow->{jobs} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return 0 36 1 37
384  
385 36 for my $job (values %$jobs) {
386 35 ▶ my $steps = $job->{steps} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $steps = $job->{"steps"} or next 35 0 35
387 35 for my $step (@$steps) {
388 53 ▶ return 1 if $step->{uses} && $step->{uses} =~ /actions\/cache/;
Branch: 1 branch
BranchTrueFalseTotal
if $step->{"uses"} and $step->{"uses"} =~ m[actions/cache]u 16 37 53
Condition100%3/3
$step->{"uses"} and $step->{"uses"} =~ m[actions/cache]u
!ll&&!rl&&r
162116
MC/DC100%2/2
$step->{"uses"} and $step->{"uses"} =~ m[actions/cache]u
$step->{"uses"} $step->{"uses"} =~ m[actions/cache]u
Truth table100%3/3
A and B
A= $step->{"uses"}B= $step->{"uses"} =~ m[actions/cache]u
ABresult
0X0
100
111
389 }
390 }
391 20 return 0;
392 }
393  
394 36 ▶sub find_unpinned_actions($workflow) {
Subroutine find_unpinned_actions: called CC=7 SCAR=19.6
Pod undocumented
395 36 my @unpinned;
396 36 ▶ my $jobs = $workflow->{jobs} or return @unpinned;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return @unpinned 36 0 36
397  
398 36 for my $job (values %$jobs) {
399 35 ▶ my $steps = $job->{steps} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $steps = $job->{"steps"} or next 35 0 35
400 35 for my $step (@$steps) {
401 74 ▶ next unless $step->{uses};
Branch: 1 branch
BranchTrueFalseTotal
unless $step->{"uses"} 27 47 74
402 47 ▶ if ($step->{uses} =~ /\@(?:master|main)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($step->{"uses"} =~ /\@(?:master|main)$/u) 16 31 47
403 16 push @unpinned, $step->{uses};
404 }
405 }
406 }
407 36 return @unpinned;
408 }
409  
410 38 ▶sub has_broad_triggers($workflow) {
Subroutine has_broad_triggers: called CC=9 SCAR=22.0
Pod undocumented
411 38 my $on = $workflow->{on};
412 38 ▶ return 0 unless $on;
Branch: 1 branch
BranchTrueFalseTotal
unless $on 5 33 38
413  
414 # Check if push trigger has no path or branch filters
415 33 ▶ if (ref $on eq 'HASH' && $on->{push}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $on eq "HASH" and $on->{"push"}) 21 12 33
Condition100%3/3
ref $on eq "HASH" and $on->{"push"}
!ll&&!rl&&r
11121
MC/DC100%2/2
ref $on eq "HASH" and $on->{"push"}
ref $on eq "HASH" $on->{"push"}
Truth table100%3/3
A and B
A= ref $on eq "HASH"B= $on->{"push"}
ABresult
0X0
100
111
416 21 my $push = $on->{push};
417 21 ▶ return 1 if ref $push eq '' || (!$push->{paths} && !$push->{branches});
Branch: 1 branch
BranchTrueFalseTotal
if ref $push eq "" or not $push->{"paths"} || $push->{"branches"} 5 16 21
Condition100%6/6
ref $push eq "" or not $push->{"paths"} || $push->{"branches"}
l!l&&r!l&&!r
2316
$push->{'paths'} || $push->{'branches'}
l!l&&r!l&&!r
1153
MC/DC100%3/3
ref $push eq "" or not $push->{"paths"} || $push->{"branches"}
ref $push eq "" $push->{'paths'} $push->{'branches'}
Truth table100%4/4
A or not(B || C)
A= ref $push eq ""B= $push->{'paths'}C= $push->{'branches'}
ABCresult
1XX1
0001
01X0
0010
418 }
419  
420 # Simple array of triggers including 'push'
421 28 ▶ if (ref $on eq 'ARRAY' && grep { $_ eq 'push' } @$on) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $on eq "ARRAY" and grep {$_ eq "push";} @$on) 9 19 28
Condition100%3/3
ref $on eq "ARRAY" and grep {$_ eq "push";} @$on
!ll&&!rl&&r
1819
MC/DC100%2/2
ref $on eq "ARRAY" and grep {$_ eq "push";} @$on
ref $on eq "ARRAY" grep {$_ eq "push";} @$on
Truth table100%3/3
A and B
A= ref $on eq "ARRAY"B= grep {$_ eq "push";} @$on
ABresult
0X0
100
111
422 9 return 1;
423 }
424  
425 19 return 0;
426 }
427  
428 44 ▶sub has_outdated_runners($workflow) {
Subroutine has_outdated_runners: called CC=5 SCAR=16.1
Pod undocumented
429 44 ▶ my $jobs = $workflow->{jobs} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return 0 44 0 44
430  
431 44 for my $job (values %$jobs) {
432 43 ▶ my $runs_on = $job->{'runs-on'} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $runs_on = $job->{"runs-on"} or next 39 4 43
433 39 ▶ return 1 if $runs_on =~ /\A(?:ubuntu-(?:18|16)\.04|macos-10\.15)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $runs_on =~ /\A(?:ubuntu-(?:18|16)\.04|macos-10\.15)\z/u 12 27 39
434 }
435 32 return 0;
436 }
437  
438 42 ▶sub detect_project_type($workflow) {
Subroutine detect_project_type: called CC=11 SCAR=24.0
Pod undocumented
439 42 ▶ return 'unknown' unless ref $workflow eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $workflow eq "HASH" 0 42 42
440  
441 42 ▶ my $jobs = $workflow->{jobs} or return 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return "unknown" 40 2 42
442  
443 40 for my $job (values %$jobs) {
444 38 ▶ my $steps = $job->{steps} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $steps = $job->{"steps"} or next 38 0 38
445 38 for my $step (@$steps) {
446 36 ▶ my $run = $step->{run} // '';
Condition100%2/2
$step->{"run"} // ""
l!l
2610
MC/DC100%1/1
$step->{"run"} // ""
$step->{"run"}
Truth table100%2/2
A
A= $step->{"run"}
Aresult
11
00
447 36 ▶ return 'npm' if $run =~ /npm (?:install|ci)/;
Branch: 1 branch
BranchTrueFalseTotal
if $run =~ /npm (?:install|ci)/u 10 26 36
448 26 ▶ return 'pip' if $run =~ /pip install/;
Branch: 1 branch
BranchTrueFalseTotal
if $run =~ /pip install/u 4 22 26
449 22 ▶ return 'cargo' if $run =~ /cargo (?:build|test)/;
Branch: 1 branch
BranchTrueFalseTotal
if $run =~ /cargo (?:build|test)/u 3 19 22
450 19 ▶ return 'bundler' if $run =~ /bundle install/;
Branch: 1 branch
BranchTrueFalseTotal
if $run =~ /bundle install/u 4 15 19
451 }
452 }
453 19 return 'unknown';
454 }
455  
456 18 ▶sub min($a, $b) {
Subroutine min: called CC=2 SCAR=6.9
Pod undocumented
457 18 ▶ return $a < $b ? $a : $b;
Branch: 1 branch
BranchTrueFalseTotal
$a < $b ? : 3 15 18
458 }
459  
460 =head2 find_outdated_actions($workflow)
461  
462 Return a list of human-readable upgrade notices for any action whose version
463 string is a key in C<App::GHGen::Fixer::ACTION_UPDATES>.
464  
465 =head3 Purpose
466  
467 Detect C<uses:> entries that reference a known-outdated action version.
468 The detection set is derived directly from C<%ACTION_UPDATES> in
469 C<App::GHGen::Fixer>, so it is always in sync with what C<update_actions>
470 can fix: every action flagged here can be auto-fixed, and every action the
471 Fixer knows about is flagged here.
472  
473 =head3 Arguments
474  
475 =over 4
476  
477 =item C<$workflow> (HashRef, required)
478  
479 A parsed workflow hash.
480  
481 =back
482  
483 =head3 Returns
484  
485 A list of strings of the form C<"old/action\@vN E<rarr> new/action\@vM">,
486 one per outdated step found. Returns an empty list when none are detected.
487  
488 =head3 Side Effects
489  
490 None. Pure function.
491  
492 =head3 FORMAL SPECIFICATION
493  
494 find_outdated_actions : Workflow → seq ℤ*
495  
496 outdated ≔ { "$old → $new" ∣ job ∈ w.jobs, step ∈ job.steps,
497 old ∈ dom(%ACTION_UPDATES), step.uses =~ /^\Qold\E/ }
498 result ≔ seq(outdated)
499  
500 =cut
501  
502 37 ▶sub find_outdated_actions($workflow) {
Subroutine find_outdated_actions: called CC=8 SCAR=20.9
Pod documented
503 37 my @outdated;
504 37 ▶ my $jobs = $workflow->{jobs} or return @outdated;
Branch: 1 branch
BranchTrueFalseTotal
my $jobs = $workflow->{"jobs"} or return @outdated 37 0 37
505  
506 # Premise: %ACTION_UPDATES (from Fixer) is the single source of truth.
507 # Conclusion: every action this function flags can also be fixed by update_actions.
508 37 for my $job (values %$jobs) {
509 36 ▶ my $steps = $job->{steps} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $steps = $job->{"steps"} or next 36 0 36
510 36 for my $step (@$steps) {
511 83 ▶ next unless $step->{uses};
Branch: 1 branch
BranchTrueFalseTotal
unless $step->{"uses"} 27 56 83
512 56 my $uses = $step->{uses};
513 56 for my $old (keys %ACTION_UPDATES) {
514 504 ▶ if ($uses =~ /^\Q$old\E/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uses =~ /^\Q$old\E/u) 17 487 504
515 17 push @outdated, "$old → $ACTION_UPDATES{$old}";
516 }
517 }
518 }
519 }
520  
521 37 return @outdated;
522 }
523  
524 =head1 AUTHOR
525  
526 Nigel Horne E<lt>njh@nigelhorne.comE<gt>
527  
528 L<https://github.com/nigelhorne>
529  
530 =head1 LICENCE
531  
532 Copyright 2025-2026 Nigel Horne.
533  
534 Usage is subject to license terms.
535  
536 =cut
537  
538 8 1;
« blib/lib/App/GHGen/Reporter.pm ↑ Summary lib/App/GHGen/Fixer.pm »