| 1 | package App::GHGen::PerlCustomizer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 67 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 67 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 67 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 67 | ▶ | use autodie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 67 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 67 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 67 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 67 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 13 | detect_perl_requirements | ||||||||||||||||||||||||||||
| 14 | generate_custom_perl_workflow | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 67 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 67 | Readonly my $DEFAULT_TIMEOUT_MINUTES => 60; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 NAME | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | App::GHGen::PerlCustomizer - Customize Perl workflows based on project requirements | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | use App::GHGen::PerlCustomizer qw(detect_perl_requirements); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | my $requirements = detect_perl_requirements(); | ||||||||||||||||||||||||||||
| 32 | # Returns: { min_version => '5.036', has_cpanfile => 1, ... } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head2 detect_perl_requirements() | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Detect Perl version requirements and dependency-file presence in the current directory. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head3 Purpose | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Inspect the current working directory for common Perl distribution files | ||||||||||||||||||||||||||||
| 43 | (C<cpanfile>, C<Makefile.PL>, C<dist.ini>, C<Build.PL>) and extract the | ||||||||||||||||||||||||||||
| 44 | minimum Perl version declared in any of them. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head3 Arguments | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | None. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head3 Returns | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | A hash reference with the following keys, all of which are always present: | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | min_version => Str | undef, # e.g. '5.036'; undef when undetected | ||||||||||||||||||||||||||||
| 56 | has_cpanfile => Bool, | ||||||||||||||||||||||||||||
| 57 | has_makefile_pl => Bool, | ||||||||||||||||||||||||||||
| 58 | has_dist_ini => Bool, | ||||||||||||||||||||||||||||
| 59 | has_build_pl => Bool, | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head3 Side Effects | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Reads files from the current working directory. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head3 Usage Example | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | use App::GHGen::PerlCustomizer qw(detect_perl_requirements); | ||||||||||||||||||||||||||||
| 69 | my $reqs = detect_perl_requirements(); | ||||||||||||||||||||||||||||
| 70 | say $reqs->{min_version} // 'not specified'; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head4 Input | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # No parameters. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head4 Output | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | type => 'hashref', | ||||||||||||||||||||||||||||
| 82 | keys => { | ||||||||||||||||||||||||||||
| 83 | min_version => { type => 'scalar', optional => 1 }, | ||||||||||||||||||||||||||||
| 84 | has_cpanfile => { type => 'scalar' }, | ||||||||||||||||||||||||||||
| 85 | has_makefile_pl => { type => 'scalar' }, | ||||||||||||||||||||||||||||
| 86 | has_dist_ini => { type => 'scalar' }, | ||||||||||||||||||||||||||||
| 87 | has_build_pl => { type => 'scalar' }, | ||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | detect_perl_requirements : → Requirements | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | Requirements ≔ { | ||||||||||||||||||||||||||||
| 96 | min_version: ℤ* ∪ { ⊥ }, | ||||||||||||||||||||||||||||
| 97 | has_cpanfile: 𝔹, | ||||||||||||||||||||||||||||
| 98 | has_makefile_pl: 𝔹, | ||||||||||||||||||||||||||||
| 99 | has_dist_ini: 𝔹, | ||||||||||||||||||||||||||||
| 100 | has_build_pl: 𝔹, | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | min_version ≔ | ||||||||||||||||||||||||||||
| 104 | cpanfile exists ∧ version parseable from cpanfile → version | ||||||||||||||||||||||||||||
| 105 | Makefile.PL exists ∧ MIN_PERL_VERSION parseable → version | ||||||||||||||||||||||||||||
| 106 | otherwise → ⊥ | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 13 | ▶ | sub detect_perl_requirements() { | ||||||||||||||||||||||||||
|
Subroutine
detect_perl_requirements: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 13 | my %reqs = ( | |||||||||||||||||||||||||||
| 112 | min_version => undef, | ||||||||||||||||||||||||||||
| 113 | has_cpanfile => 0, | ||||||||||||||||||||||||||||
| 114 | has_makefile_pl => 0, | ||||||||||||||||||||||||||||
| 115 | has_dist_ini => 0, | ||||||||||||||||||||||||||||
| 116 | has_build_pl => 0, | ||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # Check for dependency files | ||||||||||||||||||||||||||||
| 120 | 13 | $reqs{has_cpanfile} = path('cpanfile')->exists; | |||||||||||||||||||||||||||
| 121 | 13 | $reqs{has_makefile_pl} = path('Makefile.PL')->exists; | |||||||||||||||||||||||||||
| 122 | 13 | $reqs{has_dist_ini} = path('dist.ini')->exists; | |||||||||||||||||||||||||||
| 123 | 13 | $reqs{has_build_pl} = path('Build.PL')->exists; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # Try to detect minimum Perl version | ||||||||||||||||||||||||||||
| 126 | 13 | ▶ | if ($reqs{has_cpanfile}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 9 | my $content = path('cpanfile')->slurp_utf8; | |||||||||||||||||||||||||||
| 128 | 9 | ▶ | if ($content =~ /requires\s+['"]perl['"],?\s+['"]([0-9.]+)['"]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 9 | $reqs{min_version} = $1; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 13 | ▶ | if (!$reqs{min_version} && $reqs{has_makefile_pl}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $reqs{"min_version"} and $reqs{"has_makefile_pl"}
MC/DC100%2/2
not $reqs{"min_version"} and $reqs{"has_makefile_pl"}
not $reqs{"min_version"}
$reqs{"has_makefile_pl"}
Truth table100%3/3
not(A) and B
A= not $reqs{"min_version"}B= $reqs{"has_makefile_pl"}
| |||||||||||||||||||||||||||||
| 134 | 1 | my $content = path('Makefile.PL')->slurp_utf8; | |||||||||||||||||||||||||||
| 135 | 1 | ▶ | if ($content =~ /MIN_PERL_VERSION\s*=>\s*['"]([0-9.]+)['"]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | $reqs{min_version} = $1; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 13 | return \%reqs; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head2 generate_custom_perl_workflow($options) | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | Generate a customized Perl CI workflow and return it as a YAML string. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | B<Options:> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =over 4 | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item C<perl_versions> (array ref) | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Explicit list of Perl versions to include in the test matrix, e.g. | ||||||||||||||||||||||||||||
| 154 | C<['5.40', '5.38', '5.36']>. Takes precedence over C<min_perl_version> | ||||||||||||||||||||||||||||
| 155 | and C<max_perl_version> when supplied. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =item C<min_perl_version> (string, default C<'5.36'>) | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | Lowest Perl version to include in the matrix when C<perl_versions> is not | ||||||||||||||||||||||||||||
| 160 | given. Accepts both C<'5.036'> and C<'5.36'> notation. | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =item C<max_perl_version> (string, default C<'5.42'>) | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Highest Perl version to include in the default matrix when C<perl_versions> | ||||||||||||||||||||||||||||
| 165 | is not given. The built-in version table currently spans C<5.22> through | ||||||||||||||||||||||||||||
| 166 | C<5.44>; the default produces the matrix C<5.36, 5.38, 5.40, 5.42>. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | To test against B<Perl 5.44> (opt-in, not tested by default), pass | ||||||||||||||||||||||||||||
| 169 | C<< max_perl_version => '5.44' >> or set C<perl_versions> explicitly: | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | generate_custom_perl_workflow({ max_perl_version => '5.44' }); | ||||||||||||||||||||||||||||
| 172 | # matrix: 5.36, 5.38, 5.40, 5.42, 5.44 | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | generate_custom_perl_workflow({ perl_versions => ['5.42', '5.44'] }); | ||||||||||||||||||||||||||||
| 175 | # matrix: 5.42, 5.44 | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =item C<os> (array ref) | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | Operating systems for the build matrix. | ||||||||||||||||||||||||||||
| 180 | Default: C<['ubuntu-latest', 'macos-latest', 'windows-latest']>. | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =item C<timeout> (integer, default C<60>) | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | Value written to C<timeout-minutes> on every matrix job. | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =item C<install_db_file> (boolean, default C<1>) | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | When true, Linux jobs run C<apt install libdb-dev libperl-dev> before the | ||||||||||||||||||||||||||||
| 189 | CPAN install, because many CPAN modules need C<DB_File>. Set it to C<0> for | ||||||||||||||||||||||||||||
| 190 | projects that do not, to save the apt round trip. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =item C<cpanm_verbose> (boolean, default C<1>) | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | When true, C<cpanm> runs with C<--verbose>. The extra output stops GitHub | ||||||||||||||||||||||||||||
| 195 | Actions cancelling a job for "no activity" while many prerequisites build. | ||||||||||||||||||||||||||||
| 196 | Set it to C<0> for a quieter log on small dependency sets. | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =item C<enable_linter> (boolean, default C<1>) | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | When true, inserts a B<"Lint and syntax check"> step after all dependency | ||||||||||||||||||||||||||||
| 201 | installation steps and before the test run. The step runs on B<every> | ||||||||||||||||||||||||||||
| 202 | matrix cell (all OS and Perl version combinations) so that compile-time | ||||||||||||||||||||||||||||
| 203 | errors are caught across the full version range being tested. | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | The step uses C<shell: perl {0}>, which works identically on Linux, macOS, | ||||||||||||||||||||||||||||
| 206 | and Windows without any OS-specific branching. It searches C<lib/> and | ||||||||||||||||||||||||||||
| 207 | C<bin/> (falling back to C<.> when neither exists), loads each C<.pm> file | ||||||||||||||||||||||||||||
| 208 | via C<do $file> with a stub C<@INC> handler that silently satisfies any | ||||||||||||||||||||||||||||
| 209 | missing C<use> statements, and exits non-zero if any file fails. Using | ||||||||||||||||||||||||||||
| 210 | C<do $file> avoids spawning C<perl -c> subprocesses (which have | ||||||||||||||||||||||||||||
| 211 | Windows command-line quoting issues) and avoids false failures caused by | ||||||||||||||||||||||||||||
| 212 | missing CPAN dependencies. B<No additional CPAN modules are required.> | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =item C<enable_linter_unused> (boolean, default C<1>) | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | When true, appends an unused-variable check to the B<end of the lint step> | ||||||||||||||||||||||||||||
| 217 | (i.e. it runs before the test run, not after). The check installs | ||||||||||||||||||||||||||||
| 218 | L<warnings::unused> from CPAN, then runs | ||||||||||||||||||||||||||||
| 219 | C<PERL5OPT=-Mwarnings::unused prove -lr t/> so that variable lifetimes are | ||||||||||||||||||||||||||||
| 220 | exercised at runtime (C<perl -c> is compile-only and cannot detect unused | ||||||||||||||||||||||||||||
| 221 | variables). It is gated on C<RUNNER_OS == Linux> and marked | ||||||||||||||||||||||||||||
| 222 | C<continue-on-error: true> because unused-variable warnings can be | ||||||||||||||||||||||||||||
| 223 | legitimately noisy on some codebases. | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =item C<enable_critic> (boolean, default C<1>) | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | When true, adds a Perl::Critic step on the latest matrix Perl version and | ||||||||||||||||||||||||||||
| 228 | C<ubuntu-latest>. | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | =item C<enable_coverage> (boolean, default C<1>) | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | When true, adds a Devel::Cover test-coverage step on the latest matrix Perl | ||||||||||||||||||||||||||||
| 233 | version and C<ubuntu-latest>. | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =item C<enable_perlimports> (boolean, default C<1>) | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | When true, adds a B<"Check imports with perlimports"> step on the latest matrix | ||||||||||||||||||||||||||||
| 238 | Perl version and C<ubuntu-latest>. The step installs L<App::perlimports> from | ||||||||||||||||||||||||||||
| 239 | CPAN and runs C<perlimports --lint> across all C<.pm> files under C<lib/>. It | ||||||||||||||||||||||||||||
| 240 | is marked C<continue-on-error: true> because import hygiene warnings are | ||||||||||||||||||||||||||||
| 241 | advisory; they should not block a CI run in established codebases. | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | =back | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | B<Generated step order:> | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | =over 4 | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | =item 1. C<actions/checkout> | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =item 2. Setup Perl via C<shogo82148/actions-setup-perl> | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =item 3. Cache CPAN modules via C<actions/cache> | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | =item 4. Install cpanm and C<local::lib> | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | =item 5. Install project dependencies | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =item 6. B<Lint and syntax check> - all matrix cells (when C<enable_linter> is true); the unused-variable check via C<PERL5OPT=-Mwarnings::unused> is embedded at the end of this step when C<enable_linter_unused> is true | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =item 7. Run tests | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | =item 8. Run Perl::Critic - latest Perl + Ubuntu only (when C<enable_critic> is true) | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =item 9. B<Check imports with perlimports> - latest Perl + Ubuntu only (when C<enable_perlimports> is true) | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =item 10. Test coverage - latest Perl + Ubuntu only (when C<enable_coverage> is true) | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | =item 11. Show cpanm build log on failure | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | =back | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | =head4 Input | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | { | ||||||||||||||||||||||||||||
| 278 | opts => { | ||||||||||||||||||||||||||||
| 279 | type => 'hashref', | ||||||||||||||||||||||||||||
| 280 | default => {}, | ||||||||||||||||||||||||||||
| 281 | keys => { | ||||||||||||||||||||||||||||
| 282 | perl_versions => { type => 'arrayref', optional => 1 }, | ||||||||||||||||||||||||||||
| 283 | min_perl_version => { type => 'scalar', default => '5.36' }, | ||||||||||||||||||||||||||||
| 284 | max_perl_version => { type => 'scalar', default => '5.42' }, | ||||||||||||||||||||||||||||
| 285 | os => { type => 'arrayref', optional => 1 }, | ||||||||||||||||||||||||||||
| 286 | timeout => { type => 'scalar', default => $DEFAULT_TIMEOUT_MINUTES }, | ||||||||||||||||||||||||||||
| 287 | install_db_file => { type => 'scalar', default => 1 }, | ||||||||||||||||||||||||||||
| 288 | cpanm_verbose => { type => 'scalar', default => 1 }, | ||||||||||||||||||||||||||||
| 289 | enable_linter => { type => 'scalar', default => 1 }, | ||||||||||||||||||||||||||||
| 290 | enable_linter_unused => { type => 'scalar', default => 1 }, | ||||||||||||||||||||||||||||
| 291 | enable_critic => { type => 'scalar', default => 1 }, | ||||||||||||||||||||||||||||
| 292 | enable_coverage => { type => 'scalar', default => 1 }, | ||||||||||||||||||||||||||||
| 293 | enable_perlimports => { type => 'scalar', default => 1 }, | ||||||||||||||||||||||||||||
| 294 | }, | ||||||||||||||||||||||||||||
| 295 | }, | ||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =head4 Output | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | { type => 'scalar' } # multi-line YAML string starting with '---' | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | generate_custom_perl_workflow : Opts → YAML | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | versions ≔ opts.perl_versions ?? range(min, max) | ||||||||||||||||||||||||||||
| 307 | latest ≔ versions[|versions|−1] | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | yaml contains "Install DB_File" step ↔ opts.install_db_file = 1 | ||||||||||||||||||||||||||||
| 310 | yaml contains "cpanm ... --verbose" ↔ opts.cpanm_verbose = 1 | ||||||||||||||||||||||||||||
| 311 | yaml contains "Lint and syntax check" step ↔ opts.enable_linter = 1 | ||||||||||||||||||||||||||||
| 312 | yaml contains "PERL5OPT=-Mwarnings::unused" ↔ opts.enable_linter_unused = 1 | ||||||||||||||||||||||||||||
| 313 | yaml contains "Run Perl::Critic" ↔ opts.enable_critic = 1 | ||||||||||||||||||||||||||||
| 314 | yaml contains "Test coverage" ↔ opts.enable_coverage = 1 | ||||||||||||||||||||||||||||
| 315 | yaml contains "Check imports with perlimports" ↔ opts.enable_perlimports = 1 | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | step ordering invariant: | ||||||||||||||||||||||||||||
| 318 | pos(lint) < pos(unused) < pos(tests) < pos(critic) < pos(perlimports) < pos(coverage) | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | =cut | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 60 | ▶ | sub generate_custom_perl_workflow($opts = {}) { | ||||||||||||||||||||||||||
|
Subroutine
generate_custom_perl_workflow: called CC=26 SCAR=32.6
Pod
documented
| |||||||||||||||||||||||||||||
| 323 | 60 | ▶ | my $min_version = $opts->{min_perl_version} // '5.36'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"min_perl_version"} // "5.36"
MC/DC100%1/1
$opts->{"min_perl_version"} // "5.36"
$opts->{"min_perl_version"}
Truth table100%2/2
A
A= $opts->{"min_perl_version"}
| |||||||||||||||||||||||||||||
| 324 | 60 | ▶ | my $max_version = $opts->{max_perl_version} // '5.42'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"max_perl_version"} // "5.42"
MC/DC100%1/1
$opts->{"max_perl_version"} // "5.42"
$opts->{"max_perl_version"}
Truth table100%2/2
A
A= $opts->{"max_perl_version"}
| |||||||||||||||||||||||||||||
| 325 | 60 | ▶ | my $timeout = $opts->{timeout} // $DEFAULT_TIMEOUT_MINUTES; | ||||||||||||||||||||||||||
|
Condition66%2/3
$opts->{"timeout"} // $DEFAULT_TIMEOUT_MINUTES
MC/DC50%1/2
$opts->{"timeout"} // $DEFAULT_TIMEOUT_MINUTES
$opts->{"timeout"}
$DEFAULT_TIMEOUT_MINUTES
Truth table66%2/3
A // B
A= $opts->{"timeout"}B= $DEFAULT_TIMEOUT_MINUTES
| |||||||||||||||||||||||||||||
| 326 | 60 | ▶ | my $install_db_file = $opts->{install_db_file} // 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"install_db_file"} // 1
MC/DC100%1/1
$opts->{"install_db_file"} // 1
$opts->{"install_db_file"}
Truth table100%2/2
A
A= $opts->{"install_db_file"}
| |||||||||||||||||||||||||||||
| 327 | 60 | ▶ | my $cpanm_verbose = $opts->{cpanm_verbose} // 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"cpanm_verbose"} // 1
MC/DC100%1/1
$opts->{"cpanm_verbose"} // 1
$opts->{"cpanm_verbose"}
Truth table100%2/2
A
A= $opts->{"cpanm_verbose"}
| |||||||||||||||||||||||||||||
| 328 | 60 | ▶ | my @os = @{$opts->{os} // ['ubuntu-latest', 'macos-latest', 'windows-latest']}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"os"} // ["ubuntu-latest", "macos-latest", "windows-latest"]
MC/DC100%1/1
$opts->{"os"} // ["ubuntu-latest", "macos-latest", "windows-latest"]
$opts->{"os"}
Truth table100%2/2
A
A= $opts->{"os"}
| |||||||||||||||||||||||||||||
| 329 | 60 | ▶ | my $enable_linter = $opts->{enable_linter} // 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"enable_linter"} // 1
MC/DC100%1/1
$opts->{"enable_linter"} // 1
$opts->{"enable_linter"}
Truth table100%2/2
A
A= $opts->{"enable_linter"}
| |||||||||||||||||||||||||||||
| 330 | 60 | ▶ | my $enable_linter_unused = $opts->{enable_linter_unused} // 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"enable_linter_unused"} // 1
MC/DC100%1/1
$opts->{"enable_linter_unused"} // 1
$opts->{"enable_linter_unused"}
Truth table100%2/2
A
A= $opts->{"enable_linter_unused"}
| |||||||||||||||||||||||||||||
| 331 | 60 | ▶ | my $enable_critic = $opts->{enable_critic} // 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"enable_critic"} // 1
MC/DC100%1/1
$opts->{"enable_critic"} // 1
$opts->{"enable_critic"}
Truth table100%2/2
A
A= $opts->{"enable_critic"}
| |||||||||||||||||||||||||||||
| 332 | 60 | ▶ | my $enable_coverage = $opts->{enable_coverage} // 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"enable_coverage"} // 1
MC/DC100%1/1
$opts->{"enable_coverage"} // 1
$opts->{"enable_coverage"}
Truth table100%2/2
A
A= $opts->{"enable_coverage"}
| |||||||||||||||||||||||||||||
| 333 | 60 | ▶ | my $enable_perlimports = $opts->{enable_perlimports} // 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{"enable_perlimports"} // 1
MC/DC100%1/1
$opts->{"enable_perlimports"} // 1
$opts->{"enable_perlimports"}
Truth table100%2/2
A
A= $opts->{"enable_perlimports"}
| |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | # Generate Perl version list - use explicit list if provided, otherwise min/max | ||||||||||||||||||||||||||||
| 336 | 60 | my @perl_versions; | |||||||||||||||||||||||||||
| 337 | 60 | ▶ | if ($opts->{perl_versions} && @{$opts->{perl_versions}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opts->{"perl_versions"} and @{$opts->{"perl_versions"};}
MC/DC50%1/2
$opts->{"perl_versions"} and @{$opts->{"perl_versions"};}
$opts->{"perl_versions"}
@{$opts->{"perl_versions"};}
Truth table66%2/3
A and B
A= $opts->{"perl_versions"}B= @{$opts->{"perl_versions"};}
| |||||||||||||||||||||||||||||
| 338 | 6 | @perl_versions = @{$opts->{perl_versions}}; | |||||||||||||||||||||||||||
| 339 | } else { | ||||||||||||||||||||||||||||
| 340 | 54 | @perl_versions = _get_perl_versions($min_version, $max_version); | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 60 | my $yaml = "---\n"; | |||||||||||||||||||||||||||
| 344 | 60 | $yaml .= '# Created by ' . __PACKAGE__ . "\n"; | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 60 | $yaml .= "name: Perl CI\n\n"; | |||||||||||||||||||||||||||
| 347 | 60 | $yaml .= "\"on\":\n"; | |||||||||||||||||||||||||||
| 348 | 60 | $yaml .= " push:\n"; | |||||||||||||||||||||||||||
| 349 | 60 | $yaml .= " branches:\n"; | |||||||||||||||||||||||||||
| 350 | 60 | $yaml .= " - main\n"; | |||||||||||||||||||||||||||
| 351 | 60 | $yaml .= " - master\n"; | |||||||||||||||||||||||||||
| 352 | 60 | $yaml .= " pull_request:\n"; | |||||||||||||||||||||||||||
| 353 | 60 | $yaml .= " branches:\n"; | |||||||||||||||||||||||||||
| 354 | 60 | $yaml .= " - main\n"; | |||||||||||||||||||||||||||
| 355 | 60 | $yaml .= " - master\n\n"; | |||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 60 | $yaml .= "concurrency:\n"; | |||||||||||||||||||||||||||
| 358 | 60 | $yaml .= " group: \${{ github.workflow }}-\${{ github.ref }}\n"; | |||||||||||||||||||||||||||
| 359 | 60 | $yaml .= " cancel-in-progress: true\n\n"; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 60 | $yaml .= "permissions:\n"; | |||||||||||||||||||||||||||
| 362 | 60 | $yaml .= " contents: read\n\n"; | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 60 | $yaml .= "jobs:\n"; | |||||||||||||||||||||||||||
| 365 | 60 | $yaml .= " test:\n"; | |||||||||||||||||||||||||||
| 366 | 60 | $yaml .= " runs-on: \${{ matrix.os }}\n"; | |||||||||||||||||||||||||||
| 367 | 60 | $yaml .= " timeout-minutes: $timeout\n"; | |||||||||||||||||||||||||||
| 368 | 60 | $yaml .= " strategy:\n"; | |||||||||||||||||||||||||||
| 369 | 60 | $yaml .= " fail-fast: false\n"; | |||||||||||||||||||||||||||
| 370 | 60 | $yaml .= " matrix:\n"; | |||||||||||||||||||||||||||
| 371 | 60 | $yaml .= " os:\n"; | |||||||||||||||||||||||||||
| 372 | 60 | for my $os (@os) { | |||||||||||||||||||||||||||
| 373 | 164 | $yaml .= " - $os\n"; | |||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | 60 | $yaml .= " perl:\n"; | |||||||||||||||||||||||||||
| 376 | 60 | for my $version (@perl_versions) { | |||||||||||||||||||||||||||
| 377 | 221 | $yaml .= " - \"$version\"\n"; | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | # shogo82148/build-perl perl-5.40.4-thr-win32-x64.zip ships a perl.exe and a | ||||||||||||||||||||||||||||
| 380 | # libperl540.a from two different builds. Any XS module compiled against that | ||||||||||||||||||||||||||||
| 381 | # libperl540.a (key 0x12c00080) mismatches the running perl.exe (needs | ||||||||||||||||||||||||||||
| 382 | # 0x12d00080). Even Win32::Process (a core Windows XS module bundled in the | ||||||||||||||||||||||||||||
| 383 | # zip) fails to load, so no XS-using test can pass on this combination. | ||||||||||||||||||||||||||||
| 384 | # Exclude until the upstream distribution is fixed. | ||||||||||||||||||||||||||||
| 385 | 60 | ▶ | if ((grep { $_ eq '5.40' } @perl_versions) && (grep { $_ eq 'windows-latest' } @os)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
grep {$_ eq "5.40";} @perl_versions and grep {$_ eq "windows-latest";} @os
MC/DC100%2/2
grep {$_ eq "5.40";} @perl_versions and grep {$_ eq "windows-latest";} @os
grep {$_ eq "5.40";} @perl_versions
grep {$_ eq "windows-latest";} @os
Truth table100%3/3
A and B
A= grep {$_ eq "5.40";} @perl_versionsB= grep {$_ eq "windows-latest";} @os
| |||||||||||||||||||||||||||||
| 386 | 48 | $yaml .= " exclude:\n"; | |||||||||||||||||||||||||||
| 387 | 48 | $yaml .= " - os: windows-latest\n"; | |||||||||||||||||||||||||||
| 388 | 48 | $yaml .= " perl: \"5.40\"\n"; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | 60 | $yaml .= " name: Perl \${{ matrix.perl }} on \${{ matrix.os }}\n"; | |||||||||||||||||||||||||||
| 391 | 60 | $yaml .= " env:\n"; | |||||||||||||||||||||||||||
| 392 | 60 | $yaml .= " AUTOMATED_TESTING: 1\n"; | |||||||||||||||||||||||||||
| 393 | 60 | $yaml .= " NO_NETWORK_TESTING: 1\n"; | |||||||||||||||||||||||||||
| 394 | 60 | $yaml .= " NONINTERACTIVE_TESTING: 1\n"; | |||||||||||||||||||||||||||
| 395 | 60 | $yaml .= " steps:\n"; | |||||||||||||||||||||||||||
| 396 | 60 | $yaml .= " - uses: actions/checkout\@v7\n\n"; | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 60 | $yaml .= " - name: Setup Perl\n"; | |||||||||||||||||||||||||||
| 399 | 60 | $yaml .= " id: setup-perl\n"; | |||||||||||||||||||||||||||
| 400 | 60 | $yaml .= " uses: shogo82148/actions-setup-perl\@v1.44.5\n"; | |||||||||||||||||||||||||||
| 401 | 60 | $yaml .= " with:\n"; | |||||||||||||||||||||||||||
| 402 | 60 | $yaml .= " perl-version: \${{ matrix.perl }}\n\n"; | |||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | # Hash the actual Perl binary files so the cache key changes whenever the | ||||||||||||||||||||||||||||
| 405 | # binary changes, even across silent Strawberry Perl re-releases that keep the | ||||||||||||||||||||||||||||
| 406 | # same $Config{version} string but change the DLL ABI and handshake key. | ||||||||||||||||||||||||||||
| 407 | # On Windows we hash both perl.exe and the Perl runtime DLL (e.g. perl540.dll) | ||||||||||||||||||||||||||||
| 408 | # because perl.exe is a thin stub — only the DLL contains the real runtime. | ||||||||||||||||||||||||||||
| 409 | # shell: perl {0} runs identically on Linux, macOS, and Windows. | ||||||||||||||||||||||||||||
| 410 | 60 | $yaml .= " - name: Get exact Perl binary version for cache key\n"; | |||||||||||||||||||||||||||
| 411 | 60 | $yaml .= " id: perl-version\n"; | |||||||||||||||||||||||||||
| 412 | 60 | $yaml .= " shell: perl {0}\n"; | |||||||||||||||||||||||||||
| 413 | 60 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 414 | 60 | $yaml .= <<'VERSION_STEP'; | |||||||||||||||||||||||||||
| 415 | use Config; | ||||||||||||||||||||||||||||
| 416 | my @paths = ($^X); | ||||||||||||||||||||||||||||
| 417 | if ($^O eq 'MSWin32' && $Config{libperl}) { | ||||||||||||||||||||||||||||
| 418 | (my $dir = $^X) =~ s{[\\/][^\\/]+$}{}; | ||||||||||||||||||||||||||||
| 419 | my $dll = "$dir/$Config{libperl}"; | ||||||||||||||||||||||||||||
| 420 | push @paths, $dll if -f $dll; | ||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | my $sum = 0; | ||||||||||||||||||||||||||||
| 423 | for my $path (@paths) { | ||||||||||||||||||||||||||||
| 424 | open(my $fh, '<:raw', $path) or next; | ||||||||||||||||||||||||||||
| 425 | $sum += unpack('%32C*', $_) while read $fh, $_, 65536; | ||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | open(my $out, '>>', $ENV{GITHUB_OUTPUT}) or die $!; | ||||||||||||||||||||||||||||
| 428 | print $out "version=$Config{version}-$Config{archname}-$sum\n"; | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | VERSION_STEP | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 60 | $yaml .= " - name: Cache CPAN modules\n"; | |||||||||||||||||||||||||||
| 433 | 60 | $yaml .= " uses: actions/cache\@v6\n"; | |||||||||||||||||||||||||||
| 434 | 60 | $yaml .= " with:\n"; | |||||||||||||||||||||||||||
| 435 | 60 | $yaml .= " path: ~/perl5\n"; | |||||||||||||||||||||||||||
| 436 | 60 | $yaml .= " key: \${{ runner.os }}-perl-\${{ steps.perl-version.outputs.version }}-\${{ hashFiles('cpanfile') }}\n"; | |||||||||||||||||||||||||||
| 437 | 60 | $yaml .= " restore-keys: |\n"; | |||||||||||||||||||||||||||
| 438 | 60 | $yaml .= " \${{ runner.os }}-perl-\${{ steps.perl-version.outputs.version }}-\n\n"; | |||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 60 | $yaml .= " - name: Install cpanm and local::lib\n"; | |||||||||||||||||||||||||||
| 441 | 60 | $yaml .= " if: runner.os != 'Windows'\n"; | |||||||||||||||||||||||||||
| 442 | 60 | $yaml .= " run: cpanm --notest --local-lib=~/perl5 local::lib\n\n"; | |||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 60 | $yaml .= " - name: Install cpanm and local::lib (Windows)\n"; | |||||||||||||||||||||||||||
| 445 | 60 | $yaml .= " if: runner.os == 'Windows'\n"; | |||||||||||||||||||||||||||
| 446 | 60 | $yaml .= " run: cpanm --notest App::cpanminus local::lib\n\n"; | |||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | # Many CPAN modules need DB_File, but projects that do not can opt out | ||||||||||||||||||||||||||||
| 449 | 60 | ▶ | if ($install_db_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | 58 | $yaml .= " - name: Install DB_File, needed for a lot of CPAN modules\n"; | |||||||||||||||||||||||||||
| 451 | 58 | $yaml .= " if: runner.os == 'Linux'\n"; | |||||||||||||||||||||||||||
| 452 | 58 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 453 | 58 | $yaml .= " sudo apt update\n"; | |||||||||||||||||||||||||||
| 454 | 58 | $yaml .= " sudo apt install libdb-dev libperl-dev\n"; | |||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 60 | $yaml .= " - name: Install dependencies\n"; | |||||||||||||||||||||||||||
| 458 | 60 | $yaml .= " if: runner.os != 'Windows'\n"; | |||||||||||||||||||||||||||
| 459 | 60 | $yaml .= " shell: bash\n"; | |||||||||||||||||||||||||||
| 460 | 60 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 461 | 60 | $yaml .= " eval \"\$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\"\n"; | |||||||||||||||||||||||||||
| 462 | # --verbose stops GitHub Actions cancelling the job for "no activity" | ||||||||||||||||||||||||||||
| 463 | # when there are a lot of prerequisites; the command is shared by the | ||||||||||||||||||||||||||||
| 464 | # Unix and Windows install steps | ||||||||||||||||||||||||||||
| 465 | 60 | ▶ | my $cpanm_install = 'cpanm --notest --installdeps' . ($cpanm_verbose ? ' --verbose' : '') . ' .'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | 60 | $yaml .= " $cpanm_install\n\n"; | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 60 | $yaml .= " - name: Install dependencies (Windows)\n"; | |||||||||||||||||||||||||||
| 469 | 60 | $yaml .= " if: runner.os == 'Windows'\n"; | |||||||||||||||||||||||||||
| 470 | 60 | $yaml .= " shell: cmd\n"; | |||||||||||||||||||||||||||
| 471 | 60 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 472 | 60 | $yaml .= " \@echo off\n"; | |||||||||||||||||||||||||||
| 473 | 60 | $yaml .= " set \"PATH=%USERPROFILE%\\perl5\\bin;%PATH%\"\n"; | |||||||||||||||||||||||||||
| 474 | 60 | $yaml .= " set \"PERL5LIB=%USERPROFILE%\\perl5\\lib\\perl5\"\n"; | |||||||||||||||||||||||||||
| 475 | 60 | $yaml .= " $cpanm_install\n\n"; | |||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | # The shogo82148 Perl distributions bundle pre-compiled XS modules (e.g. | ||||||||||||||||||||||||||||
| 478 | # YAML::XS) in the Perl zip. cpanm sees them as "already installed" and | ||||||||||||||||||||||||||||
| 479 | # skips recompilation, leaving a DLL that may have the wrong handshake key. | ||||||||||||||||||||||||||||
| 480 | # Force-reinstall YAML::XS into site/lib (which precedes the bundled lib in | ||||||||||||||||||||||||||||
| 481 | # @INC) to ensure a freshly compiled copy is always used. | ||||||||||||||||||||||||||||
| 482 | # NOTE: this step cannot rescue a fundamentally broken distribution where | ||||||||||||||||||||||||||||
| 483 | # libperl540.a and perl.exe themselves are from different builds (as in the | ||||||||||||||||||||||||||||
| 484 | # shogo82148 perl-5.40.4-thr-win32-x64.zip build) — that case is handled | ||||||||||||||||||||||||||||
| 485 | # by the matrix exclusion above. | ||||||||||||||||||||||||||||
| 486 | 60 | $yaml .= " - name: Reinstall YAML::XS against current Perl (Windows)\n"; | |||||||||||||||||||||||||||
| 487 | 60 | $yaml .= " if: runner.os == 'Windows'\n"; | |||||||||||||||||||||||||||
| 488 | 60 | $yaml .= " shell: cmd\n"; | |||||||||||||||||||||||||||
| 489 | 60 | $yaml .= " run: cpanm --notest --reinstall YAML::XS\n\n"; | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 60 | ▶ | if ($enable_linter) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | 55 | $yaml .= " - name: Lint and syntax check\n"; | |||||||||||||||||||||||||||
| 493 | 55 | $yaml .= " shell: perl {0}\n"; | |||||||||||||||||||||||||||
| 494 | 55 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 495 | 55 | $yaml .= <<'LINT_STEP'; | |||||||||||||||||||||||||||
| 496 | use strict; | ||||||||||||||||||||||||||||
| 497 | use warnings; | ||||||||||||||||||||||||||||
| 498 | use File::Find; | ||||||||||||||||||||||||||||
| 499 | use lib 'lib'; | ||||||||||||||||||||||||||||
| 500 | my @failed; | ||||||||||||||||||||||||||||
| 501 | push @INC, sub { open my $h, '<', \qq{1;\n}; $h }; | ||||||||||||||||||||||||||||
| 502 | my @dirs = grep { -d } qw(lib bin); | ||||||||||||||||||||||||||||
| 503 | @dirs = ('.') unless @dirs; | ||||||||||||||||||||||||||||
| 504 | find({ wanted => sub { | ||||||||||||||||||||||||||||
| 505 | return unless -f && /\.pm$/; | ||||||||||||||||||||||||||||
| 506 | my $file = $File::Find::name; | ||||||||||||||||||||||||||||
| 507 | do $file; | ||||||||||||||||||||||||||||
| 508 | if ($@) { | ||||||||||||||||||||||||||||
| 509 | warn "Syntax check failed: $file\n"; | ||||||||||||||||||||||||||||
| 510 | push @failed, $file; | ||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | }, no_chdir => 1 }, @dirs); | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | LINT_STEP | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | 55 | ▶ | if ($enable_linter_unused) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 517 | 52 | $yaml .= <<'UNUSED_CODE'; | |||||||||||||||||||||||||||
| 518 | if (($ENV{RUNNER_OS} // '') eq 'Linux') { | ||||||||||||||||||||||||||||
| 519 | system('cpanm --notest --quiet warnings::unused 2>/dev/null'); | ||||||||||||||||||||||||||||
| 520 | system('PERL5OPT=-Mwarnings::unused prove -lr t/ 2>&1 | grep -i unused && true || echo "warnings::unused: no unused variables detected"'); | ||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | UNUSED_CODE | ||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 55 | $yaml .= " exit(\@failed ? 1 : 0);\n\n"; | |||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 60 | $yaml .= " - name: Run tests\n"; | |||||||||||||||||||||||||||
| 530 | 60 | $yaml .= " if: runner.os != 'Windows'\n"; | |||||||||||||||||||||||||||
| 531 | 60 | $yaml .= " shell: bash\n"; | |||||||||||||||||||||||||||
| 532 | 60 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 533 | 60 | $yaml .= " eval \"\$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\"\n"; | |||||||||||||||||||||||||||
| 534 | 60 | $yaml .= " prove -lr t/\n\n"; | |||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 60 | $yaml .= " - name: Run tests (Windows)\n"; | |||||||||||||||||||||||||||
| 537 | 60 | $yaml .= " if: runner.os == 'Windows'\n"; | |||||||||||||||||||||||||||
| 538 | 60 | $yaml .= " shell: cmd\n"; | |||||||||||||||||||||||||||
| 539 | 60 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 540 | 60 | $yaml .= " \@echo off\n"; | |||||||||||||||||||||||||||
| 541 | 60 | $yaml .= " set \"PATH=%USERPROFILE%\\perl5\\bin;%PATH%\"\n"; | |||||||||||||||||||||||||||
| 542 | 60 | $yaml .= " set \"PERL5LIB=%USERPROFILE%\\perl5\\lib\\perl5\"\n"; | |||||||||||||||||||||||||||
| 543 | 60 | $yaml .= " prove -lr t/\n\n"; | |||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | 60 | ▶ | if ($enable_critic) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 546 | 53 | my $latest = $perl_versions[-1]; | |||||||||||||||||||||||||||
| 547 | 53 | $yaml .= " - name: Run Perl::Critic\n"; | |||||||||||||||||||||||||||
| 548 | 53 | $yaml .= " if: matrix.perl == '$latest' && matrix.os == 'ubuntu-latest'\n"; | |||||||||||||||||||||||||||
| 549 | 53 | $yaml .= " continue-on-error: true\n"; | |||||||||||||||||||||||||||
| 550 | 53 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 551 | 53 | $yaml .= " eval \"\$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\"\n"; | |||||||||||||||||||||||||||
| 552 | 53 | $yaml .= " cpanm --notest Perl::Critic\n"; | |||||||||||||||||||||||||||
| 553 | 53 | $yaml .= " perlcritic --severity 3 lib/ || true\n"; | |||||||||||||||||||||||||||
| 554 | 53 | $yaml .= " shell: bash\n\n"; | |||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | 60 | ▶ | if ($enable_perlimports) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 558 | 56 | my $latest = $perl_versions[-1]; | |||||||||||||||||||||||||||
| 559 | 56 | $yaml .= " - name: Check imports with perlimports\n"; | |||||||||||||||||||||||||||
| 560 | 56 | $yaml .= " if: matrix.perl == '$latest' && matrix.os == 'ubuntu-latest'\n"; | |||||||||||||||||||||||||||
| 561 | 56 | $yaml .= " continue-on-error: true\n"; | |||||||||||||||||||||||||||
| 562 | 56 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 563 | 56 | $yaml .= " eval \"\$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\"\n"; | |||||||||||||||||||||||||||
| 564 | 56 | $yaml .= " cpanm --notest App::perlimports\n"; | |||||||||||||||||||||||||||
| 565 | 56 | $yaml .= " find lib -name '*.pm' -print0 | xargs -0 perlimports --lint\n"; | |||||||||||||||||||||||||||
| 566 | 56 | $yaml .= " shell: bash\n\n"; | |||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | 60 | ▶ | if ($enable_coverage) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 570 | 53 | my $latest = $perl_versions[-1]; | |||||||||||||||||||||||||||
| 571 | 53 | $yaml .= " - name: Test coverage\n"; | |||||||||||||||||||||||||||
| 572 | 53 | $yaml .= " if: matrix.perl == '$latest' && matrix.os == 'ubuntu-latest'\n"; | |||||||||||||||||||||||||||
| 573 | 53 | $yaml .= " run: |\n"; | |||||||||||||||||||||||||||
| 574 | 53 | $yaml .= " eval \"\$(perl -I ~/perl5/lib/perl5 -Mlocal::lib)\"\n"; | |||||||||||||||||||||||||||
| 575 | 53 | $yaml .= " cpanm --notest Devel::Cover\n"; | |||||||||||||||||||||||||||
| 576 | 53 | $yaml .= " cover -delete\n"; | |||||||||||||||||||||||||||
| 577 | 53 | $yaml .= " HARNESS_PERL_SWITCHES=-MDevel::Cover prove -lr t/\n"; | |||||||||||||||||||||||||||
| 578 | 53 | $yaml .= " cover\n"; | |||||||||||||||||||||||||||
| 579 | 53 | $yaml .= " shell: bash\n"; | |||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | 60 | $yaml .= <<'YAML'; | |||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | - name: Show cpanm build log on failure (Windows) | ||||||||||||||||||||||||||||
| 585 | if: runner.os == 'Windows' && failure() | ||||||||||||||||||||||||||||
| 586 | shell: pwsh | ||||||||||||||||||||||||||||
| 587 | run: Get-Content "$env:USERPROFILE\.cpanm\work\*\build.log" -Tail 100 | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | - name: Show cpanm build log on failure (non-Windows) | ||||||||||||||||||||||||||||
| 590 | if: runner.os != 'Windows' && failure() | ||||||||||||||||||||||||||||
| 591 | run: tail -100 "$HOME/.cpanm/work/*/build.log" | ||||||||||||||||||||||||||||
| 592 | YAML | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | 60 | return $yaml; | |||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 58 | ▶ | sub _get_perl_versions($min, $max) { | ||||||||||||||||||||||||||
|
Subroutine
_get_perl_versions: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 598 | # All available Perl versions in descending order. | ||||||||||||||||||||||||||||
| 599 | # 5.44 is listed so projects can opt in via max_perl_version => '5.44', | ||||||||||||||||||||||||||||
| 600 | # but it is not included in the default matrix (max defaults to 5.42). | ||||||||||||||||||||||||||||
| 601 | 58 | my @all_versions = qw(5.44 5.42 5.40 5.38 5.36 5.34 5.32 5.30 5.28 5.26 5.24 5.22); | |||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | # Normalize version strings for comparison | ||||||||||||||||||||||||||||
| 604 | 58 | my $min_normalized = _normalize_version($min); | |||||||||||||||||||||||||||
| 605 | 58 | my $max_normalized = _normalize_version($max); | |||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | 58 | my @selected; | |||||||||||||||||||||||||||
| 608 | 58 | for my $version (@all_versions) { | |||||||||||||||||||||||||||
| 609 | 696 | my $v_normalized = _normalize_version($version); | |||||||||||||||||||||||||||
| 610 | 696 | ▶ | if ($v_normalized >= $min_normalized && $v_normalized <= $max_normalized) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$v_normalized >= $min_normalized and $v_normalized <= $max_normalized
MC/DC100%2/2
$v_normalized >= $min_normalized and $v_normalized <= $max_normalized
$v_normalized >= $min_normalized
$v_normalized <= $max_normalized
Truth table100%3/3
A and B
A= $v_normalized >= $min_normalizedB= $v_normalized <= $max_normalized
| |||||||||||||||||||||||||||||
| 611 | 217 | push @selected, $version; | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | 58 | return reverse @selected; # Return in ascending order | |||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | 818 | ▶ | sub _normalize_version($version) { | ||||||||||||||||||||||||||
|
Subroutine
_normalize_version: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||
| 619 | # Convert "5.036" or "5.36" to comparable number | ||||||||||||||||||||||||||||
| 620 | 818 | $version =~ s/^v?//; | |||||||||||||||||||||||||||
| 621 | 818 | my @parts = split /\./, $version; | |||||||||||||||||||||||||||
| 622 | 818 | ▶ | return sprintf('%d.%03d', $parts[0] // 5, $parts[1] // 0); | ||||||||||||||||||||||||||
|
Condition50%2/4
$parts[0] // 5
$parts[1] // 0
MC/DC0%0/1
$parts[0] // 5
$parts[0]
MC/DC0%0/1
$parts[1] // 0
$parts[1]
Truth table50%1/2
A
A= $parts[0]
Truth table50%1/2
A
A= $parts[1]
| |||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | =head1 LIMITATIONS | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | =head2 Windows + Perl 5.40 excluded from the generated matrix | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | The shogo82148 C<perl-5.40.4-thr-win32-x64.zip> distribution ships a | ||||||||||||||||||||||||||||
| 630 | C<perl.exe> and a C<libperl540.a> from two different builds. Any XS module | ||||||||||||||||||||||||||||
| 631 | compiled against that C<libperl540.a> receives handshake key | ||||||||||||||||||||||||||||
| 632 | C<0x12c00080>, but C<perl.exe> needs C<0x12d00080>. Even | ||||||||||||||||||||||||||||
| 633 | C<Win32::Process> - a core Windows XS module bundled in the zip and loaded | ||||||||||||||||||||||||||||
| 634 | transitively by C<IPC::System::Simple> - fails to load with this mismatch, | ||||||||||||||||||||||||||||
| 635 | so no XS-using test can pass on this combination. | ||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | Recompiling XS modules (e.g. via C<cpanm --reinstall YAML::XS>) does not | ||||||||||||||||||||||||||||
| 638 | help: the compilation itself links against the broken C<libperl540.a> and | ||||||||||||||||||||||||||||
| 639 | inherits the wrong key. | ||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | The generated workflow therefore includes a C<matrix.exclude> entry for | ||||||||||||||||||||||||||||
| 642 | C<{os: windows-latest, perl: '5.40'}>. This entry is only emitted when | ||||||||||||||||||||||||||||
| 643 | both C<windows-latest> and C<5.40> are present in the matrix, so workflows | ||||||||||||||||||||||||||||
| 644 | that restrict their OS or Perl lists are unaffected. | ||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||
| 646 | Remove the exclusion once the upstream shogo82148/build-perl distribution | ||||||||||||||||||||||||||||
| 647 | is fixed and the C<perl.exe> and C<libperl540.a> in the 5.40.x zip are | ||||||||||||||||||||||||||||
| 648 | built from the same source tree. | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | See L<https://github.com/shogo82148/actions-setup-perl/issues/2310> for further information. | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | Nigel Horne E<lt>njh@nigelhorne.comE<gt> | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | L<https://github.com/nigelhorne> | ||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||
| 658 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | Usage is subject to the GPL2 licence terms. | ||||||||||||||||||||||||||||
| 661 | If you use it, | ||||||||||||||||||||||||||||
| 662 | please let me know. | ||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||
| 664 | =cut | ||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | 67 | 1; | |||||||||||||||||||||||||||