NAME
App::GHGen::Generator - Generate GitHub Actions workflows
SYNOPSIS
use App::GHGen::Generator qw(generate_workflow);
use Path::Tiny;
my $yaml = generate_workflow('perl');
path('.github/workflows/ci.yml')->spew_utf8($yaml);
FUNCTIONS
generate_workflow($type, \%opts)
Generate a complete GitHub Actions workflow YAML string for the given project type.
Purpose
Dispatch to the appropriate language-specific workflow generator and return the resulting YAML string ready to be written to a .github/workflows/ file.
Arguments
$type(Str, required)-
A project-type identifier. Supported values:
perl,node,python,rust,go,ruby,java,cpp,php,docker,static. $opts(HashRef, optional)-
versions(ArrayRef of Str)-
Language/runtime versions to test against, replacing the default matrix. Applies to
perl,node,python,ruby,java,php,go(Go Go-versions) andrust(toolchains, e.g.stable,beta,1.80). It is ignored forcpp,dockerandstatic, which have no version matrix. Each entry may contain only letters, digits,.,-,+,*and_; anything else croaks.Defaults when
versionsis not given: perl 5.36, 5.38, 5.40, 5.42; node 18.x, 20.x, 22.x; python 3.9-3.12; ruby 3.1-3.3; java 11, 17, 21; php 8.1-8.3; go 1.22; rust stable.
Returns
A multi-line YAML string beginning with --- when $type is recognised, or undef when the type is not supported.
Side Effects
The perl type without versions reads the current directory to detect project requirements (via App::GHGen::PerlCustomizer). Passing versions for cpp, docker or static emits a carp warning.
Usage
use App::GHGen::Generator qw(generate_workflow);
my $yaml = generate_workflow('node') // die "unsupported type";
path('.github/workflows/ci.yml')->spew_utf8($yaml);
EXAMPLE
# Default matrix
my $default = generate_workflow('python');
# Only test the two newest Pythons
my $custom = generate_workflow('python', { versions => ['3.12', '3.13'] });
# Go pins one version by default; --versions turns it into a matrix
my $go = generate_workflow('go', { versions => ['1.23', '1.24'] });
MESSAGES
Invalid version '%s' for --versions(croak)-
An entry in
versionscontains characters outside[A-Za-z0-9_.+*-]. Remove the offending characters. --versions has no effect for type '%s'(carp)-
versionswas supplied forcpp,dockerorstatic, which have no version matrix. The YAML is returned unchanged; drop the option.
API SPECIFICATION
Input
{
type => { type => 'scalar', required => 1 },
opts => {
type => 'hashref',
optional => 1,
keys => { versions => { type => 'arrayref', optional => 1 } },
},
}
Output
known type -> { type => 'scalar' } # YAML string
unknown type -> undef
FORMAL SPECIFICATION
SupportedTypes ≔ { perl, node, python, rust, go, ruby, java, cpp, php, docker, static }
generate_workflow : ℤ* → ℤ* ∪ { ⊥ }
t ∈ SupportedTypes ∧ versions = ∅ → generators[t]() (default matrix)
t ∈ SupportedTypes ∧ versions ≠ ∅ → rewrite(generators[t](), versions)
t ¬in; SupportedTypes → ⊥ (undef)
∀ v ∈ versions • v ∈ VersionToken (else croak)
PSEUDOCODE
look up the generator for $type; return undef when there is none
when no versions were requested, return the generator's default YAML
validate every requested version (croak on an unsafe one)
warn when the type has no version matrix
perl: regenerate with the explicit version list
node/python/ruby/java/php: replace the existing matrix list
go/rust: replace the pinned version with a matrix reference and
insert a one-key matrix under the job
parse_version_list($text)
Turn a comma-separated --versions string into a validated list of versions.
Purpose
Give the command line and the API one definition of what a version list is, so --versions=5.40, 5.42 means the same thing everywhere.
Arguments
$text(Str, required)-
Comma-separated versions. Whitespace around entries is ignored, empty entries are dropped and duplicates are removed, keeping the first occurrence.
Returns
An array reference of version strings, in the order given.
Side Effects
None.
Usage
my $versions = parse_version_list($ARGV_versions);
my $yaml = generate_workflow('node', { versions => $versions });
EXAMPLE
parse_version_list('20, 22,20'); # ['20', '22']
parse_version_list('5.40,5.42'); # ['5.40', '5.42']
parse_version_list(','); # croaks: needs at least one version
MESSAGES
--versions requires at least one version(croak)-
$textcontained no entries. Supply at least one version. Invalid version '%s' for --versions(croak)-
An entry contains characters outside
[A-Za-z0-9_.+*-].
API SPECIFICATION
Input
{ text => { type => 'scalar', required => 1, min => 1 } }
Output
{ type => 'arrayref', min => 1, element_type => 'scalar' }
FORMAL SPECIFICATION
VersionToken ≔ { s : seq CHAR | s ≠ ⟨⟩ ∧ ran s ⊆ [A-Za-z0-9_.+*-] }
parse_version_list : TEXT ⇸ seq VersionToken
items ≔ nodup(split(',', text) ∖ {⟨⟩})
items ≠ ⟨⟩ ∧ items ⊆ VersionToken ⊢ parse_version_list(text) = items
parse_os_list($text)
Turn a comma-separated --os string into a list of GitHub runner labels.
Purpose
Let users write linux,macos instead of ubuntu-latest,macos-latest, while still accepting a literal label such as ubuntu-22.04.
Arguments
$text(Str, required)-
Comma-separated names, case-insensitive:
linux,ubuntu,macos,windows, or a literal label matching(ubuntu|macos|windows)-....
Returns
An array reference of runner labels, in the order given, without duplicates.
Side Effects
None.
Usage
my $os = parse_os_list('linux,macos'); # no Windows jobs
my $yaml = generate_custom_perl_workflow({ os => $os });
EXAMPLE
parse_os_list('Linux, macOS'); # ['ubuntu-latest', 'macos-latest']
parse_os_list('ubuntu,linux'); # ['ubuntu-latest']
parse_os_list('ubuntu-22.04'); # ['ubuntu-22.04']
parse_os_list('bsd'); # croaks: unknown OS
MESSAGES
Unknown OS '%s' for --os (use linux, macos, windows)(croak)-
The name is neither a known short name nor a literal runner label.
--os requires at least one operating system(croak)-
$textcontained no entries.
API SPECIFICATION
Input
{ text => { type => 'scalar', required => 1, min => 1 } }
Output
{ type => 'arrayref', min => 1, element_type => 'scalar' }
FORMAL SPECIFICATION
Label ≔ { ubuntu-latest, macos-latest, windows-latest } ∪ LiteralLabel
parse_os_list : TEXT ⇸ seq Label
names ≔ split(',', lc text) ∖ {⟨⟩}
labels ≔ nodup(runner ∘ names) (runner is partial; undefined → croak)
labels ≠ ⟨⟩ ⊢ parse_os_list(text) = labels
list_workflow_types()
Return a flat hash of all supported workflow types and their descriptions.
Purpose
Enumerate every type that generate_workflow can handle, with a one-line human-readable description for each.
Arguments
None.
Returns
A flat hash (not a reference) mapping type strings to description strings. Contains exactly eleven entries: perl, node, python, rust, go, ruby, java, cpp, php, docker, static.
Side Effects
None. Pure function.
Usage Example
my %types = list_workflow_types();
say "$_: $types{$_}" for sort keys %types;
API SPECIFICATION
Input
# No parameters.
Output
{ type => 'hashref', keys => { '*' => { type => 'scalar' } } }
FORMAL SPECIFICATION
list_workflow_types : → ℤ* → ℤ*
result ≔ { t ↦ desc(t) ∣ t ∈ SupportedTypes }
|result| = 11
LIMITATIONS
Workflows are text templates, not data
Every generator except
perlis a heredoc, and--versionsworks by regex-rewriting that text. It is tied to the exact layout of each template (indentation, theubuntu-latestjob line, the pinned Go and Rust lines) and a template edit can silently stop it matching. Building each workflow as a Perl data structure and serialising it with YAML::XS would remove the whole class of problem; that is a rewrite of every generator, so it is not done here. The tests in t/versions_option.t parse the output as YAML to catch a broken rewrite.Default versions are fixed in the templates
The defaults are not validated against what the setup actions support today, and some are end of life (node 18, python 3.9, ruby 3.1). They are kept so existing output does not change.
One version list per run
--versionsapplies to the single generated type. There is no way to give different lists to different jobs in one workflow.Messages are sprintf formats only
%MESSAGEScan be reworded or translated by replacing its values, but there is no plural or grammatical-gender handling, and the table is a package global rather than per-object configuration. The messages here take only strings, so none is needed yet.Version tokens are checked for safety, not meaning
9.9.9is accepted for any language. Whether the setup action can install it is only discovered when the workflow runs.Perl ignores project detection when versions are given
generate_workflow('perl', { versions =... })> uses exactly the list given; the minimum Perl detected from cpanfile or Makefile.PL is not applied.
AUTHOR
Nigel Horne <njh@nigelhorne.com>
COPYRIGHT AND LICENSE
Copyright 2025-2026 Nigel Horne.
Usage is subject to the GPL2 licence terms. If you use it, please let me know.