| 1 | package App::GHGen::CostEstimator; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use YAML::XS qw(LoadFile); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 8 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||
| 11 | estimate_current_usage | ||||||||||||||||||||||||||||||||
| 12 | estimate_savings | ||||||||||||||||||||||||||||||||
| 13 | estimate_workflow_cost | ||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 8 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | App::GHGen::CostEstimator - Estimate CI costs and savings | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | use App::GHGen::CostEstimator qw(estimate_current_usage); | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | my $estimate = estimate_current_usage(\@workflows); | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | =head2 estimate_current_usage($workflows) | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | Estimate current monthly CI usage based on workflow configurations. | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | =head3 Purpose | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | Load and analyse every workflow file in C<$workflows>, then aggregate | ||||||||||||||||||||||||||||||||
| 37 | estimated runs, minutes, and cost into a single summary hash. | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | =head3 Arguments | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | =over 4 | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | =item C<$workflows> (ArrayRef[Path::Tiny], required) | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | Array reference of L<Path::Tiny> objects pointing to YAML workflow files. | ||||||||||||||||||||||||||||||||
| 46 | Each file is loaded with C<YAML::XS::LoadFile>. | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | =back | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | =head3 Returns | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | A hash reference with keys: | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||
| 55 | total_minutes => Num, | ||||||||||||||||||||||||||||||||
| 56 | billable_minutes => Num, # 0 when within free tier (2 000 min/month) | ||||||||||||||||||||||||||||||||
| 57 | monthly_cost => Num, # USD; 0 when within free tier | ||||||||||||||||||||||||||||||||
| 58 | workflows => ArrayRef[ estimate_workflow_cost result ], | ||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | =head3 Side Effects | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | Reads each workflow file from disk via C<YAML::XS::LoadFile>. | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | =head3 Usage Example | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | use App::GHGen::CostEstimator qw(estimate_current_usage); | ||||||||||||||||||||||||||||||||
| 68 | use App::GHGen::Analyzer qw(find_workflows); | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | my @wfs = find_workflows(); | ||||||||||||||||||||||||||||||||
| 71 | my $usage = estimate_current_usage(\@wfs); | ||||||||||||||||||||||||||||||||
| 72 | printf "Monthly cost: \$%.2f\n", $usage->{monthly_cost}; | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | =head4 Input | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | { workflows => { type => 'arrayref', required => 1 } } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | =head4 Output | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||
| 83 | type => 'hashref', | ||||||||||||||||||||||||||||||||
| 84 | keys => { | ||||||||||||||||||||||||||||||||
| 85 | total_minutes => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 86 | billable_minutes => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 87 | monthly_cost => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 88 | workflows => { type => 'arrayref' }, | ||||||||||||||||||||||||||||||||
| 89 | }, | ||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | FREE_TIER ≔ 2000 | ||||||||||||||||||||||||||||||||
| 95 | COST_PER_MIN ≔ 0.008 | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | estimate_current_usage : seq Path → UsageSummary | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | total ≔ ∑ { estimate_workflow_cost(f).minutes_per_month ∣ f ∈ workflows } | ||||||||||||||||||||||||||||||||
| 100 | billable ≔ max(0, total − FREE_TIER) | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | result ≔ { | ||||||||||||||||||||||||||||||||
| 103 | total_minutes ↦ total, | ||||||||||||||||||||||||||||||||
| 104 | billable_minutes ↦ billable, | ||||||||||||||||||||||||||||||||
| 105 | monthly_cost ↦ billable × COST_PER_MIN, | ||||||||||||||||||||||||||||||||
| 106 | workflows ↦ [ estimate_workflow_cost(f) ∣ f ∈ workflows ], | ||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 10 | ▶ | sub estimate_current_usage($workflows) { | ||||||||||||||||||||||||||||||
|
Subroutine
estimate_current_usage: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 112 | 10 | my $total_minutes = 0; | |||||||||||||||||||||||||||||||
| 113 | 10 | my @workflow_costs; | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 10 | for my $wf_file (@$workflows) { | |||||||||||||||||||||||||||||||
| 116 | 11 | my $workflow = LoadFile($wf_file); | |||||||||||||||||||||||||||||||
| 117 | 10 | my $cost = estimate_workflow_cost($workflow, $wf_file->basename); | |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 10 | $total_minutes += $cost->{minutes_per_month}; | |||||||||||||||||||||||||||||||
| 120 | 10 | push @workflow_costs, $cost; | |||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | # GitHub pricing (approximate) | ||||||||||||||||||||||||||||||||
| 124 | # Free tier: 2,000 minutes/month for private repos | ||||||||||||||||||||||||||||||||
| 125 | # Additional: $0.008 per minute | ||||||||||||||||||||||||||||||||
| 126 | 9 | my $cost_per_minute = 0.008; | |||||||||||||||||||||||||||||||
| 127 | 9 | my $free_tier = 2000; | |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 9 | ▶ | my $billable_minutes = $total_minutes > $free_tier ? ($total_minutes - $free_tier) : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 9 | my $monthly_cost = $billable_minutes * $cost_per_minute; | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | return { | ||||||||||||||||||||||||||||||||
| 134 | 9 | total_minutes => $total_minutes, | |||||||||||||||||||||||||||||||
| 135 | billable_minutes => $billable_minutes, | ||||||||||||||||||||||||||||||||
| 136 | monthly_cost => $monthly_cost, | ||||||||||||||||||||||||||||||||
| 137 | workflows => \@workflow_costs, | ||||||||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | =head2 estimate_workflow_cost($workflow, $filename) | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | Estimate the monthly CI cost of a single parsed workflow. | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | =head3 Purpose | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | Compute estimated runs per month, average run duration, and total minute | ||||||||||||||||||||||||||||||||
| 148 | usage for one workflow, based on its trigger configuration and step complexity. | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | =head3 Arguments | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | =over 4 | ||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | =item C<$workflow> (HashRef, required) | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | A parsed workflow hash (e.g. from C<YAML::XS::LoadFile>). | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | =item C<$filename> (Str, required) | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | Filename string used as a display label when C<$workflow-E<gt>{name}> is absent. | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | =back | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | =head3 Returns | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | A hash reference: | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||
| 169 | name => Str, | ||||||||||||||||||||||||||||||||
| 170 | file => Str, | ||||||||||||||||||||||||||||||||
| 171 | runs_per_month => Num, | ||||||||||||||||||||||||||||||||
| 172 | minutes_per_run => Num, | ||||||||||||||||||||||||||||||||
| 173 | minutes_per_month => Num, # == runs_per_month * minutes_per_run | ||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | =head3 Side Effects | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | None. Pure function. | ||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | =head3 Usage Example | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | my $cost = estimate_workflow_cost($workflow, 'ci.yml'); | ||||||||||||||||||||||||||||||||
| 183 | printf "%s: %d min/month\n", $cost->{name}, $cost->{minutes_per_month}; | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | =head4 Input | ||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||||||
| 190 | workflow => { type => 'hashref', required => 1 }, | ||||||||||||||||||||||||||||||||
| 191 | filename => { type => 'scalar', required => 1 }, | ||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | =head4 Output | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||||||
| 197 | type => 'hashref', | ||||||||||||||||||||||||||||||||
| 198 | keys => { | ||||||||||||||||||||||||||||||||
| 199 | name => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 200 | file => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 201 | runs_per_month => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 202 | minutes_per_run => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 203 | minutes_per_month => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 204 | }, | ||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | estimate_workflow_cost : Workflow × ℤ* → CostRecord | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | runs ≔ estimate_runs_per_month(w) | ||||||||||||||||||||||||||||||||
| 212 | dur ≔ estimate_duration(w) | ||||||||||||||||||||||||||||||||
| 213 | result ≔ { | ||||||||||||||||||||||||||||||||
| 214 | name ↦ w.name ?? f, | ||||||||||||||||||||||||||||||||
| 215 | file ↦ f, | ||||||||||||||||||||||||||||||||
| 216 | runs_per_month ↦ runs, | ||||||||||||||||||||||||||||||||
| 217 | minutes_per_run ↦ dur, | ||||||||||||||||||||||||||||||||
| 218 | minutes_per_month ↦ runs × dur, | ||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | invariant: result.minutes_per_month = result.runs_per_month × result.minutes_per_run | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | =cut | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | 11 | ▶ | sub estimate_workflow_cost($workflow, $filename) { | ||||||||||||||||||||||||||||||
|
Subroutine
estimate_workflow_cost: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 226 | 11 | ▶ | my $name = $workflow->{name} // $filename; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$workflow->{"name"} // $filename
MC/DC0%0/2
$workflow->{"name"} // $filename
$workflow->{"name"}
$filename
Truth table66%2/3
A // B
A= $workflow->{"name"}B= $filename
| |||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | # Estimate triggers per month | ||||||||||||||||||||||||||||||||
| 229 | 11 | my $runs_per_month = estimate_runs_per_month($workflow); | |||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | # Estimate duration per run | ||||||||||||||||||||||||||||||||
| 232 | 11 | my $minutes_per_run = estimate_duration($workflow); | |||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | # Calculate total | ||||||||||||||||||||||||||||||||
| 235 | 11 | my $minutes_per_month = $runs_per_month * $minutes_per_run; | |||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | return { | ||||||||||||||||||||||||||||||||
| 238 | 11 | name => $name, | |||||||||||||||||||||||||||||||
| 239 | file => $filename, | ||||||||||||||||||||||||||||||||
| 240 | runs_per_month => $runs_per_month, | ||||||||||||||||||||||||||||||||
| 241 | minutes_per_run => $minutes_per_run, | ||||||||||||||||||||||||||||||||
| 242 | minutes_per_month => $minutes_per_month, | ||||||||||||||||||||||||||||||||
| 243 | }; | ||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | =head2 estimate_savings($issues, $workflows) | ||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | Estimate potential CI-minute and cost savings from resolving a set of issues. | ||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | =head3 Purpose | ||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | For each issue in C<$issues>, compute how many CI minutes per month would be | ||||||||||||||||||||||||||||||||
| 253 | saved by fixing it. Optionally uses C<$workflows> to proportion savings | ||||||||||||||||||||||||||||||||
| 254 | against actual current usage. | ||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | =head3 Arguments | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | =over 4 | ||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | =item C<$issues> (ArrayRef[HashRef], required) | ||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | Array reference of issue hashes, each with at least C<type> and C<message>. | ||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | =item C<$workflows> (ArrayRef[Path::Tiny], optional, default C<[]>) | ||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||
| 266 | Workflow files used to compute current usage for percentage calculations. | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | =back | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | =head3 Returns | ||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | A hash reference: | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||||||
| 275 | minutes => Int, # total minutes saved per month | ||||||||||||||||||||||||||||||||
| 276 | percentage => Int, # 0–100; 0 when no current usage available | ||||||||||||||||||||||||||||||||
| 277 | cost => Str, # formatted as "NN.NN" (USD) | ||||||||||||||||||||||||||||||||
| 278 | details => ArrayRef[{ description => Str, minutes => Int, issue_type => Str }], | ||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | =head3 Side Effects | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | May read workflow files from disk when C<$workflows> is non-empty. | ||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||
| 285 | =head3 Usage Example | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | my $savings = estimate_savings(\@issues, \@workflow_paths); | ||||||||||||||||||||||||||||||||
| 288 | printf "Save %d min/month (\$%s)\n", | ||||||||||||||||||||||||||||||||
| 289 | $savings->{minutes}, $savings->{cost}; | ||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | =head4 Input | ||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||||||
| 296 | issues => { type => 'arrayref', required => 1 }, | ||||||||||||||||||||||||||||||||
| 297 | workflows => { type => 'arrayref', default => [] }, | ||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | =head4 Output | ||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | { | ||||||||||||||||||||||||||||||||
| 303 | type => 'hashref', | ||||||||||||||||||||||||||||||||
| 304 | keys => { | ||||||||||||||||||||||||||||||||
| 305 | minutes => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 306 | percentage => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 307 | cost => { type => 'scalar' }, | ||||||||||||||||||||||||||||||||
| 308 | details => { type => 'arrayref' }, | ||||||||||||||||||||||||||||||||
| 309 | }, | ||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | estimate_savings : seq Issue × seq Path → SavingsSummary | ||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | savings(i) ≔ | ||||||||||||||||||||||||||||||||
| 317 | i.type = performance ∧ i.message =~ /caching/ → 75 | ||||||||||||||||||||||||||||||||
| 318 | i.type = cost ∧ i.message =~ /concurrency/ → 50 | usage×0.15 | ||||||||||||||||||||||||||||||||
| 319 | i.type = cost ∧ i.message =~ /triggers/ → 100 | usage×0.25 | ||||||||||||||||||||||||||||||||
| 320 | otherwise → 0 | ||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | total ≔ ∑ { savings(i) ∣ i ∈ issues } | ||||||||||||||||||||||||||||||||
| 323 | result ≔ { | ||||||||||||||||||||||||||||||||
| 324 | minutes ↦ floor(total), | ||||||||||||||||||||||||||||||||
| 325 | percentage ↦ floor(total / usage × 100) | 30 (if total > 0, no usage), | ||||||||||||||||||||||||||||||||
| 326 | cost ↦ sprintf("%.2f", total × 0.008), | ||||||||||||||||||||||||||||||||
| 327 | details ↦ [ { description, minutes, issue_type } ∣ savings(i) > 0 ], | ||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | =cut | ||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||
| 332 | 22 | ▶ | sub estimate_savings($issues, $workflows = []) { | ||||||||||||||||||||||||||||||
|
Subroutine
estimate_savings: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 333 | 22 | my %savings = ( | |||||||||||||||||||||||||||||||
| 334 | minutes => 0, | ||||||||||||||||||||||||||||||||
| 335 | percentage => 0, | ||||||||||||||||||||||||||||||||
| 336 | cost => 0, | ||||||||||||||||||||||||||||||||
| 337 | details => [], | ||||||||||||||||||||||||||||||||
| 338 | ); | ||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | # Get current usage if workflows provided | ||||||||||||||||||||||||||||||||
| 341 | 22 | ▶ | my $current_usage = @$workflows ? estimate_current_usage($workflows) : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||
| 343 | 22 | for my $issue (@$issues) { | |||||||||||||||||||||||||||||||
| 344 | 27 | my $saving = 0; | |||||||||||||||||||||||||||||||
| 345 | 27 | my $description = ''; | |||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||
| 347 | 27 | ▶ | if ($issue->{type} eq 'performance') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 348 | 13 | ▶ | if ($issue->{message} =~ /caching/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 349 | # Caching typically saves 30-60 seconds per run | ||||||||||||||||||||||||||||||||
| 350 | # Estimate 100 runs/month affected | ||||||||||||||||||||||||||||||||
| 351 | 11 | $saving = 100 * 0.75; # 75 minutes | |||||||||||||||||||||||||||||||
| 352 | 11 | $description = 'Adding dependency caching'; | |||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | elsif ($issue->{type} eq 'cost') { | ||||||||||||||||||||||||||||||||
| 356 | 11 | ▶ | if ($issue->{message} =~ /concurrency/) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 357 | # Concurrency saves by canceling superseded runs | ||||||||||||||||||||||||||||||||
| 358 | # Estimate 10-20% of runs are canceled | ||||||||||||||||||||||||||||||||
| 359 | 6 | ▶ | if ($current_usage) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 360 | 2 | $saving = $current_usage->{total_minutes} * 0.15; | |||||||||||||||||||||||||||||||
| 361 | } else { | ||||||||||||||||||||||||||||||||
| 362 | 4 | $saving = 50; # Conservative estimate | |||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||
| 364 | 6 | $description = 'Adding concurrency controls'; | |||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||
| 366 | elsif ($issue->{message} =~ /triggers/) { | ||||||||||||||||||||||||||||||||
| 367 | # Trigger filters reduce unnecessary runs | ||||||||||||||||||||||||||||||||
| 368 | # Estimate 20-30% of runs avoided | ||||||||||||||||||||||||||||||||
| 369 | 4 | ▶ | if ($current_usage) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 370 | 2 | $saving = $current_usage->{total_minutes} * 0.25; | |||||||||||||||||||||||||||||||
| 371 | } else { | ||||||||||||||||||||||||||||||||
| 372 | 2 | $saving = 100; # Conservative estimate | |||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||
| 374 | 4 | $description = 'Optimizing workflow triggers'; | |||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | 27 | ▶ | if ($saving > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 379 | 21 | $savings{minutes} += $saving; | |||||||||||||||||||||||||||||||
| 380 | 21 | push @{$savings{details}}, { | |||||||||||||||||||||||||||||||
| 381 | description => $description, | ||||||||||||||||||||||||||||||||
| 382 | minutes => int($saving), | ||||||||||||||||||||||||||||||||
| 383 | issue_type => $issue->{type}, | ||||||||||||||||||||||||||||||||
| 384 | 21 | }; | |||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||
| 388 | # Calculate percentage and cost | ||||||||||||||||||||||||||||||||
| 389 | 22 | ▶ | if ($current_usage && $current_usage->{total_minutes} > 0) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$current_usage and $current_usage->{"total_minutes"} > 0
MC/DC100%2/2
$current_usage and $current_usage->{"total_minutes"} > 0
$current_usage
$current_usage->{"total_minutes"} > 0
Truth table100%3/3
A and B
A= $current_usageB= $current_usage->{"total_minutes"} > 0
| |||||||||||||||||||||||||||||||||
| 390 | 7 | $savings{percentage} = int(($savings{minutes} / $current_usage->{total_minutes}) * 100); | |||||||||||||||||||||||||||||||
| 391 | } elsif ($savings{minutes} > 0) { | ||||||||||||||||||||||||||||||||
| 392 | 10 | $savings{percentage} = 30; # Estimate 30% savings | |||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | 22 | $savings{cost} = sprintf('%.2f', $savings{minutes} * 0.008); | |||||||||||||||||||||||||||||||
| 396 | 22 | $savings{minutes} = int($savings{minutes}); | |||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||
| 398 | 22 | return \%savings; | |||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||
| 401 | 18 | ▶ | sub estimate_runs_per_month($workflow) { | ||||||||||||||||||||||||||||||
|
Subroutine
estimate_runs_per_month: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 402 | 18 | ▶ | my $on = $workflow->{on} or return 50; # Default estimate | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||
| 404 | 15 | my $runs = 0; | |||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | # Parse different trigger formats | ||||||||||||||||||||||||||||||||
| 407 | 15 | ▶ | if (ref $on eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 408 | 2 | for my $trigger (@$on) { | |||||||||||||||||||||||||||||||
| 409 | 2 | $runs += estimate_trigger_frequency($trigger); | |||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||
| 412 | elsif (ref $on eq 'HASH') { | ||||||||||||||||||||||||||||||||
| 413 | 8 | for my $trigger (keys %$on) { | |||||||||||||||||||||||||||||||
| 414 | 10 | $runs += estimate_trigger_frequency($trigger, $on->{$trigger}); | |||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||
| 416 | } else { | ||||||||||||||||||||||||||||||||
| 417 | 5 | $runs += estimate_trigger_frequency($on); | |||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||
| 420 | 15 | ▶ | return $runs || 50; # Minimum estimate | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$runs || 50
MC/DC100%1/1
$runs || 50
$runs
Truth table100%2/2
A
A= $runs
| |||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | 26 | ▶ | sub estimate_trigger_frequency($trigger, $config = undef) { | ||||||||||||||||||||||||||||||
|
Subroutine
estimate_trigger_frequency: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 424 | # Estimates based on typical project activity | ||||||||||||||||||||||||||||||||
| 425 | 26 | my %frequencies = ( | |||||||||||||||||||||||||||||||
| 426 | push => 100, # ~5 pushes/day for active projects | ||||||||||||||||||||||||||||||||
| 427 | pull_request => 60, # ~2-3 PRs/day | ||||||||||||||||||||||||||||||||
| 428 | schedule => 30, # Depends on cron, assume daily | ||||||||||||||||||||||||||||||||
| 429 | workflow_dispatch => 10, # Manual runs | ||||||||||||||||||||||||||||||||
| 430 | release => 4, # ~1 per week | ||||||||||||||||||||||||||||||||
| 431 | issues => 20, # Issue activity | ||||||||||||||||||||||||||||||||
| 432 | ); | ||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | 26 | ▶ | my $base = $frequencies{$trigger} // 20; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$frequencies{$trigger} // 20
MC/DC100%1/1
$frequencies{$trigger} // 20
$frequencies{$trigger}
Truth table100%2/2
A
A= $frequencies{$trigger}
| |||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||
| 436 | # Adjust based on configuration | ||||||||||||||||||||||||||||||||
| 437 | 26 | ▶ | if ($config && ref $config eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$config and ref $config eq "HASH"
MC/DC50%1/2
$config and ref $config eq "HASH"
$config
ref $config eq "HASH"
Truth table66%2/3
A and B
A= $configB= ref $config eq "HASH"
| |||||||||||||||||||||||||||||||||
| 438 | # If it has branches filter, likely fewer runs | ||||||||||||||||||||||||||||||||
| 439 | 15 | ▶ | if ($config->{branches}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 440 | 8 | $base *= 0.6; # 40% reduction | |||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||
| 443 | # If it has paths filter, significantly fewer runs | ||||||||||||||||||||||||||||||||
| 444 | 15 | ▶ | if ($config->{paths}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 445 | 3 | $base *= 0.3; # 70% reduction | |||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||
| 449 | 26 | return int($base); | |||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||
| 452 | 15 | ▶ | sub estimate_duration($workflow) { | ||||||||||||||||||||||||||||||
|
Subroutine
estimate_duration: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 453 | 15 | ▶ | my $jobs = $workflow->{jobs} or return 5; # Default 5 minutes | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||
| 455 | 14 | my $total_duration = 0; | |||||||||||||||||||||||||||||||
| 456 | 14 | my $max_parallel_duration = 0; | |||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||
| 458 | # Check if jobs run in parallel or sequence | ||||||||||||||||||||||||||||||||
| 459 | 14 | my $has_dependencies = 0; | |||||||||||||||||||||||||||||||
| 460 | 14 | for my $job (values %$jobs) { | |||||||||||||||||||||||||||||||
| 461 | 18 | ▶ | $has_dependencies = 1 if $job->{needs}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | 14 | for my $job (values %$jobs) { | |||||||||||||||||||||||||||||||
| 465 | 18 | my $duration = estimate_job_duration($job); | |||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||
| 467 | 18 | ▶ | if ($has_dependencies) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 468 | # Sequential - add durations | ||||||||||||||||||||||||||||||||
| 469 | 4 | $total_duration += $duration; | |||||||||||||||||||||||||||||||
| 470 | } else { | ||||||||||||||||||||||||||||||||
| 471 | # Parallel - track maximum | ||||||||||||||||||||||||||||||||
| 472 | 14 | ▶ | $max_parallel_duration = $duration if $duration > $max_parallel_duration; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||
| 476 | 14 | ▶ | my $estimated = $has_dependencies ? $total_duration : $max_parallel_duration; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||
| 478 | # Factor in matrix multiplier | ||||||||||||||||||||||||||||||||
| 479 | 14 | my $matrix_factor = estimate_matrix_factor($workflow); | |||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||
| 481 | 14 | ▶ | return int($estimated * $matrix_factor) || 5; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
int $estimated * $matrix_factor || 5
MC/DC100%1/1
int $estimated * $matrix_factor || 5
int $estimated * $matrix_factor
Truth table100%2/2
A
A= int $estimated * $matrix_factor
| |||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||
| 484 | 30 | ▶ | sub estimate_job_duration($job) { | ||||||||||||||||||||||||||||||
|
Subroutine
estimate_job_duration: called CC=13 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 485 | 30 | ▶ | my $steps = $job->{steps} or return 3; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||
| 487 | 28 | my $duration = 0; | |||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||
| 489 | 28 | for my $step (@$steps) { | |||||||||||||||||||||||||||||||
| 490 | # Estimate based on step type | ||||||||||||||||||||||||||||||||
| 491 | 50 | ▶ | if ($step->{uses}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 492 | 16 | my $uses = $step->{uses}; | |||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||
| 494 | # Common actions and their typical durations | ||||||||||||||||||||||||||||||||
| 495 | 16 | ▶ | if ($uses =~ /checkout/) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 496 | 11 | $duration += 0.5; | |||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||
| 498 | elsif ($uses =~ /setup-(?:node|python|go|ruby)/) { | ||||||||||||||||||||||||||||||||
| 499 | 3 | $duration += 1; | |||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||
| 501 | elsif ($uses =~ /cache/) { | ||||||||||||||||||||||||||||||||
| 502 | # Cache hit: ~10s, miss: ~30s | ||||||||||||||||||||||||||||||||
| 503 | 1 | $duration += 0.3; | |||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||
| 506 | elsif ($step->{run}) { | ||||||||||||||||||||||||||||||||
| 507 | 31 | my $run = $step->{run}; | |||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||
| 509 | # Estimate based on command | ||||||||||||||||||||||||||||||||
| 510 | 31 | ▶ | if ($run =~ /npm (?:install|ci)/) { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 511 | 12 | $duration += 2; # npm install takes time | |||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||
| 513 | elsif ($run =~ /pip install/) { | ||||||||||||||||||||||||||||||||
| 514 | 1 | $duration += 1.5; | |||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||
| 516 | elsif ($run =~ /cargo build/) { | ||||||||||||||||||||||||||||||||
| 517 | 6 | $duration += 5; # Rust builds are slow | |||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||
| 519 | elsif ($run =~ /(?:npm|pytest|cargo|go) test/) { | ||||||||||||||||||||||||||||||||
| 520 | 9 | $duration += 2; # Test suites | |||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||
| 522 | else { | ||||||||||||||||||||||||||||||||
| 523 | 3 | $duration += 0.5; # Generic command | |||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||
| 528 | 28 | ▶ | return $duration || 3; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$duration || 3
MC/DC100%1/1
$duration || 3
$duration
Truth table100%2/2
A
A= $duration
| |||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||
| 531 | 20 | ▶ | sub estimate_matrix_factor($workflow) { | ||||||||||||||||||||||||||||||
|
Subroutine
estimate_matrix_factor: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 532 | 20 | ▶ | my $jobs = $workflow->{jobs} or return 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||
| 534 | 20 | my $max_matrix_size = 1; | |||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||
| 536 | 20 | for my $job (values %$jobs) { | |||||||||||||||||||||||||||||||
| 537 | 25 | ▶ | next unless $job->{strategy}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 538 | 8 | ▶ | next unless $job->{strategy}->{matrix}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||
| 540 | 8 | my $matrix = $job->{strategy}->{matrix}; | |||||||||||||||||||||||||||||||
| 541 | 8 | my $size = 1; | |||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||
| 543 | # Calculate matrix size | ||||||||||||||||||||||||||||||||
| 544 | 8 | for my $key (keys %$matrix) { | |||||||||||||||||||||||||||||||
| 545 | 13 | ▶ | next if $key eq 'include' || $key eq 'exclude'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "include" or $key eq "exclude"
MC/DC100%2/2
$key eq "include" or $key eq "exclude"
$key eq "include"
$key eq "exclude"
Truth table100%3/3
A or B
A= $key eq "include"B= $key eq "exclude"
| |||||||||||||||||||||||||||||||||
| 546 | 10 | my $values = $matrix->{$key}; | |||||||||||||||||||||||||||||||
| 547 | 10 | ▶ | if (ref $values eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 548 | 9 | $size *= scalar @$values; | |||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||
| 552 | 8 | ▶ | $max_matrix_size = $size if $size > $max_matrix_size; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||
| 555 | 20 | return $max_matrix_size; | |||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||
| 558 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||
| 560 | Nigel Horne E<lt>njh@nigelhorne.comE<gt> | ||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||
| 562 | L<https://github.com/nigelhorne> | ||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||
| 564 | =head1 LICENSE | ||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||
| 566 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 567 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||
| 569 | =cut | ||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||
| 571 | 8 | 1; | |||||||||||||||||||||||||||||||