| 1 | package App::Workflow::Lint; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Carp qw(croak carp); | ||
| 6 | |||
| 7 | use App::Workflow::Lint::Engine; | ||
| 8 | |||
| 9 | # VERSION MUST be simple for MakeMaker to parse | ||
| 10 | our $VERSION = '0.01'; | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | App::Workflow::Lint - Linter for GitHub Actions workflow files | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | use App::Workflow::Lint; | ||
| 19 | |||
| 20 | my $linter = App::Workflow::Lint->new; | ||
| 21 | my @diagnostics = $linter->check_file('workflow.yml'); | ||
| 22 | |||
| 23 | # Or via CLI: | ||
| 24 | # workflow-lint check workflow.yml | ||
| 25 | |||
| 26 | =head1 DESCRIPTION | ||
| 27 | |||
| 28 | C<App::Workflow::Lint> provides the core interface for linting GitHub | ||
| 29 | Actions workflow files. It loads a workflow, applies a set of linting | ||
| 30 | rules, and returns diagnostics describing any issues found. | ||
| 31 | |||
| 32 | This module is used internally by the C<workflow-lint> command-line tool, | ||
| 33 | but can also be used programmatically. | ||
| 34 | |||
| 35 | =head1 METHODS | ||
| 36 | |||
| 37 | =head2 new | ||
| 38 | |||
| 39 | my $linter = App::Workflow::Lint->new(%opts); | ||
| 40 | |||
| 41 | Constructs a new linter instance. | ||
| 42 | |||
| 43 | =head2 check_file | ||
| 44 | |||
| 45 | my @diagnostics = $linter->check_file($file); | ||
| 46 | |||
| 47 | Loads the workflow from C<$file>, applies all linting rules, and returns | ||
| 48 | a list of diagnostics. Each diagnostic is a hashref describing the issue. | ||
| 49 | |||
| 50 | =head2 fix_file | ||
| 51 | |||
| 52 | my ($workflow, $diagnostics) = $linter->fix_file($file); | ||
| 53 | |||
| 54 | Loads the workflow, applies all rules, executes any available fixes, and | ||
| 55 | returns the modified workflow structure along with the list of diagnostics. | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | #---------------------------------------------------------------------- | ||
| 60 | # Constructor | ||
| 61 | #---------------------------------------------------------------------- | ||
| 62 | sub new { | ||
| 63 | my ($class, %opts) = @_; | ||
| 64 | return bless { %opts }, $class; | ||
| 65 | } | ||
| 66 | |||
| 67 | #---------------------------------------------------------------------- | ||
| 68 | # check_file($path) | ||
| 69 | # | ||
| 70 | # Convenience wrapper around the engine. Loads the workflow file, | ||
| 71 | # runs all rules, and returns a list of diagnostics. | ||
| 72 | #---------------------------------------------------------------------- | ||
| 73 | sub check_file { | ||
| 74 | my ($self, $file) = @_; | ||
| 75 | croak "check_file() requires a filename" unless defined $file; | ||
| 76 | |||
| 77 | my $engine = App::Workflow::Lint::Engine->new(%$self); | ||
| 78 | return $engine->check_file($file); | ||
| 79 | } | ||
| 80 | |||
| 81 | =head1 AUTHOR | ||
| 82 | |||
| 83 | Nigel Horne, C<< <njh at nigelhorne.com> >> | ||
| 84 | |||
| 85 | =head1 BUGS | ||
| 86 | |||
| 87 | is_tablet() only currently detects the iPad and Windows PCs. Android strings | ||
| 88 | don't differ between tablets and smartphones. | ||
| 89 | |||
| 90 | params() returns a ref which means that calling routines can change the hash | ||
| 91 | for other routines. | ||
| 92 | Take a local copy before making amendments to the table if you don't want unexpected | ||
| 93 | things to happen. | ||
| 94 | |||
| 95 | =head1 SEE ALSO | ||
| 96 | |||
| 97 | =over 4 | ||
| 98 | |||
| 99 | =item * L<App::Test::Generator> | ||
| 100 | |||
| 101 | =back | ||
| 102 | |||
| 103 | =head1 REPOSITORY | ||
| 104 | |||
| 105 | L<https://github.com/nigelhorne/App-Workflow-Lint> | ||
| 106 | |||
| 107 | =head1 SUPPORT | ||
| 108 | |||
| 109 | This module is provided as-is without any warranty. | ||
| 110 | |||
| 111 | Please report any bugs or feature requests to C<bug-app-workflow-lint at rt.cpan.org>, | ||
| 112 | or through the web interface at | ||
| 113 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Workflow-Lint>. | ||
| 114 | I will be notified, and then you'll | ||
| 115 | automatically be notified of progress on your bug as I make changes. | ||
| 116 | |||
| 117 | You can find documentation for this module with the perldoc command. | ||
| 118 | |||
| 119 | perldoc App::Workflow::Lint | ||
| 120 | |||
| 121 | You can also look for information at: | ||
| 122 | |||
| 123 | =over 4 | ||
| 124 | |||
| 125 | =item * MetaCPAN | ||
| 126 | |||
| 127 | L<https://metacpan.org/dist/App-Workflow-Lint> | ||
| 128 | |||
| 129 | =item * RT: CPAN's request tracker | ||
| 130 | |||
| 131 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=App-Workflow-Lint> | ||
| 132 | |||
| 133 | =item * CPAN Testers' Matrix | ||
| 134 | |||
| 135 | L<http://matrix.cpantesters.org/?dist=App-Workflow-Lint> | ||
| 136 | |||
| 137 | =item * CPAN Testers Dependencies | ||
| 138 | |||
| 139 | L<http://deps.cpantesters.org/?module=App::Workflow::Lint> | ||
| 140 | |||
| 141 | =back | ||
| 142 | |||
| 143 | =head1 LICENCE AND COPYRIGHT | ||
| 144 | |||
| 145 | Copyright 2026 Nigel Horne. | ||
| 146 | |||
| 147 | Usage is subject to licence terms. | ||
| 148 | |||
| 149 | The licence terms of this software are as follows: | ||
| 150 | |||
| 151 | =over 4 | ||
| 152 | |||
| 153 | =item * Personal single user, single computer use: GPL2 | ||
| 154 | |||
| 155 | =item * All other users (including Commercial, Charity, Educational, Government) | ||
| 156 | must apply in writing for a licence for use from Nigel Horne at the | ||
| 157 | above e-mail. | ||
| 158 | |||
| 159 | =back | ||
| 160 | |||
| 161 | =cut | ||
| 162 | |||
| 163 | 1; |