| 1 | package App::GHGen::Fixer; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use YAML::XS qw(LoadFile DumpFile); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 13 | apply_fixes | ||||||||||||||||||||||||||||||||||||||||||
| 14 | can_auto_fix | ||||||||||||||||||||||||||||||||||||||||||
| 15 | fix_workflow | ||||||||||||||||||||||||||||||||||||||||||
| 16 | %ACTION_UPDATES | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | Readonly my $DEFAULT_TIMEOUT_MINUTES => 60; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 PACKAGE DATA | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | =head2 %ACTION_UPDATES | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | Canonical mapping of outdated action strings to their current replacements. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 'old/action@vN' => 'old/action@vM' | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | This hash is the B<single source of truth> for action version knowledge. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | Both C<find_outdated_actions> (detection) and C<update_actions> (mutation) | ||||||||||||||||||||||||||||||||||||||||||
| 33 | consume it so that detecting an outdated action always implies the ability | ||||||||||||||||||||||||||||||||||||||||||
| 34 | to fix it — and vice versa. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | Premise 1: the Analyzer reports every key in this hash as "outdated". | ||||||||||||||||||||||||||||||||||||||||||
| 37 | Premise 2: the Fixer replaces every key with its value. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | Conclusion: no detected issue is unfixable, and no fix targets an undetected issue. | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | our %ACTION_UPDATES = ( | |||||||||||||||||||||||||||||||||||||||||
| 43 | 'actions/cache@v4' => 'actions/cache@v5', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 'actions/cache@v3' => 'actions/cache@v5', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 'actions/checkout@v5' => 'actions/checkout@v6', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 'actions/checkout@v4' => 'actions/checkout@v6', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 'actions/checkout@v2' => 'actions/checkout@v6', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 'actions/checkout@v3' => 'actions/checkout@v6', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'actions/setup-node@v3' => 'actions/setup-node@v4', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 'actions/setup-python@v4' => 'actions/setup-python@v5', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 'actions/setup-go@v4' => 'actions/setup-go@v5', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | App::GHGen::Fixer - Auto-fix workflow issues | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | use App::GHGen::Fixer qw(apply_fixes); | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | my $fixed = apply_fixes($workflow, \@issues); | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =head2 can_auto_fix($issue) | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | Determine whether a given issue can be automatically resolved. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | =head3 Purpose | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | Act as a capability gate before calling C<apply_fixes>. Returns true only | ||||||||||||||||||||||||||||||||||||||||||
| 73 | for the four issue types that the Fixer knows how to handle. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | =head3 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | =item C<$issue> (HashRef, required) | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | An issue hash with at least a C<type> key. Recognised types are | ||||||||||||||||||||||||||||||||||||||||||
| 82 | C<performance>, C<security>, C<cost>, and C<maintenance>. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | =head3 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | C<1> (true) when the issue type is auto-fixable; C<0> (false) otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | =head3 Side Effects | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | None. Pure predicate. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =head3 Usage Example | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | if (can_auto_fix($issue)) { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | apply_fixes($workflow, [$issue]); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head4 Input | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | { issue => { type => 'hashref', required => 1 } } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =head4 Output | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | { type => 'scalar' } # boolean: 1 or 0 | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | can_auto_fix : Issue → 𝔹 | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | FixableTypes ≔ { performance, security, cost, maintenance } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | can_auto_fix(i) ≡ i.type ∈ FixableTypes | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 43 | ▶ | sub can_auto_fix($issue) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_auto_fix: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 43 | my %fixable = ( | |||||||||||||||||||||||||||||||||||||||||
| 122 | 'performance' => 1, # Can add caching | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 'security' => 1, # Can update action versions and add permissions | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 'cost' => 1, # Can add concurrency, filters | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 'maintenance' => 1, # Can update runners | ||||||||||||||||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 43 | ▶ | return $fixable{$issue->{type}} // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$fixable{$issue->{"type"}} // 0
MC/DC100%1/1
$fixable{$issue->{"type"}} // 0
$fixable{$issue->{"type"}}
Truth table100%2/2
A
A= $fixable{$issue->{"type"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =head2 apply_fixes($workflow, $issues) | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | Apply all auto-fixable changes from C<$issues> directly to C<$workflow>. | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =head3 Purpose | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | Iterate over C<$issues>, skip issues that are not auto-fixable, and call | ||||||||||||||||||||||||||||||||||||||||||
| 138 | the appropriate internal fix routine for each fixable type/message | ||||||||||||||||||||||||||||||||||||||||||
| 139 | combination. Modifies C<$workflow> in place. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | =head3 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =item C<$workflow> (HashRef, required) | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | The parsed workflow hash to be mutated. | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =item C<$issues> (ArrayRef[HashRef], required) | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | The issues to process. Each must have C<type> and C<message> keys. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =head3 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | The number of individual fix operations applied (an integer ≥ 0). | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =head3 Side Effects | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | Modifies C<$workflow> in place. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | =head3 Usage Example | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | my $n = apply_fixes($workflow, \@issues); | ||||||||||||||||||||||||||||||||||||||||||
| 166 | say "$n fix(es) applied."; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | =head4 Input | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||||||||||||||||
| 173 | workflow => { type => 'hashref', required => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | issues => { type => 'arrayref', required => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | =head4 Output | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | { type => 'scalar' } # non-negative integer | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | apply_fixes : Workflow × seq Issue → ℕ | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | applied ≔ ∑ { fix(w, i) ∣ i ∈ issues, can_auto_fix(i) } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | result ≔ applied | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | Mutates w by applying each fix in sequence. | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # File-scoped dispatch table for apply_fixes. | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # Premise: can_auto_fix guarantees type ∈ {performance,security,cost,maintenance}. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # Conclusion: we only need to match on (type, message pattern) — no further type | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # validation is required inside the loop. | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # Each rule: [ type_string, compiled_pattern, handler_sub ]. | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # Using anonymous delegates (not direct coderefs) so symbol-table mocks work. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | my @_APPLY_RULES = ( | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | ▶ | [ 'performance', qr/caching/, sub($wf) { add_caching($wf) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | [ 'security', qr/unpinned/, sub($wf) { fix_unpinned_actions($wf) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | [ 'security', qr/permissions/, sub($wf) { add_permissions($wf) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | [ 'maintenance', qr/outdated action/, sub($wf) { update_actions($wf) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 8 | ▶ | [ 'cost', qr/concurrency/, sub($wf) { add_concurrency($wf) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | ▶ | [ 'cost', qr/triggers/, sub($wf) { add_trigger_filters($wf) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | ▶ | [ 'maintenance', qr/runner/, sub($wf) { update_runners($wf) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 5 | ▶ | [ 'performance', qr/missing timeout-minutes/, sub($wf) { add_missing_timeout($wf) } ], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 25 | ▶ | sub apply_fixes($workflow, $issues) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_fixes: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 25 | my $modified = 0; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 25 | for my $issue (@$issues) { | |||||||||||||||||||||||||||||||||||||||||
| 213 | # Guard: can_auto_fix is a complete predicate — if it returns false the | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # type is guaranteed not in the dispatch table, so skip immediately. | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 33 | ▶ | next unless can_auto_fix($issue); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 30 | for my $rule (@_APPLY_RULES) { | |||||||||||||||||||||||||||||||||||||||||
| 218 | 161 | my ($type, $pattern, $handler) = @$rule; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 161 | ▶ | if ($issue->{type} eq $type && $issue->{message} =~ $pattern) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$issue->{"type"} eq $type and $issue->{"message"} =~ /$pattern/u
MC/DC100%2/2
$issue->{"type"} eq $type and $issue->{"message"} =~ /$pattern/u
$issue->{"type"} eq $type
$issue->{"message"} =~ /$pattern/u
Truth table100%3/3
A and B
A= $issue->{"type"} eq $typeB= $issue->{"message"} =~ /$pattern/u
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 27 | $modified += $handler->($workflow); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 27 | last; # first-match-wins; one issue maps to exactly one fix | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 25 | return $modified; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | =head2 fix_workflow($file, $issues) | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | Load a workflow YAML file, apply fixes, and write it back to disk. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | =head3 Purpose | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | Persist the results of C<apply_fixes> by reading the workflow from C<$file> | ||||||||||||||||||||||||||||||||||||||||||
| 236 | with C<YAML::XS::LoadFile>, calling C<apply_fixes>, and rewriting the file | ||||||||||||||||||||||||||||||||||||||||||
| 237 | with C<YAML::XS::DumpFile> when at least one fix was applied. | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | =head3 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | =item C<$file> (Str, required) | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | Path to a YAML workflow file. Passed directly to C<YAML::XS::LoadFile>. | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | =item C<$issues> (ArrayRef[HashRef], required) | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | Issues to fix, each with C<type> and C<message> keys. | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | =head3 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | The number of fixes applied (an integer ≥ 0). The file is only rewritten | ||||||||||||||||||||||||||||||||||||||||||
| 256 | when the count is greater than zero. | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | =head3 Side Effects | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | Reads C<$file> from disk; rewrites C<$file> in place when fixes are applied. | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | =head3 Usage Example | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | my $n = fix_workflow('.github/workflows/ci.yml', \@issues); | ||||||||||||||||||||||||||||||||||||||||||
| 265 | say "$n fix(es) written to ci.yml."; | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | =head4 Input | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||
| 272 | file => { type => 'scalar', required => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 273 | issues => { type => 'arrayref', required => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | =head4 Output | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | { type => 'scalar' } # non-negative integer | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | fix_workflow : Path × seq Issue → ℕ | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | w ≔ LoadFile(file) | ||||||||||||||||||||||||||||||||||||||||||
| 285 | fixes ≔ apply_fixes(w, issues) | ||||||||||||||||||||||||||||||||||||||||||
| 286 | fixes > 0 → DumpFile(file, w) | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | result ≔ fixes | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 5 | ▶ | sub fix_workflow($file, $issues) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fix_workflow: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 5 | my $workflow = LoadFile($file); | |||||||||||||||||||||||||||||||||||||||||
| 294 | 5 | my $fixes = apply_fixes($workflow, $issues); | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 5 | ▶ | if ($fixes > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 3 | DumpFile($file, $workflow); | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 5 | return $fixes; | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | # Fix implementations | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 11 | ▶ | sub add_caching($workflow) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_caching: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 11 | ▶ | my $jobs = $workflow->{jobs} or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 11 | my $modified = 0; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 11 | for my $job (values %$jobs) { | |||||||||||||||||||||||||||||||||||||||||
| 310 | 11 | ▶ | my $steps = $job->{steps} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | # Check if already has caching | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 11 | ▶ | my $has_cache = grep { $_->{uses} && $_->{uses} =~ /actions\/cache/ } @$steps; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->{'uses'} && $_->{'uses'} =~ m[actions/cache]u
MC/DC100%2/2
$_->{'uses'} && $_->{'uses'} =~ m[actions/cache]u
$_->{'uses'}
$_->{'uses'} =~ m[actions/cache]u
Truth table100%3/3
A && B
A= $_->{'uses'}B= $_->{'uses'} =~ m[actions/cache]u
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 11 | ▶ | next if $has_cache; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | # Detect project type and add appropriate cache | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 8 | my $cache_step = detect_and_create_cache_step($steps); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 8 | ▶ | next unless $cache_step; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | # Insert cache step after checkout | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 6 | my $insert_at = 0; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 6 | for my $i (0 .. $#$steps) { | |||||||||||||||||||||||||||||||||||||||||
| 323 | 8 | ▶ | if ($steps->[$i]->{uses} && $steps->[$i]->{uses} =~ /actions\/checkout/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$steps->[$i]{"uses"} and $steps->[$i]{"uses"} =~ m[actions/checkout]u
MC/DC50%1/2
$steps->[$i]{"uses"} and $steps->[$i]{"uses"} =~ m[actions/checkout]u
$steps->[$i]{"uses"}
$steps->[$i]{"uses"} =~ m[actions/checkout]u
Truth table66%2/3
A and B
A= $steps->[$i]{"uses"}B= $steps->[$i]{"uses"} =~ m[actions/checkout]u
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | $insert_at = $i + 1; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 6 | splice @$steps, $insert_at, 0, $cache_step; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 6 | $modified++; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 11 | return $modified; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 17 | ▶ | sub detect_and_create_cache_step($steps) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
detect_and_create_cache_step: called CC=13 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | # Detect project type from steps | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 17 | for my $step (@$steps) { | |||||||||||||||||||||||||||||||||||||||||
| 339 | 25 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | # Node.js | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 25 | ▶ | if ($run =~ /npm (?:install|ci)/ || ($step->{uses} && $step->{uses} =~ /setup-node/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$run =~ /npm (?:install|ci)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-node/u
$step->{"uses"} and $step->{"uses"} =~ /setup-node/u
MC/DC100%3/3
$run =~ /npm (?:install|ci)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-node/u
$run =~ /npm (?:install|ci)/u
$step->{"uses"}
$step->{"uses"} =~ /setup-node/u
Truth table100%4/4
A or B and C
A= $run =~ /npm (?:install|ci)/uB= $step->{"uses"}C= $step->{"uses"} =~ /setup-node/u
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 8 | name => 'Cache dependencies', | |||||||||||||||||||||||||||||||||||||||||
| 345 | uses => 'actions/cache@v5', | ||||||||||||||||||||||||||||||||||||||||||
| 346 | with => { | ||||||||||||||||||||||||||||||||||||||||||
| 347 | path => '~/.npm', | ||||||||||||||||||||||||||||||||||||||||||
| 348 | key => '${{ runner.os }}-node-${{ hashFiles(\'**/package-lock.json\') }}', | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 'restore-keys' => '${{ runner.os }}-node-', | ||||||||||||||||||||||||||||||||||||||||||
| 350 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 351 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | # Python | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 17 | ▶ | if ($run =~ /pip install/ || ($step->{uses} && $step->{uses} =~ /setup-python/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$run =~ /pip install/u or $step->{"uses"} and $step->{"uses"} =~ /setup-python/u
$step->{"uses"} and $step->{"uses"} =~ /setup-python/u
MC/DC100%3/3
$run =~ /pip install/u or $step->{"uses"} and $step->{"uses"} =~ /setup-python/u
$run =~ /pip install/u
$step->{"uses"}
$step->{"uses"} =~ /setup-python/u
Truth table100%4/4
A or B and C
A= $run =~ /pip install/uB= $step->{"uses"}C= $step->{"uses"} =~ /setup-python/u
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 2 | name => 'Cache pip packages', | |||||||||||||||||||||||||||||||||||||||||
| 358 | uses => 'actions/cache@v5', | ||||||||||||||||||||||||||||||||||||||||||
| 359 | with => { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | path => '~/.cache/pip', | ||||||||||||||||||||||||||||||||||||||||||
| 361 | key => '${{ runner.os }}-pip-${{ hashFiles(\'**/requirements.txt\') }}', | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 'restore-keys' => '${{ runner.os }}-pip-', | ||||||||||||||||||||||||||||||||||||||||||
| 363 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 364 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | # Rust | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 15 | ▶ | if ($run =~ /cargo (?:build|test)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | name => 'Cache cargo', | |||||||||||||||||||||||||||||||||||||||||
| 371 | uses => 'actions/cache@v5', | ||||||||||||||||||||||||||||||||||||||||||
| 372 | with => { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | path => "~/.cargo/bin/\n~/.cargo/registry/index/\n~/.cargo/registry/cache/\n~/.cargo/git/db/\ntarget/", | ||||||||||||||||||||||||||||||||||||||||||
| 374 | key => '${{ runner.os }}-cargo-${{ hashFiles(\'**/Cargo.lock\') }}', | ||||||||||||||||||||||||||||||||||||||||||
| 375 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 376 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # Go | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 14 | ▶ | if ($run =~ /go (?:build|test)/ || ($step->{uses} && $step->{uses} =~ /setup-go/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$run =~ /go (?:build|test)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-go/u
$step->{"uses"} and $step->{"uses"} =~ /setup-go/u
MC/DC100%3/3
$run =~ /go (?:build|test)/u or $step->{"uses"} and $step->{"uses"} =~ /setup-go/u
$run =~ /go (?:build|test)/u
$step->{"uses"}
$step->{"uses"} =~ /setup-go/u
Truth table100%4/4
A or B and C
A= $run =~ /go (?:build|test)/uB= $step->{"uses"}C= $step->{"uses"} =~ /setup-go/u
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | name => 'Cache Go modules', | |||||||||||||||||||||||||||||||||||||||||
| 383 | uses => 'actions/cache@v5', | ||||||||||||||||||||||||||||||||||||||||||
| 384 | with => { | ||||||||||||||||||||||||||||||||||||||||||
| 385 | path => '~/go/pkg/mod', | ||||||||||||||||||||||||||||||||||||||||||
| 386 | key => '${{ runner.os }}-go-${{ hashFiles(\'**/go.sum\') }}', | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 'restore-keys' => '${{ runner.os }}-go-', | ||||||||||||||||||||||||||||||||||||||||||
| 388 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 389 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | ▶ | sub fix_unpinned_actions($workflow) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fix_unpinned_actions: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 2 | ▶ | my $jobs = $workflow->{jobs} or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | my $modified = 0; | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | for my $job (values %$jobs) { | |||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | ▶ | my $steps = $job->{steps} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 2 | for my $step (@$steps) { | |||||||||||||||||||||||||||||||||||||||||
| 403 | 6 | ▶ | next unless $step->{uses}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 6 | ▶ | if ($step->{uses} =~ /^(.+?)\@(?:master|main)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 4 | my $action = $1; | |||||||||||||||||||||||||||||||||||||||||
| 407 | # Map to appropriate version | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 4 | my $version = get_latest_version($action); | |||||||||||||||||||||||||||||||||||||||||
| 409 | 4 | $step->{uses} = "$action\@$version"; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 4 | $modified++; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | return $modified; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 4 | ▶ | sub add_permissions($workflow) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_permissions: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 4 | ▶ | return 0 if $workflow->{permissions}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 3 | $workflow->{permissions} = { contents => 'read' }; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 4 | ▶ | sub update_actions($workflow) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_actions: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | ▶ | my $jobs = $workflow->{jobs} or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 4 | my $modified = 0; | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | # Premise: %ACTION_UPDATES is the canonical version table (defined above). | ||||||||||||||||||||||||||||||||||||||||||
| 430 | # Conclusion: this function and find_outdated_actions (Analyzer) are always in sync. | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 4 | for my $job (values %$jobs) { | |||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | ▶ | my $steps = $job->{steps} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 4 | for my $step (@$steps) { | |||||||||||||||||||||||||||||||||||||||||
| 434 | 17 | ▶ | next unless $step->{uses}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 16 | for my $old (keys %ACTION_UPDATES) { | |||||||||||||||||||||||||||||||||||||||||
| 436 | 144 | ▶ | if ($step->{uses} =~ /^\Q$old\E/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 13 | $step->{uses} = $ACTION_UPDATES{$old}; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 13 | $modified++; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 4 | return $modified; | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 10 | ▶ | sub add_concurrency($workflow) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_concurrency: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 10 | ▶ | return 0 if $workflow->{concurrency}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | $workflow->{concurrency} = { | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 9 | group => '${{ github.workflow }}-${{ github.ref }}', | |||||||||||||||||||||||||||||||||||||||||
| 452 | 'cancel-in-progress' => 'true', | ||||||||||||||||||||||||||||||||||||||||||
| 453 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 9 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 9 | ▶ | sub add_trigger_filters($workflow) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_trigger_filters: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 9 | ▶ | my $on = $workflow->{on} or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 8 | my $modified = 0; | |||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | # If 'on' is just 'push', expand it | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 8 | ▶ | if (ref $on eq 'ARRAY' && grep { $_ eq 'push' } @$on) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
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
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | $workflow->{on} = { | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 3 | push => { | |||||||||||||||||||||||||||||||||||||||||
| 465 | branches => ['main', 'master'], | ||||||||||||||||||||||||||||||||||||||||||
| 466 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 467 | pull_request => { | ||||||||||||||||||||||||||||||||||||||||||
| 468 | branches => ['main', 'master'], | ||||||||||||||||||||||||||||||||||||||||||
| 469 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 470 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 3 | $modified++; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | ▶ | elsif (ref $on eq 'HASH' && $on->{push} && ref $on->{push} eq '') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
ref $on eq "HASH" and $on->{"push"} and ref $on->{"push"} eq ""
ref $on eq "HASH" and $on->{"push"}
MC/DC66%2/3
ref $on eq "HASH" and $on->{"push"} and ref $on->{"push"} eq ""
ref $on eq "HASH"
$on->{"push"}
ref $on->{"push"} eq ""
Truth table75%3/4
A and B and C
A= ref $on eq "HASH"B= $on->{"push"}C= ref $on->{"push"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | # 'push' with no filters | ||||||||||||||||||||||||||||||||||||||||||
| 475 | $on->{push} = { | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | branches => ['main', 'master'], | |||||||||||||||||||||||||||||||||||||||||
| 477 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 1 | $modified++; | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 8 | return $modified; | |||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 6 | ▶ | sub add_missing_timeout($workflow) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_missing_timeout: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 6 | ▶ | my $jobs = $workflow->{jobs} or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 6 | my $modified = 0; | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 6 | for my $job_name (keys %$jobs) { | |||||||||||||||||||||||||||||||||||||||||
| 489 | 7 | my $job = $jobs->{$job_name}; | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | # Skip if timeout already exists | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 7 | ▶ | next if exists $job->{'timeout-minutes'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | # Insert default timeout | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 6 | $job->{'timeout-minutes'} = $DEFAULT_TIMEOUT_MINUTES; | |||||||||||||||||||||||||||||||||||||||||
| 496 | 6 | $modified++; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 6 | return $modified; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 8 | ▶ | sub update_runners($workflow) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_runners: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 8 | ▶ | my $jobs = $workflow->{jobs} or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 8 | my $modified = 0; | |||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 8 | my %runner_updates = ( | |||||||||||||||||||||||||||||||||||||||||
| 507 | 'ubuntu-18.04' => 'ubuntu-latest', | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 'ubuntu-16.04' => 'ubuntu-latest', | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 'macos-10.15' => 'macos-latest', | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 'windows-2016' => 'windows-latest', | ||||||||||||||||||||||||||||||||||||||||||
| 511 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 8 | for my $job (values %$jobs) { | |||||||||||||||||||||||||||||||||||||||||
| 514 | 8 | ▶ | my $runs_on = $job->{'runs-on'} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 7 | ▶ | if (exists $runner_updates{$runs_on}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 5 | $job->{'runs-on'} = $runner_updates{$runs_on}; | |||||||||||||||||||||||||||||||||||||||||
| 518 | 5 | $modified++; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 8 | return $modified; | |||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 8 | ▶ | sub get_latest_version($action) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_latest_version: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 8 | my %versions = ( | |||||||||||||||||||||||||||||||||||||||||
| 527 | 'actions/checkout' => 'v6', | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 'actions/cache' => 'v5', | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 'actions/setup-node' => 'v4', | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 'actions/setup-python' => 'v5', | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 'actions/setup-go' => 'v5', | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 'actions/upload-artifact' => 'v4', | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 'actions/download-artifact' => 'v4', | ||||||||||||||||||||||||||||||||||||||||||
| 534 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 8 | ▶ | return $versions{$action} // 'v4'; # Default fallback | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$versions{$action} // "v4"
MC/DC100%1/1
$versions{$action} // "v4"
$versions{$action}
Truth table100%2/2
A
A= $versions{$action}
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | Nigel Horne E<lt>njh@nigelhorne.comE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | L<https://github.com/nigelhorne> | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | Copyright 2025-2026 Nigel Horne. | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | Usage is subject to license terms. | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | The license terms of this software are as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||