| 1 | package App::GHGen::Generator; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 64 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 64 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 64 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 64 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 64 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 64 | ▶ | use List::Util qw(uniq); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 64 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 64 | ▶ | use App::GHGen::PerlCustomizer qw(detect_perl_requirements generate_custom_perl_workflow); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 64 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 64 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||
| 16 | generate_workflow | ||||||||||||||||||||||||||||||||||||||
| 17 | list_workflow_types | ||||||||||||||||||||||||||||||||||||||
| 18 | parse_os_list | ||||||||||||||||||||||||||||||||||||||
| 19 | parse_version_list | ||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | # A version is a single token: letters, digits and . + * - _ only. Anything | ||||||||||||||||||||||||||||||||||||||
| 23 | # else (newlines, quotes, colons) could break out of the YAML scalar the | ||||||||||||||||||||||||||||||||||||||
| 24 | # version is written into. | ||||||||||||||||||||||||||||||||||||||
| 25 | 64 | Readonly my $VERSION_PATTERN => qr/\A[\w.+*-]+\z/; | |||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | # Short OS names accepted by --os, mapped to GitHub runner labels. | ||||||||||||||||||||||||||||||||||||||
| 28 | 64 | Readonly my %RUNNER_LABEL_FOR => ( | |||||||||||||||||||||||||||||||||||||
| 29 | linux => 'ubuntu-latest', | ||||||||||||||||||||||||||||||||||||||
| 30 | ubuntu => 'ubuntu-latest', | ||||||||||||||||||||||||||||||||||||||
| 31 | macos => 'macos-latest', | ||||||||||||||||||||||||||||||||||||||
| 32 | windows => 'windows-latest', | ||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | # A literal runner label such as ubuntu-22.04 is passed through unchanged. | ||||||||||||||||||||||||||||||||||||||
| 36 | 64 | Readonly my $RUNNER_LABEL_PATTERN => qr/\A(?:ubuntu|macos|windows)-[\w.]+\z/; | |||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | # Generator types that expose a "<key>:" list of versions in their matrix. | ||||||||||||||||||||||||||||||||||||||
| 39 | 64 | Readonly my %MATRIX_KEY_FOR => ( | |||||||||||||||||||||||||||||||||||||
| 40 | node => 'node-version', | ||||||||||||||||||||||||||||||||||||||
| 41 | python => 'python-version', | ||||||||||||||||||||||||||||||||||||||
| 42 | ruby => 'ruby-version', | ||||||||||||||||||||||||||||||||||||||
| 43 | java => 'java-version', | ||||||||||||||||||||||||||||||||||||||
| 44 | php => 'php-version', | ||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | # Types with no language version to vary at all. | ||||||||||||||||||||||||||||||||||||||
| 48 | 64 | Readonly my %VERSIONLESS_TYPE => map { $_ => 1 } qw(cpp docker static); | |||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | # The Go and Rust templates pin one version; these are the texts rewritten | ||||||||||||||||||||||||||||||||||||||
| 51 | # to turn that pin into a matrix. | ||||||||||||||||||||||||||||||||||||||
| 52 | 64 | Readonly my $GO_PINNED_VERSION => qr/go-version: '1\.22'/; | |||||||||||||||||||||||||||||||||||||
| 53 | 64 | Readonly my $RUST_TOOLCHAIN_STEP => qr/(uses: dtolnay\/rust-toolchain\@stable\n)/; | |||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | # Every user-facing message lives here so it can be translated or reworded | ||||||||||||||||||||||||||||||||||||||
| 56 | # without touching the logic. Values are sprintf formats; see _message(). | ||||||||||||||||||||||||||||||||||||||
| 57 | 64 | our %MESSAGES = ( | |||||||||||||||||||||||||||||||||||||
| 58 | invalid_version => "Invalid version '%s' for --versions", | ||||||||||||||||||||||||||||||||||||||
| 59 | no_versions => '--versions requires at least one version', | ||||||||||||||||||||||||||||||||||||||
| 60 | unknown_os => "Unknown OS '%s' for --os (use linux, macos, windows)", | ||||||||||||||||||||||||||||||||||||||
| 61 | no_os => '--os requires at least one operating system', | ||||||||||||||||||||||||||||||||||||||
| 62 | versions_ignored => "--versions has no effect for type '%s'", | ||||||||||||||||||||||||||||||||||||||
| 63 | unknown_message => "Internal error: unknown message key '%s'", | ||||||||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | 64 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||
| 72 | App::GHGen::Generator - Generate GitHub Actions workflows | ||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | use App::GHGen::Generator qw(generate_workflow); | ||||||||||||||||||||||||||||||||||||||
| 77 | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | my $yaml = generate_workflow('perl'); | ||||||||||||||||||||||||||||||||||||||
| 80 | path('.github/workflows/ci.yml')->spew_utf8($yaml); | ||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | =head2 generate_workflow($type, \%opts) | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | Generate a complete GitHub Actions workflow YAML string for the given project type. | ||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | =head3 Purpose | ||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | Dispatch to the appropriate language-specific workflow generator and return | ||||||||||||||||||||||||||||||||||||||
| 91 | the resulting YAML string ready to be written to a C<.github/workflows/> file. | ||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | =head3 Arguments | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | =item C<$type> (Str, required) | ||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||
| 99 | A project-type identifier. Supported values: C<perl>, C<node>, C<python>, | ||||||||||||||||||||||||||||||||||||||
| 100 | C<rust>, C<go>, C<ruby>, C<java>, C<cpp>, C<php>, C<docker>, C<static>. | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | =item C<$opts> (HashRef, optional) | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | =item C<versions> (ArrayRef of Str) | ||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | Language/runtime versions to test against, replacing the default matrix. | ||||||||||||||||||||||||||||||||||||||
| 109 | Applies to C<perl>, C<node>, C<python>, C<ruby>, C<java>, C<php>, C<go> | ||||||||||||||||||||||||||||||||||||||
| 110 | (Go Go-versions) and C<rust> (toolchains, e.g. C<stable>, C<beta>, C<1.80>). | ||||||||||||||||||||||||||||||||||||||
| 111 | It is ignored for C<cpp>, C<docker> and C<static>, which have no version | ||||||||||||||||||||||||||||||||||||||
| 112 | matrix. Each entry may contain only letters, digits, C<.>, C<->, C<+>, | ||||||||||||||||||||||||||||||||||||||
| 113 | C<*> and C<_>; anything else croaks. | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | Defaults when C<versions> is not given: perl 5.36, 5.38, 5.40, 5.42; | ||||||||||||||||||||||||||||||||||||||
| 116 | node 18.x, 20.x, 22.x; python 3.9-3.12; ruby 3.1-3.3; java 11, 17, 21; | ||||||||||||||||||||||||||||||||||||||
| 117 | php 8.1-8.3; go 1.22; rust stable. | ||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||
| 119 | =back | ||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||
| 121 | =back | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | =head3 Returns | ||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||
| 125 | A multi-line YAML string beginning with C<---> when C<$type> is recognised, | ||||||||||||||||||||||||||||||||||||||
| 126 | or C<undef> when the type is not supported. | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | =head3 Side Effects | ||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | The C<perl> type without C<versions> reads the current directory to detect | ||||||||||||||||||||||||||||||||||||||
| 131 | project requirements (via L<App::GHGen::PerlCustomizer>). Passing | ||||||||||||||||||||||||||||||||||||||
| 132 | C<versions> for C<cpp>, C<docker> or C<static> emits a C<carp> warning. | ||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||
| 134 | =head3 Usage | ||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | use App::GHGen::Generator qw(generate_workflow); | ||||||||||||||||||||||||||||||||||||||
| 137 | my $yaml = generate_workflow('node') // die "unsupported type"; | ||||||||||||||||||||||||||||||||||||||
| 138 | path('.github/workflows/ci.yml')->spew_utf8($yaml); | ||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||
| 140 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||
| 142 | # Default matrix | ||||||||||||||||||||||||||||||||||||||
| 143 | my $default = generate_workflow('python'); | ||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | # Only test the two newest Pythons | ||||||||||||||||||||||||||||||||||||||
| 146 | my $custom = generate_workflow('python', { versions => ['3.12', '3.13'] }); | ||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | # Go pins one version by default; --versions turns it into a matrix | ||||||||||||||||||||||||||||||||||||||
| 149 | my $go = generate_workflow('go', { versions => ['1.23', '1.24'] }); | ||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||
| 153 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||
| 155 | =item C<Invalid version '%s' for --versions> (croak) | ||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||
| 157 | An entry in C<versions> contains characters outside C<[A-Za-z0-9_.+*-]>. | ||||||||||||||||||||||||||||||||||||||
| 158 | Remove the offending characters. | ||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | =item C<--versions has no effect for type '%s'> (carp) | ||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||
| 162 | C<versions> was supplied for C<cpp>, C<docker> or C<static>, which have no | ||||||||||||||||||||||||||||||||||||||
| 163 | version matrix. The YAML is returned unchanged; drop the option. | ||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | =back | ||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||
| 167 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||
| 169 | =head4 Input | ||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||||||||||||
| 172 | type => { type => 'scalar', required => 1 }, | ||||||||||||||||||||||||||||||||||||||
| 173 | opts => { | ||||||||||||||||||||||||||||||||||||||
| 174 | type => 'hashref', | ||||||||||||||||||||||||||||||||||||||
| 175 | optional => 1, | ||||||||||||||||||||||||||||||||||||||
| 176 | keys => { versions => { type => 'arrayref', optional => 1 } }, | ||||||||||||||||||||||||||||||||||||||
| 177 | }, | ||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||
| 180 | =head4 Output | ||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||
| 182 | known type -> { type => 'scalar' } # YAML string | ||||||||||||||||||||||||||||||||||||||
| 183 | unknown type -> undef | ||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||
| 185 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||
| 187 | SupportedTypes ≔ { perl, node, python, rust, go, ruby, java, cpp, php, docker, static } | ||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||
| 189 | generate_workflow : ℤ* → ℤ* ∪ { ⊥ } | ||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||
| 191 | t ∈ SupportedTypes ∧ versions = ∅ → generators[t]() (default matrix) | ||||||||||||||||||||||||||||||||||||||
| 192 | t ∈ SupportedTypes ∧ versions ≠ ∅ → rewrite(generators[t](), versions) | ||||||||||||||||||||||||||||||||||||||
| 193 | t ∉ SupportedTypes → ⊥ (undef) | ||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||
| 195 | ∀ v ∈ versions • v ∈ VersionToken (else croak) | ||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||
| 197 | =head3 PSEUDOCODE | ||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||
| 199 | look up the generator for $type; return undef when there is none | ||||||||||||||||||||||||||||||||||||||
| 200 | when no versions were requested, return the generator's default YAML | ||||||||||||||||||||||||||||||||||||||
| 201 | validate every requested version (croak on an unsafe one) | ||||||||||||||||||||||||||||||||||||||
| 202 | warn when the type has no version matrix | ||||||||||||||||||||||||||||||||||||||
| 203 | perl: regenerate with the explicit version list | ||||||||||||||||||||||||||||||||||||||
| 204 | node/python/ruby/java/php: replace the existing matrix list | ||||||||||||||||||||||||||||||||||||||
| 205 | go/rust: replace the pinned version with a matrix reference and | ||||||||||||||||||||||||||||||||||||||
| 206 | insert a one-key matrix under the job | ||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||
| 208 | =cut | ||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||
| 210 | 78 | ▶ | sub generate_workflow($type, $opts = {}) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_workflow: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 211 | 78 | my %generators = ( | |||||||||||||||||||||||||||||||||||||
| 212 | perl => \&_generate_perl_workflow, | ||||||||||||||||||||||||||||||||||||||
| 213 | node => \&_generate_node_workflow, | ||||||||||||||||||||||||||||||||||||||
| 214 | python => \&_generate_python_workflow, | ||||||||||||||||||||||||||||||||||||||
| 215 | rust => \&_generate_rust_workflow, | ||||||||||||||||||||||||||||||||||||||
| 216 | go => \&_generate_go_workflow, | ||||||||||||||||||||||||||||||||||||||
| 217 | ruby => \&_generate_ruby_workflow, | ||||||||||||||||||||||||||||||||||||||
| 218 | java => \&_generate_java_workflow, | ||||||||||||||||||||||||||||||||||||||
| 219 | cpp => \&_generate_cpp_workflow, | ||||||||||||||||||||||||||||||||||||||
| 220 | php => \&_generate_php_workflow, | ||||||||||||||||||||||||||||||||||||||
| 221 | docker => \&_generate_docker_workflow, | ||||||||||||||||||||||||||||||||||||||
| 222 | static => \&_generate_static_workflow, | ||||||||||||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||
| 225 | 78 | my $generator = $generators{$type}; | |||||||||||||||||||||||||||||||||||||
| 226 | 78 | my $versions = $opts->{versions}; | |||||||||||||||||||||||||||||||||||||
| 227 | 78 | my $yaml; | |||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||
| 229 | 78 | ▶ | if (!$generator) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 230 | # Unknown type: documented to return undef rather than croak | ||||||||||||||||||||||||||||||||||||||
| 231 | 4 | $yaml = undef; | |||||||||||||||||||||||||||||||||||||
| 232 | 26 | ▶ | } elsif (!($versions && @{$versions})) { | ||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$versions && @{$versions;}
MC/DC100%2/2
$versions && @{$versions;}
$versions
@{$versions;}
Truth table100%3/3
A && B
A= $versionsB= @{$versions;}
| |||||||||||||||||||||||||||||||||||||||
| 233 | 49 | $yaml = $generator->(); | |||||||||||||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||||||||||||
| 235 | # Validate before touching the template so a bad value never reaches YAML | ||||||||||||||||||||||||||||||||||||||
| 236 | 25 | _validate_versions($versions); | |||||||||||||||||||||||||||||||||||||
| 237 | 24 | ▶ | carp _message('versions_ignored', $type) if $VERSIONLESS_TYPE{$type}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||
| 239 | # Perl builds its matrix itself; the other types are rewritten text | ||||||||||||||||||||||||||||||||||||||
| 240 | $yaml = ($type eq 'perl') | ||||||||||||||||||||||||||||||||||||||
| 241 | 24 | ▶ | ? generate_custom_perl_workflow({ perl_versions => [ @{$versions} ] }) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 242 | : _apply_versions($type, $generator->(), $versions); | ||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||
| 245 | 77 | return $yaml; | |||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||
| 248 | =head2 parse_version_list($text) | ||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | Turn a comma-separated C<--versions> string into a validated list of versions. | ||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||
| 252 | =head3 Purpose | ||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||
| 254 | Give the command line and the API one definition of what a version list is, | ||||||||||||||||||||||||||||||||||||||
| 255 | so C<--versions=5.40, 5.42> means the same thing everywhere. | ||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||
| 257 | =head3 Arguments | ||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||
| 259 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | =item C<$text> (Str, required) | ||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||
| 263 | Comma-separated versions. Whitespace around entries is ignored, empty | ||||||||||||||||||||||||||||||||||||||
| 264 | entries are dropped and duplicates are removed, keeping the first occurrence. | ||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||
| 266 | =back | ||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | =head3 Returns | ||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||
| 270 | An array reference of version strings, in the order given. | ||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||
| 272 | =head3 Side Effects | ||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||
| 274 | None. | ||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||
| 276 | =head3 Usage | ||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||
| 278 | my $versions = parse_version_list($ARGV_versions); | ||||||||||||||||||||||||||||||||||||||
| 279 | my $yaml = generate_workflow('node', { versions => $versions }); | ||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||
| 281 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||
| 283 | parse_version_list('20, 22,20'); # ['20', '22'] | ||||||||||||||||||||||||||||||||||||||
| 284 | parse_version_list('5.40,5.42'); # ['5.40', '5.42'] | ||||||||||||||||||||||||||||||||||||||
| 285 | parse_version_list(','); # croaks: needs at least one version | ||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||
| 287 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||
| 289 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||
| 291 | =item C<--versions requires at least one version> (croak) | ||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | C<$text> contained no entries. Supply at least one version. | ||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||
| 295 | =item C<Invalid version '%s' for --versions> (croak) | ||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||
| 297 | An entry contains characters outside C<[A-Za-z0-9_.+*-]>. | ||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||
| 299 | =back | ||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||
| 301 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||
| 303 | =head4 Input | ||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||
| 305 | { text => { type => 'scalar', required => 1, min => 1 } } | ||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||
| 307 | =head4 Output | ||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||
| 309 | { type => 'arrayref', min => 1, element_type => 'scalar' } | ||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||
| 311 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||
| 313 | VersionToken ≔ { s : seq CHAR | s ≠ ⟨⟩ ∧ ran s ⊆ [A-Za-z0-9_.+*-] } | ||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||
| 315 | parse_version_list : TEXT ⇸ seq VersionToken | ||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||
| 317 | items ≔ nodup(split(',', text) ∖ {⟨⟩}) | ||||||||||||||||||||||||||||||||||||||
| 318 | items ≠ ⟨⟩ ∧ items ⊆ VersionToken ⊢ parse_version_list(text) = items | ||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||
| 320 | =cut | ||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||
| 322 | 37 | ▶ | sub parse_version_list($text) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_version_list: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 323 | 37 | my $versions = _split_unique($text); | |||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||
| 325 | # An empty list would silently fall back to the default matrix | ||||||||||||||||||||||||||||||||||||||
| 326 | 37 | ▶ | croak _message('no_versions') unless @{$versions}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||
| 328 | 34 | return _validate_versions($versions); | |||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||
| 331 | =head2 parse_os_list($text) | ||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||
| 333 | Turn a comma-separated C<--os> string into a list of GitHub runner labels. | ||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||
| 335 | =head3 Purpose | ||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||
| 337 | Let users write C<linux,macos> instead of C<ubuntu-latest,macos-latest>, | ||||||||||||||||||||||||||||||||||||||
| 338 | while still accepting a literal label such as C<ubuntu-22.04>. | ||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||
| 340 | =head3 Arguments | ||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||
| 342 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||
| 344 | =item C<$text> (Str, required) | ||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||
| 346 | Comma-separated names, case-insensitive: C<linux>, C<ubuntu>, C<macos>, | ||||||||||||||||||||||||||||||||||||||
| 347 | C<windows>, or a literal label matching C<(ubuntu|macos|windows)-...>. | ||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||
| 349 | =back | ||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||
| 351 | =head3 Returns | ||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||
| 353 | An array reference of runner labels, in the order given, without duplicates. | ||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||
| 355 | =head3 Side Effects | ||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||
| 357 | None. | ||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||
| 359 | =head3 Usage | ||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||
| 361 | my $os = parse_os_list('linux,macos'); # no Windows jobs | ||||||||||||||||||||||||||||||||||||||
| 362 | my $yaml = generate_custom_perl_workflow({ os => $os }); | ||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||
| 364 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||
| 366 | parse_os_list('Linux, macOS'); # ['ubuntu-latest', 'macos-latest'] | ||||||||||||||||||||||||||||||||||||||
| 367 | parse_os_list('ubuntu,linux'); # ['ubuntu-latest'] | ||||||||||||||||||||||||||||||||||||||
| 368 | parse_os_list('ubuntu-22.04'); # ['ubuntu-22.04'] | ||||||||||||||||||||||||||||||||||||||
| 369 | parse_os_list('bsd'); # croaks: unknown OS | ||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||
| 371 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||
| 373 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||
| 375 | =item C<Unknown OS '%s' for --os (use linux, macos, windows)> (croak) | ||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||
| 377 | The name is neither a known short name nor a literal runner label. | ||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||
| 379 | =item C<--os requires at least one operating system> (croak) | ||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||
| 381 | C<$text> contained no entries. | ||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||
| 383 | =back | ||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||
| 385 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||
| 387 | =head4 Input | ||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||
| 389 | { text => { type => 'scalar', required => 1, min => 1 } } | ||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||
| 391 | =head4 Output | ||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||
| 393 | { type => 'arrayref', min => 1, element_type => 'scalar' } | ||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||
| 395 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||
| 397 | Label ≔ { ubuntu-latest, macos-latest, windows-latest } ∪ LiteralLabel | ||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||
| 399 | parse_os_list : TEXT ⇸ seq Label | ||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||
| 401 | names ≔ split(',', lc text) ∖ {⟨⟩} | ||||||||||||||||||||||||||||||||||||||
| 402 | labels ≔ nodup(runner ∘ names) (runner is partial; undefined → croak) | ||||||||||||||||||||||||||||||||||||||
| 403 | labels ≠ ⟨⟩ ⊢ parse_os_list(text) = labels | ||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||
| 405 | =cut | ||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||
| 407 | 25 | ▶ | sub parse_os_list($text) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_os_list: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 408 | # Lower-case first so "Linux" and "LINUX" are accepted | ||||||||||||||||||||||||||||||||||||||
| 409 | 25 | my @labels = uniq map { _runner_label($_) } @{ _split_unique(lc($text)) }; | |||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||
| 411 | 18 | ▶ | croak _message('no_os') unless @labels; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||
| 413 | 14 | return \@labels; | |||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||
| 416 | # Purpose: Split a comma-separated option value into trimmed, non-empty, | ||||||||||||||||||||||||||||||||||||||
| 417 | # de-duplicated entries (first occurrence wins). | ||||||||||||||||||||||||||||||||||||||
| 418 | # Entry: $text is a defined string. | ||||||||||||||||||||||||||||||||||||||
| 419 | # Exit status: Returns an array reference, possibly empty. | ||||||||||||||||||||||||||||||||||||||
| 420 | # Side effects: None. | ||||||||||||||||||||||||||||||||||||||
| 421 | 62 | ▶ | sub _split_unique($text) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_unique: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 422 | 62 | my @entries = grep { length } map { s/\A\s+|\s+\z//gr } split /,/, $text; | |||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||
| 424 | 62 | return [ uniq @entries ]; | |||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||
| 427 | # Purpose: Map one --os name to a GitHub runner label. | ||||||||||||||||||||||||||||||||||||||
| 428 | # Entry: $name is a trimmed, lower-case string. | ||||||||||||||||||||||||||||||||||||||
| 429 | # Exit status: Returns the label; croaks with 'unknown_os' otherwise. | ||||||||||||||||||||||||||||||||||||||
| 430 | # Side effects: None. | ||||||||||||||||||||||||||||||||||||||
| 431 | 32 | ▶ | sub _runner_label($name) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_runner_label: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||
| 432 | 32 | ▶ | my $label = $RUNNER_LABEL_FOR{$name} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$RUNNER_LABEL_FOR{$name} // ($name =~ /$RUNNER_LABEL_PATTERN/u ? $name : undef)
MC/DC100%2/2
$RUNNER_LABEL_FOR{$name} // ($name =~ /$RUNNER_LABEL_PATTERN/u ? $name : undef)
$RUNNER_LABEL_FOR{$name}
($name =~ /$RUNNER_LABEL_PATTERN/u ? $name : undef)
Truth table100%3/3
A // B
A= $RUNNER_LABEL_FOR{$name}B= ($name =~ /$RUNNER_LABEL_PATTERN/u ? $name : undef)
| |||||||||||||||||||||||||||||||||||||||
| 433 | // ($name =~ $RUNNER_LABEL_PATTERN ? $name : undef); | ||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||
| 435 | 32 | ▶ | croak _message('unknown_os', $name) unless defined $label; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||
| 437 | 25 | return $label; | |||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||
| 440 | # Purpose: Reject any version that could break out of a YAML scalar. | ||||||||||||||||||||||||||||||||||||||
| 441 | # Entry: $versions is an array reference of strings. | ||||||||||||||||||||||||||||||||||||||
| 442 | # Exit status: Returns $versions unchanged; croaks with 'invalid_version'. | ||||||||||||||||||||||||||||||||||||||
| 443 | # Side effects: None. | ||||||||||||||||||||||||||||||||||||||
| 444 | 59 | ▶ | sub _validate_versions($versions) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_versions: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||
| 445 | 59 | for my $version (@{$versions}) { | |||||||||||||||||||||||||||||||||||||
| 446 | 105 | ▶ | croak _message('invalid_version', $version // 'undef') | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $version and $version =~ /$VERSION_PATTERN/u
$version // "undef"
MC/DC50%1/2
defined $version and $version =~ /$VERSION_PATTERN/u
defined $version
$version =~ /$VERSION_PATTERN/u
MC/DC0%0/1
$version // "undef"
$version
Truth table66%2/3
A and B
A= defined $versionB= $version =~ /$VERSION_PATTERN/u
Truth table50%1/2
A
A= $version
| |||||||||||||||||||||||||||||||||||||||
| 447 | unless defined $version && $version =~ $VERSION_PATTERN; | ||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||
| 450 | 53 | return $versions; | |||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||
| 453 | # Purpose: Format a message from %MESSAGES with sprintf interpolation. | ||||||||||||||||||||||||||||||||||||||
| 454 | # Entry: $key is a key of %MESSAGES; @args fill its placeholders. | ||||||||||||||||||||||||||||||||||||||
| 455 | # Exit status: Returns the formatted string; an unknown key yields the | ||||||||||||||||||||||||||||||||||||||
| 456 | # 'unknown_message' text instead, so a typo cannot hide an error. | ||||||||||||||||||||||||||||||||||||||
| 457 | # Side effects: None. | ||||||||||||||||||||||||||||||||||||||
| 458 | 27 | ▶ | sub _message($key, @args) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_message: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 459 | 27 | my $format = $MESSAGES{$key}; | |||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||
| 461 | return defined $format | ||||||||||||||||||||||||||||||||||||||
| 462 | ? sprintf($format, @args) | ||||||||||||||||||||||||||||||||||||||
| 463 | 27 | ▶ | : sprintf($MESSAGES{unknown_message}, $key); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||
| 466 | # Purpose: Render version entries as a YAML list at the given indent. | ||||||||||||||||||||||||||||||||||||||
| 467 | # Entry: $indent is the dash column as spaces; $versions is an arrayref. | ||||||||||||||||||||||||||||||||||||||
| 468 | # Exit status: Returns the YAML text; every entry is single-quoted so that | ||||||||||||||||||||||||||||||||||||||
| 469 | # 3.10 stays a string and is not read as the number 3.1. | ||||||||||||||||||||||||||||||||||||||
| 470 | # Side effects: None. | ||||||||||||||||||||||||||||||||||||||
| 471 | 17 | ▶ | sub _matrix_items($indent, $versions) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_matrix_items: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 472 | 17 | return join '', map { "$indent- '$_'\n" } @{$versions}; | |||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||
| 475 | # Purpose: Rewrite the version matrix of a generated workflow. | ||||||||||||||||||||||||||||||||||||||
| 476 | # Entry: $type is a known generator type; $yaml is that type's template; | ||||||||||||||||||||||||||||||||||||||
| 477 | # $versions has been validated. | ||||||||||||||||||||||||||||||||||||||
| 478 | # Exit status: Returns the rewritten YAML; types without a matrix (cpp, | ||||||||||||||||||||||||||||||||||||||
| 479 | # docker, static) come back unchanged. | ||||||||||||||||||||||||||||||||||||||
| 480 | # Side effects: None. | ||||||||||||||||||||||||||||||||||||||
| 481 | 23 | ▶ | sub _apply_versions($type, $yaml, $versions) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_versions: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||
| 482 | 23 | ▶ | if (my $key = $MATRIX_KEY_FOR{$type}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 483 | # Replace the existing list under "<key>:" keeping its indentation | ||||||||||||||||||||||||||||||||||||||
| 484 | 13 | $yaml =~ s{^( +)\Q$key\E:\n(?: +- .*\n)+}{ | |||||||||||||||||||||||||||||||||||||
| 485 | 13 | "$1$key:\n" . _matrix_items("$1 ", $versions) | |||||||||||||||||||||||||||||||||||||
| 486 | }me; | ||||||||||||||||||||||||||||||||||||||
| 487 | } elsif ($type eq 'go') { | ||||||||||||||||||||||||||||||||||||||
| 488 | 2 | $yaml =~ s{$GO_PINNED_VERSION}{go-version: \${{ matrix.go-version }}}; | |||||||||||||||||||||||||||||||||||||
| 489 | 2 | $yaml = _insert_matrix($yaml, 'go-version', $versions); | |||||||||||||||||||||||||||||||||||||
| 490 | } elsif ($type eq 'rust') { | ||||||||||||||||||||||||||||||||||||||
| 491 | # dtolnay/rust-toolchain reads the toolchain from "with:" when the | ||||||||||||||||||||||||||||||||||||||
| 492 | # ref is not a version, so point it at the matrix value | ||||||||||||||||||||||||||||||||||||||
| 493 | 2 | $yaml =~ s{$RUST_TOOLCHAIN_STEP}{$1 with:\n toolchain: \${{ matrix.rust-version }}\n}; | |||||||||||||||||||||||||||||||||||||
| 494 | 2 | $yaml = _insert_matrix($yaml, 'rust-version', $versions); | |||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||
| 497 | 23 | return $yaml; | |||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||
| 500 | # Purpose: Add a one-key strategy matrix to the (single) ubuntu job. | ||||||||||||||||||||||||||||||||||||||
| 501 | # Entry: $yaml has exactly one " runs-on: ubuntu-latest" line. | ||||||||||||||||||||||||||||||||||||||
| 502 | # Exit status: Returns the YAML with the matrix inserted after that line. | ||||||||||||||||||||||||||||||||||||||
| 503 | # Side effects: None. | ||||||||||||||||||||||||||||||||||||||
| 504 | 4 | ▶ | sub _insert_matrix($yaml, $key, $versions) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_matrix: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 505 | 4 | my $block = " strategy:\n matrix:\n $key:\n" | |||||||||||||||||||||||||||||||||||||
| 506 | . _matrix_items(' ', $versions); | ||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||
| 508 | 4 | $yaml =~ s{^( runs-on: ubuntu-latest\n)}{$1$block}m; | |||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||
| 510 | 4 | return $yaml; | |||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||
| 513 | =head2 list_workflow_types() | ||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||
| 515 | Return a flat hash of all supported workflow types and their descriptions. | ||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||
| 517 | =head3 Purpose | ||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||
| 519 | Enumerate every type that C<generate_workflow> can handle, with a one-line | ||||||||||||||||||||||||||||||||||||||
| 520 | human-readable description for each. | ||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||
| 522 | =head3 Arguments | ||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||
| 524 | None. | ||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||
| 526 | =head3 Returns | ||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||
| 528 | A flat hash (not a reference) mapping type strings to description strings. | ||||||||||||||||||||||||||||||||||||||
| 529 | Contains exactly eleven entries: C<perl>, C<node>, C<python>, C<rust>, | ||||||||||||||||||||||||||||||||||||||
| 530 | C<go>, C<ruby>, C<java>, C<cpp>, C<php>, C<docker>, C<static>. | ||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||
| 532 | =head3 Side Effects | ||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||
| 534 | None. Pure function. | ||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||
| 536 | =head3 Usage Example | ||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||
| 538 | my %types = list_workflow_types(); | ||||||||||||||||||||||||||||||||||||||
| 539 | say "$_: $types{$_}" for sort keys %types; | ||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||
| 541 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||
| 543 | =head4 Input | ||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||
| 545 | # No parameters. | ||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||
| 547 | =head4 Output | ||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||
| 549 | { type => 'hashref', keys => { '*' => { type => 'scalar' } } } | ||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||
| 551 | =head3 FORMAL SPECIFICATION | ||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||
| 553 | list_workflow_types : → ℤ* → ℤ* | ||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||
| 555 | result ≔ { t ↦ desc(t) ∣ t ∈ SupportedTypes } | ||||||||||||||||||||||||||||||||||||||
| 556 | |result| = 11 | ||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||
| 558 | =cut | ||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||
| 560 | 4 | ▶ | sub list_workflow_types() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
list_workflow_types: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 561 | return ( | ||||||||||||||||||||||||||||||||||||||
| 562 | 4 | node => 'Node.js/npm projects with testing and linting', | |||||||||||||||||||||||||||||||||||||
| 563 | python => 'Python projects with pytest and coverage', | ||||||||||||||||||||||||||||||||||||||
| 564 | rust => 'Rust projects with cargo, clippy, and formatting', | ||||||||||||||||||||||||||||||||||||||
| 565 | go => 'Go projects with testing and race detection', | ||||||||||||||||||||||||||||||||||||||
| 566 | ruby => 'Ruby projects with bundler and rake', | ||||||||||||||||||||||||||||||||||||||
| 567 | perl => 'Perl projects with cpanm, prove, and coverage', | ||||||||||||||||||||||||||||||||||||||
| 568 | java => 'Java projects with Maven or Gradle', | ||||||||||||||||||||||||||||||||||||||
| 569 | cpp => 'C++ projects with CMake', | ||||||||||||||||||||||||||||||||||||||
| 570 | php => 'PHP projects with Composer and PHPUnit', | ||||||||||||||||||||||||||||||||||||||
| 571 | docker => 'Docker image build and push workflow', | ||||||||||||||||||||||||||||||||||||||
| 572 | static => 'Static site deployment to GitHub Pages', | ||||||||||||||||||||||||||||||||||||||
| 573 | ); | ||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||
| 576 | # Private workflow generators | ||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||
| 578 | 5 | ▶ | sub _generate_perl_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_perl_workflow: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||
| 579 | # Try to detect requirements from project | ||||||||||||||||||||||||||||||||||||||
| 580 | 5 | my $reqs = detect_perl_requirements(); | |||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||
| 582 | # Use detected min version or default to 5.36 | ||||||||||||||||||||||||||||||||||||||
| 583 | 5 | ▶ | my $min_version = $reqs->{min_version} // '5.36'; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$reqs->{"min_version"} // "5.36"
MC/DC0%0/1
$reqs->{"min_version"} // "5.36"
$reqs->{"min_version"}
Truth table50%1/2
A
A= $reqs->{"min_version"}
| |||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||
| 585 | # Generate custom workflow with detected settings | ||||||||||||||||||||||||||||||||||||||
| 586 | 5 | return generate_custom_perl_workflow({ | |||||||||||||||||||||||||||||||||||||
| 587 | min_perl_version => $min_version, | ||||||||||||||||||||||||||||||||||||||
| 588 | max_perl_version => '5.40', | ||||||||||||||||||||||||||||||||||||||
| 589 | os => ['macos-latest', 'ubuntu-latest', 'windows-latest'], | ||||||||||||||||||||||||||||||||||||||
| 590 | enable_critic => 1, | ||||||||||||||||||||||||||||||||||||||
| 591 | enable_coverage => 1, | ||||||||||||||||||||||||||||||||||||||
| 592 | }); | ||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||
| 595 | 9 | ▶ | sub _generate_node_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_node_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 596 | 9 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 597 | --- | ||||||||||||||||||||||||||||||||||||||
| 598 | name: Node.js CI | ||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||
| 600 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 601 | push: | ||||||||||||||||||||||||||||||||||||||
| 602 | branches: | ||||||||||||||||||||||||||||||||||||||
| 603 | - main | ||||||||||||||||||||||||||||||||||||||
| 604 | - develop | ||||||||||||||||||||||||||||||||||||||
| 605 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 606 | branches: | ||||||||||||||||||||||||||||||||||||||
| 607 | - main | ||||||||||||||||||||||||||||||||||||||
| 608 | - develop | ||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||
| 610 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 611 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 612 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||
| 614 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 615 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||
| 617 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 618 | test: | ||||||||||||||||||||||||||||||||||||||
| 619 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 620 | strategy: | ||||||||||||||||||||||||||||||||||||||
| 621 | matrix: | ||||||||||||||||||||||||||||||||||||||
| 622 | node-version: | ||||||||||||||||||||||||||||||||||||||
| 623 | - 18.x | ||||||||||||||||||||||||||||||||||||||
| 624 | - 20.x | ||||||||||||||||||||||||||||||||||||||
| 625 | - 22.x | ||||||||||||||||||||||||||||||||||||||
| 626 | steps: | ||||||||||||||||||||||||||||||||||||||
| 627 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 628 | uses: actions/checkout@76 | ||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||
| 630 | - name: Setup Node.js ${{ matrix.node-version }} | ||||||||||||||||||||||||||||||||||||||
| 631 | uses: actions/setup-node@v4 | ||||||||||||||||||||||||||||||||||||||
| 632 | with: | ||||||||||||||||||||||||||||||||||||||
| 633 | node-version: ${{ matrix.node-version }} | ||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||
| 635 | - name: Cache dependencies | ||||||||||||||||||||||||||||||||||||||
| 636 | uses: actions/cache@v6 | ||||||||||||||||||||||||||||||||||||||
| 637 | with: | ||||||||||||||||||||||||||||||||||||||
| 638 | path: ~/.npm | ||||||||||||||||||||||||||||||||||||||
| 639 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||||||||||||||||||||||||||||||||||||||
| 640 | restore-keys: | | ||||||||||||||||||||||||||||||||||||||
| 641 | ${{ runner.os }}-node- | ||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||
| 643 | - name: Install dependencies | ||||||||||||||||||||||||||||||||||||||
| 644 | run: npm ci | ||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||
| 646 | - name: Run linter | ||||||||||||||||||||||||||||||||||||||
| 647 | run: npm run lint --if-present | ||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||
| 649 | - name: Run tests | ||||||||||||||||||||||||||||||||||||||
| 650 | run: npm test | ||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||
| 652 | - name: Build project | ||||||||||||||||||||||||||||||||||||||
| 653 | run: npm run build --if-present | ||||||||||||||||||||||||||||||||||||||
| 654 | YAML | ||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||
| 657 | 11 | ▶ | sub _generate_python_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_python_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 658 | 11 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 659 | --- | ||||||||||||||||||||||||||||||||||||||
| 660 | name: Python CI | ||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||
| 662 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 663 | push: | ||||||||||||||||||||||||||||||||||||||
| 664 | branches: | ||||||||||||||||||||||||||||||||||||||
| 665 | - main | ||||||||||||||||||||||||||||||||||||||
| 666 | - develop | ||||||||||||||||||||||||||||||||||||||
| 667 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 668 | branches: | ||||||||||||||||||||||||||||||||||||||
| 669 | - main | ||||||||||||||||||||||||||||||||||||||
| 670 | - develop | ||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||
| 672 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 673 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 674 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||
| 676 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 677 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||
| 679 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 680 | test: | ||||||||||||||||||||||||||||||||||||||
| 681 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 682 | strategy: | ||||||||||||||||||||||||||||||||||||||
| 683 | matrix: | ||||||||||||||||||||||||||||||||||||||
| 684 | python-version: | ||||||||||||||||||||||||||||||||||||||
| 685 | - '3.9' | ||||||||||||||||||||||||||||||||||||||
| 686 | - '3.10' | ||||||||||||||||||||||||||||||||||||||
| 687 | - '3.11' | ||||||||||||||||||||||||||||||||||||||
| 688 | - '3.12' | ||||||||||||||||||||||||||||||||||||||
| 689 | steps: | ||||||||||||||||||||||||||||||||||||||
| 690 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 691 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||
| 693 | - name: Set up Python ${{ matrix.python-version }} | ||||||||||||||||||||||||||||||||||||||
| 694 | uses: actions/setup-python@v5 | ||||||||||||||||||||||||||||||||||||||
| 695 | with: | ||||||||||||||||||||||||||||||||||||||
| 696 | python-version: ${{ matrix.python-version }} | ||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||
| 698 | - name: Cache pip packages | ||||||||||||||||||||||||||||||||||||||
| 699 | uses: actions/cache@v6 | ||||||||||||||||||||||||||||||||||||||
| 700 | with: | ||||||||||||||||||||||||||||||||||||||
| 701 | path: ~/.cache/pip | ||||||||||||||||||||||||||||||||||||||
| 702 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||||||||||||||||||||||||||||||||||||||
| 703 | restore-keys: | | ||||||||||||||||||||||||||||||||||||||
| 704 | ${{ runner.os }}-pip- | ||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||
| 706 | - name: Install dependencies | ||||||||||||||||||||||||||||||||||||||
| 707 | run: | | ||||||||||||||||||||||||||||||||||||||
| 708 | pip install -r requirements.txt | ||||||||||||||||||||||||||||||||||||||
| 709 | pip install pytest pytest-cov flake8 | ||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||
| 711 | - name: Lint with flake8 | ||||||||||||||||||||||||||||||||||||||
| 712 | run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||
| 714 | - name: Run tests with coverage | ||||||||||||||||||||||||||||||||||||||
| 715 | run: pytest --cov=. --cov-report=xml | ||||||||||||||||||||||||||||||||||||||
| 716 | YAML | ||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||
| 719 | 6 | ▶ | sub _generate_rust_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_rust_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 720 | 6 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 721 | --- | ||||||||||||||||||||||||||||||||||||||
| 722 | name: Rust CI | ||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||
| 724 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 725 | push: | ||||||||||||||||||||||||||||||||||||||
| 726 | branches: | ||||||||||||||||||||||||||||||||||||||
| 727 | - main | ||||||||||||||||||||||||||||||||||||||
| 728 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 729 | branches: | ||||||||||||||||||||||||||||||||||||||
| 730 | - main | ||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||
| 732 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 733 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 734 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||
| 736 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 737 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||
| 739 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 740 | test: | ||||||||||||||||||||||||||||||||||||||
| 741 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 742 | steps: | ||||||||||||||||||||||||||||||||||||||
| 743 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 744 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||
| 746 | - name: Setup Rust | ||||||||||||||||||||||||||||||||||||||
| 747 | uses: dtolnay/rust-toolchain@stable | ||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||
| 749 | - name: Cache cargo | ||||||||||||||||||||||||||||||||||||||
| 750 | uses: actions/cache@v6 | ||||||||||||||||||||||||||||||||||||||
| 751 | with: | ||||||||||||||||||||||||||||||||||||||
| 752 | path: | | ||||||||||||||||||||||||||||||||||||||
| 753 | ~/.cargo/bin/ | ||||||||||||||||||||||||||||||||||||||
| 754 | ~/.cargo/registry/index/ | ||||||||||||||||||||||||||||||||||||||
| 755 | ~/.cargo/registry/cache/ | ||||||||||||||||||||||||||||||||||||||
| 756 | ~/.cargo/git/db/ | ||||||||||||||||||||||||||||||||||||||
| 757 | target/ | ||||||||||||||||||||||||||||||||||||||
| 758 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||
| 760 | - name: Check formatting | ||||||||||||||||||||||||||||||||||||||
| 761 | run: cargo fmt -- --check | ||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||
| 763 | - name: Run clippy | ||||||||||||||||||||||||||||||||||||||
| 764 | run: cargo clippy -- -D warnings | ||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||
| 766 | - name: Run tests | ||||||||||||||||||||||||||||||||||||||
| 767 | run: cargo test --verbose | ||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||
| 769 | - name: Build release | ||||||||||||||||||||||||||||||||||||||
| 770 | run: cargo build --release --verbose | ||||||||||||||||||||||||||||||||||||||
| 771 | YAML | ||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||
| 774 | 6 | ▶ | sub _generate_go_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_go_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 775 | 6 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 776 | --- | ||||||||||||||||||||||||||||||||||||||
| 777 | name: Go CI | ||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||
| 779 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 780 | push: | ||||||||||||||||||||||||||||||||||||||
| 781 | branches: | ||||||||||||||||||||||||||||||||||||||
| 782 | - main | ||||||||||||||||||||||||||||||||||||||
| 783 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 784 | branches: | ||||||||||||||||||||||||||||||||||||||
| 785 | - main | ||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||
| 787 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 788 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 789 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||
| 791 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 792 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||
| 794 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 795 | test: | ||||||||||||||||||||||||||||||||||||||
| 796 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 797 | steps: | ||||||||||||||||||||||||||||||||||||||
| 798 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 799 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||
| 801 | - name: Setup Go | ||||||||||||||||||||||||||||||||||||||
| 802 | uses: actions/setup-go@v5 | ||||||||||||||||||||||||||||||||||||||
| 803 | with: | ||||||||||||||||||||||||||||||||||||||
| 804 | go-version: '1.22' | ||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||
| 806 | - name: Cache Go modules | ||||||||||||||||||||||||||||||||||||||
| 807 | uses: actions/cache@v6 | ||||||||||||||||||||||||||||||||||||||
| 808 | with: | ||||||||||||||||||||||||||||||||||||||
| 809 | path: ~/go/pkg/mod | ||||||||||||||||||||||||||||||||||||||
| 810 | key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||||||||||||||||||||||||||||||||||||||
| 811 | restore-keys: | | ||||||||||||||||||||||||||||||||||||||
| 812 | ${{ runner.os }}-go- | ||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||
| 814 | - name: Download dependencies | ||||||||||||||||||||||||||||||||||||||
| 815 | run: go mod download | ||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||
| 817 | - name: Run go vet | ||||||||||||||||||||||||||||||||||||||
| 818 | run: go vet ./... | ||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||
| 820 | - name: Run tests | ||||||||||||||||||||||||||||||||||||||
| 821 | run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... | ||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||
| 823 | - name: Build | ||||||||||||||||||||||||||||||||||||||
| 824 | run: go build -v ./... | ||||||||||||||||||||||||||||||||||||||
| 825 | YAML | ||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||
| 828 | 6 | ▶ | sub _generate_ruby_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_ruby_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 829 | 6 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 830 | --- | ||||||||||||||||||||||||||||||||||||||
| 831 | name: Ruby CI | ||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||
| 833 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 834 | push: | ||||||||||||||||||||||||||||||||||||||
| 835 | branches: | ||||||||||||||||||||||||||||||||||||||
| 836 | - main | ||||||||||||||||||||||||||||||||||||||
| 837 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 838 | branches: | ||||||||||||||||||||||||||||||||||||||
| 839 | - main | ||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||
| 841 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 842 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 843 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||
| 845 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 846 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||
| 848 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 849 | test: | ||||||||||||||||||||||||||||||||||||||
| 850 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 851 | strategy: | ||||||||||||||||||||||||||||||||||||||
| 852 | matrix: | ||||||||||||||||||||||||||||||||||||||
| 853 | ruby-version: | ||||||||||||||||||||||||||||||||||||||
| 854 | - '3.1' | ||||||||||||||||||||||||||||||||||||||
| 855 | - '3.2' | ||||||||||||||||||||||||||||||||||||||
| 856 | - '3.3' | ||||||||||||||||||||||||||||||||||||||
| 857 | steps: | ||||||||||||||||||||||||||||||||||||||
| 858 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 859 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||
| 861 | - name: Set up Ruby | ||||||||||||||||||||||||||||||||||||||
| 862 | uses: ruby/setup-ruby@v1 | ||||||||||||||||||||||||||||||||||||||
| 863 | with: | ||||||||||||||||||||||||||||||||||||||
| 864 | ruby-version: ${{ matrix.ruby-version }} | ||||||||||||||||||||||||||||||||||||||
| 865 | bundler-cache: true | ||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||
| 867 | - name: Run tests | ||||||||||||||||||||||||||||||||||||||
| 868 | run: bundle exec rake test | ||||||||||||||||||||||||||||||||||||||
| 869 | YAML | ||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||
| 872 | 6 | ▶ | sub _generate_docker_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_docker_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 873 | 6 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 874 | --- | ||||||||||||||||||||||||||||||||||||||
| 875 | name: Docker Build | ||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||
| 877 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 878 | push: | ||||||||||||||||||||||||||||||||||||||
| 879 | branches: | ||||||||||||||||||||||||||||||||||||||
| 880 | - main | ||||||||||||||||||||||||||||||||||||||
| 881 | tags: | ||||||||||||||||||||||||||||||||||||||
| 882 | - v* | ||||||||||||||||||||||||||||||||||||||
| 883 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 884 | branches: | ||||||||||||||||||||||||||||||||||||||
| 885 | - main | ||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||
| 887 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 888 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 889 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||
| 891 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 892 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 893 | packages: write | ||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||
| 895 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 896 | build: | ||||||||||||||||||||||||||||||||||||||
| 897 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 898 | steps: | ||||||||||||||||||||||||||||||||||||||
| 899 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 900 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||
| 902 | - name: Set up Docker Buildx | ||||||||||||||||||||||||||||||||||||||
| 903 | uses: docker/setup-buildx-action@v3 | ||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||
| 905 | - name: Log in to Docker Hub | ||||||||||||||||||||||||||||||||||||||
| 906 | uses: docker/login-action@v3 | ||||||||||||||||||||||||||||||||||||||
| 907 | with: | ||||||||||||||||||||||||||||||||||||||
| 908 | username: ${{ secrets.DOCKER_USERNAME }} | ||||||||||||||||||||||||||||||||||||||
| 909 | password: ${{ secrets.DOCKER_PASSWORD }} | ||||||||||||||||||||||||||||||||||||||
| 910 | if: github.event_name != 'pull_request' | ||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||
| 912 | - name: Extract metadata | ||||||||||||||||||||||||||||||||||||||
| 913 | id: meta | ||||||||||||||||||||||||||||||||||||||
| 914 | uses: docker/metadata-action@v5 | ||||||||||||||||||||||||||||||||||||||
| 915 | with: | ||||||||||||||||||||||||||||||||||||||
| 916 | images: your-username/your-image | ||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||
| 918 | - name: Build and push | ||||||||||||||||||||||||||||||||||||||
| 919 | uses: docker/build-push-action@v5 | ||||||||||||||||||||||||||||||||||||||
| 920 | with: | ||||||||||||||||||||||||||||||||||||||
| 921 | context: . | ||||||||||||||||||||||||||||||||||||||
| 922 | push: ${{ github.event_name != 'pull_request' }} | ||||||||||||||||||||||||||||||||||||||
| 923 | tags: ${{ steps.meta.outputs.tags }} | ||||||||||||||||||||||||||||||||||||||
| 924 | labels: ${{ steps.meta.outputs.labels }} | ||||||||||||||||||||||||||||||||||||||
| 925 | cache-from: type=gha | ||||||||||||||||||||||||||||||||||||||
| 926 | cache-to: type=gha,mode=max | ||||||||||||||||||||||||||||||||||||||
| 927 | YAML | ||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||
| 930 | 6 | ▶ | sub _generate_static_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_static_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 931 | 6 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 932 | --- | ||||||||||||||||||||||||||||||||||||||
| 933 | name: Deploy Static Site | ||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||
| 935 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 936 | push: | ||||||||||||||||||||||||||||||||||||||
| 937 | branches: | ||||||||||||||||||||||||||||||||||||||
| 938 | - main | ||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||
| 940 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 941 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 942 | pages: write | ||||||||||||||||||||||||||||||||||||||
| 943 | id-token: write | ||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||
| 945 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 946 | group: pages | ||||||||||||||||||||||||||||||||||||||
| 947 | cancel-in-progress: false | ||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||
| 949 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 950 | build: | ||||||||||||||||||||||||||||||||||||||
| 951 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 952 | steps: | ||||||||||||||||||||||||||||||||||||||
| 953 | - name: Checkout | ||||||||||||||||||||||||||||||||||||||
| 954 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||
| 956 | - name: Setup Pages | ||||||||||||||||||||||||||||||||||||||
| 957 | uses: actions/configure-pages@v4 | ||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||
| 959 | - name: Build | ||||||||||||||||||||||||||||||||||||||
| 960 | run: echo "Add your build command here" | ||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||
| 962 | - name: Upload artifact | ||||||||||||||||||||||||||||||||||||||
| 963 | uses: actions/upload-pages-artifact@v3 | ||||||||||||||||||||||||||||||||||||||
| 964 | with: | ||||||||||||||||||||||||||||||||||||||
| 965 | path: ./public | ||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||
| 967 | deploy: | ||||||||||||||||||||||||||||||||||||||
| 968 | environment: | ||||||||||||||||||||||||||||||||||||||
| 969 | name: github-pages | ||||||||||||||||||||||||||||||||||||||
| 970 | url: ${{ steps.deployment.outputs.page_url }} | ||||||||||||||||||||||||||||||||||||||
| 971 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 972 | needs: build | ||||||||||||||||||||||||||||||||||||||
| 973 | steps: | ||||||||||||||||||||||||||||||||||||||
| 974 | - name: Deploy to GitHub Pages | ||||||||||||||||||||||||||||||||||||||
| 975 | id: deployment | ||||||||||||||||||||||||||||||||||||||
| 976 | uses: actions/deploy-pages@v4 | ||||||||||||||||||||||||||||||||||||||
| 977 | YAML | ||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||
| 980 | 6 | ▶ | sub _generate_java_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_java_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 981 | 6 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 982 | --- | ||||||||||||||||||||||||||||||||||||||
| 983 | name: Java CI | ||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||
| 985 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 986 | push: | ||||||||||||||||||||||||||||||||||||||
| 987 | branches: | ||||||||||||||||||||||||||||||||||||||
| 988 | - main | ||||||||||||||||||||||||||||||||||||||
| 989 | - develop | ||||||||||||||||||||||||||||||||||||||
| 990 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 991 | branches: | ||||||||||||||||||||||||||||||||||||||
| 992 | - main | ||||||||||||||||||||||||||||||||||||||
| 993 | - develop | ||||||||||||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||||||||||||
| 995 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 996 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 997 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||
| 999 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 1000 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||
| 1002 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 1003 | test: | ||||||||||||||||||||||||||||||||||||||
| 1004 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 1005 | strategy: | ||||||||||||||||||||||||||||||||||||||
| 1006 | matrix: | ||||||||||||||||||||||||||||||||||||||
| 1007 | java-version: | ||||||||||||||||||||||||||||||||||||||
| 1008 | - '11' | ||||||||||||||||||||||||||||||||||||||
| 1009 | - '17' | ||||||||||||||||||||||||||||||||||||||
| 1010 | - '21' | ||||||||||||||||||||||||||||||||||||||
| 1011 | steps: | ||||||||||||||||||||||||||||||||||||||
| 1012 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 1013 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||
| 1015 | - name: Set up JDK ${{ matrix.java-version }} | ||||||||||||||||||||||||||||||||||||||
| 1016 | uses: actions/setup-java@v4 | ||||||||||||||||||||||||||||||||||||||
| 1017 | with: | ||||||||||||||||||||||||||||||||||||||
| 1018 | java-version: ${{ matrix.java-version }} | ||||||||||||||||||||||||||||||||||||||
| 1019 | distribution: 'temurin' | ||||||||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||||||||
| 1021 | - name: Cache Maven packages | ||||||||||||||||||||||||||||||||||||||
| 1022 | uses: actions/cache@v6 | ||||||||||||||||||||||||||||||||||||||
| 1023 | with: | ||||||||||||||||||||||||||||||||||||||
| 1024 | path: ~/.m2/repository | ||||||||||||||||||||||||||||||||||||||
| 1025 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||||||||||||||||||||||||||||||||||||||
| 1026 | restore-keys: | | ||||||||||||||||||||||||||||||||||||||
| 1027 | ${{ runner.os }}-maven- | ||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||
| 1029 | - name: Build with Maven | ||||||||||||||||||||||||||||||||||||||
| 1030 | run: mvn -B package --file pom.xml | ||||||||||||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||||||||||||
| 1032 | - name: Run tests | ||||||||||||||||||||||||||||||||||||||
| 1033 | run: mvn -B test | ||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||
| 1035 | - name: Generate test report | ||||||||||||||||||||||||||||||||||||||
| 1036 | if: always() | ||||||||||||||||||||||||||||||||||||||
| 1037 | run: mvn surefire-report:report | ||||||||||||||||||||||||||||||||||||||
| 1038 | YAML | ||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||
| 1041 | 6 | ▶ | sub _generate_cpp_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_cpp_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 1042 | 6 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 1043 | --- | ||||||||||||||||||||||||||||||||||||||
| 1044 | name: C++ CI | ||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||
| 1046 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 1047 | push: | ||||||||||||||||||||||||||||||||||||||
| 1048 | branches: | ||||||||||||||||||||||||||||||||||||||
| 1049 | - main | ||||||||||||||||||||||||||||||||||||||
| 1050 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 1051 | branches: | ||||||||||||||||||||||||||||||||||||||
| 1052 | - main | ||||||||||||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||||||||||||
| 1054 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 1055 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 1056 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||
| 1058 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 1059 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||
| 1061 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 1062 | test: | ||||||||||||||||||||||||||||||||||||||
| 1063 | runs-on: ${{ matrix.os }} | ||||||||||||||||||||||||||||||||||||||
| 1064 | strategy: | ||||||||||||||||||||||||||||||||||||||
| 1065 | matrix: | ||||||||||||||||||||||||||||||||||||||
| 1066 | os: | ||||||||||||||||||||||||||||||||||||||
| 1067 | - ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 1068 | - macos-latest | ||||||||||||||||||||||||||||||||||||||
| 1069 | - windows-latest | ||||||||||||||||||||||||||||||||||||||
| 1070 | build-type: | ||||||||||||||||||||||||||||||||||||||
| 1071 | - Debug | ||||||||||||||||||||||||||||||||||||||
| 1072 | - Release | ||||||||||||||||||||||||||||||||||||||
| 1073 | steps: | ||||||||||||||||||||||||||||||||||||||
| 1074 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 1075 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||
| 1077 | - name: Install CMake | ||||||||||||||||||||||||||||||||||||||
| 1078 | uses: lukka/get-cmake@latest | ||||||||||||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||||||||||||
| 1080 | - name: Cache build artifacts | ||||||||||||||||||||||||||||||||||||||
| 1081 | uses: actions/cache@v6 | ||||||||||||||||||||||||||||||||||||||
| 1082 | with: | ||||||||||||||||||||||||||||||||||||||
| 1083 | path: | | ||||||||||||||||||||||||||||||||||||||
| 1084 | build | ||||||||||||||||||||||||||||||||||||||
| 1085 | ~/.cache/ccache | ||||||||||||||||||||||||||||||||||||||
| 1086 | key: ${{ runner.os }}-${{ matrix.build-type }}-${{ hashFiles('**/CMakeLists.txt') }} | ||||||||||||||||||||||||||||||||||||||
| 1087 | |||||||||||||||||||||||||||||||||||||||
| 1088 | - name: Configure CMake | ||||||||||||||||||||||||||||||||||||||
| 1089 | run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} | ||||||||||||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||||||||||||
| 1091 | - name: Build | ||||||||||||||||||||||||||||||||||||||
| 1092 | run: cmake --build build --config ${{ matrix.build-type }} | ||||||||||||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||||||||||||
| 1094 | - name: Run tests | ||||||||||||||||||||||||||||||||||||||
| 1095 | working-directory: build | ||||||||||||||||||||||||||||||||||||||
| 1096 | run: ctest -C ${{ matrix.build-type }} --output-on-failure | ||||||||||||||||||||||||||||||||||||||
| 1097 | YAML | ||||||||||||||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||||||||||||
| 1099 | |||||||||||||||||||||||||||||||||||||||
| 1100 | 6 | ▶ | sub _generate_php_workflow() { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_php_workflow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 1101 | 6 | return <<'YAML'; | |||||||||||||||||||||||||||||||||||||
| 1102 | --- | ||||||||||||||||||||||||||||||||||||||
| 1103 | name: PHP CI | ||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||
| 1105 | 'on': | ||||||||||||||||||||||||||||||||||||||
| 1106 | push: | ||||||||||||||||||||||||||||||||||||||
| 1107 | branches: | ||||||||||||||||||||||||||||||||||||||
| 1108 | - main | ||||||||||||||||||||||||||||||||||||||
| 1109 | - develop | ||||||||||||||||||||||||||||||||||||||
| 1110 | pull_request: | ||||||||||||||||||||||||||||||||||||||
| 1111 | branches: | ||||||||||||||||||||||||||||||||||||||
| 1112 | - main | ||||||||||||||||||||||||||||||||||||||
| 1113 | - develop | ||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||
| 1115 | concurrency: | ||||||||||||||||||||||||||||||||||||||
| 1116 | group: ${{ github.workflow }}-${{ github.ref }} | ||||||||||||||||||||||||||||||||||||||
| 1117 | cancel-in-progress: true | ||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||
| 1119 | permissions: | ||||||||||||||||||||||||||||||||||||||
| 1120 | contents: read | ||||||||||||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||||||||||||
| 1122 | jobs: | ||||||||||||||||||||||||||||||||||||||
| 1123 | test: | ||||||||||||||||||||||||||||||||||||||
| 1124 | runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| 1125 | strategy: | ||||||||||||||||||||||||||||||||||||||
| 1126 | matrix: | ||||||||||||||||||||||||||||||||||||||
| 1127 | php-version: | ||||||||||||||||||||||||||||||||||||||
| 1128 | - '8.1' | ||||||||||||||||||||||||||||||||||||||
| 1129 | - '8.2' | ||||||||||||||||||||||||||||||||||||||
| 1130 | - '8.3' | ||||||||||||||||||||||||||||||||||||||
| 1131 | steps: | ||||||||||||||||||||||||||||||||||||||
| 1132 | - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| 1133 | uses: actions/checkout@v7 | ||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||
| 1135 | - name: Setup PHP ${{ matrix.php-version }} | ||||||||||||||||||||||||||||||||||||||
| 1136 | uses: shivammathur/setup-php@v2 | ||||||||||||||||||||||||||||||||||||||
| 1137 | with: | ||||||||||||||||||||||||||||||||||||||
| 1138 | php-version: ${{ matrix.php-version }} | ||||||||||||||||||||||||||||||||||||||
| 1139 | extensions: mbstring, xml, ctype, json | ||||||||||||||||||||||||||||||||||||||
| 1140 | coverage: xdebug | ||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||
| 1142 | - name: Validate composer.json | ||||||||||||||||||||||||||||||||||||||
| 1143 | run: composer validate --strict | ||||||||||||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||||||||||||
| 1145 | - name: Cache Composer packages | ||||||||||||||||||||||||||||||||||||||
| 1146 | uses: actions/cache@v6 | ||||||||||||||||||||||||||||||||||||||
| 1147 | with: | ||||||||||||||||||||||||||||||||||||||
| 1148 | path: vendor | ||||||||||||||||||||||||||||||||||||||
| 1149 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} | ||||||||||||||||||||||||||||||||||||||
| 1150 | restore-keys: | | ||||||||||||||||||||||||||||||||||||||
| 1151 | ${{ runner.os }}-php- | ||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||
| 1153 | - name: Install dependencies | ||||||||||||||||||||||||||||||||||||||
| 1154 | run: composer install --prefer-dist --no-progress | ||||||||||||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||||||||||||
| 1156 | - name: Run PHPUnit tests | ||||||||||||||||||||||||||||||||||||||
| 1157 | run: vendor/bin/phpunit --coverage-text | ||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||
| 1159 | - name: Run PHP CodeSniffer | ||||||||||||||||||||||||||||||||||||||
| 1160 | run: vendor/bin/phpcs --standard=PSR12 src tests | ||||||||||||||||||||||||||||||||||||||
| 1161 | continue-on-error: true | ||||||||||||||||||||||||||||||||||||||
| 1162 | YAML | ||||||||||||||||||||||||||||||||||||||
| 1163 | } | ||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||
| 1165 | =head1 LIMITATIONS | ||||||||||||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||||||||||||
| 1167 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||
| 1169 | =item * Workflows are text templates, not data | ||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||
| 1171 | Every generator except C<perl> is a heredoc, and C<--versions> works by | ||||||||||||||||||||||||||||||||||||||
| 1172 | regex-rewriting that text. It is tied to the exact layout of each template | ||||||||||||||||||||||||||||||||||||||
| 1173 | (indentation, the C<ubuntu-latest> job line, the pinned Go and Rust lines) | ||||||||||||||||||||||||||||||||||||||
| 1174 | and a template edit can silently stop it matching. Building each workflow as | ||||||||||||||||||||||||||||||||||||||
| 1175 | a Perl data structure and serialising it with L<YAML::XS> would remove the | ||||||||||||||||||||||||||||||||||||||
| 1176 | whole class of problem; that is a rewrite of every generator, so it is not | ||||||||||||||||||||||||||||||||||||||
| 1177 | done here. The tests in F<t/versions_option.t> parse the output as YAML to | ||||||||||||||||||||||||||||||||||||||
| 1178 | catch a broken rewrite. | ||||||||||||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||||||||||||
| 1180 | =item * Default versions are fixed in the templates | ||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||
| 1182 | The defaults are not validated against what the setup actions support today, | ||||||||||||||||||||||||||||||||||||||
| 1183 | and some are end of life (node 18, python 3.9, ruby 3.1). They are kept so | ||||||||||||||||||||||||||||||||||||||
| 1184 | existing output does not change. | ||||||||||||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||||||||||||
| 1186 | =item * One version list per run | ||||||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||||||
| 1188 | C<--versions> applies to the single generated type. There is no way to give | ||||||||||||||||||||||||||||||||||||||
| 1189 | different lists to different jobs in one workflow. | ||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||
| 1191 | =item * Messages are sprintf formats only | ||||||||||||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||||||||||||
| 1193 | C<%MESSAGES> can be reworded or translated by replacing its values, but there | ||||||||||||||||||||||||||||||||||||||
| 1194 | is no plural or grammatical-gender handling, and the table is a package | ||||||||||||||||||||||||||||||||||||||
| 1195 | global rather than per-object configuration. The messages here take only | ||||||||||||||||||||||||||||||||||||||
| 1196 | strings, so none is needed yet. | ||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||
| 1198 | =item * Version tokens are checked for safety, not meaning | ||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||
| 1200 | C<9.9.9> is accepted for any language. Whether the setup action can install | ||||||||||||||||||||||||||||||||||||||
| 1201 | it is only discovered when the workflow runs. | ||||||||||||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||||||||||||
| 1203 | =item * Perl ignores project detection when versions are given | ||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||
| 1205 | C<generate_workflow('perl', { versions => ... })> uses exactly the list given; | ||||||||||||||||||||||||||||||||||||||
| 1206 | the minimum Perl detected from F<cpanfile> or F<Makefile.PL> is not applied. | ||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||
| 1208 | =back | ||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||
| 1210 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||
| 1212 | Nigel Horne E<lt>njh@nigelhorne.comE<gt> | ||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||
| 1214 | L<https://github.com/nigelhorne> | ||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||
| 1216 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||
| 1218 | Copyright 2025-2026 Nigel Horne. | ||||||||||||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||||||||||||
| 1220 | Usage is subject to the GPL2 licence terms. | ||||||||||||||||||||||||||||||||||||||
| 1221 | If you use it, | ||||||||||||||||||||||||||||||||||||||
| 1222 | please let me know. | ||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||
| 1224 | =cut | ||||||||||||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||||||||||||
| 1226 | 64 | 1; | |||||||||||||||||||||||||||||||||||||