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