Dist-Conformance

 view release on metacpan or  search on metacpan

lib/Dist/Conformance/Check/Workflows.pm  view on Meta::CPAN

package Dist::Conformance::Check::Workflows 0.003;

# ABSTRACT: The CI workflows exist

use 5.040;
use warnings FATAL => 'all';
use re '/aasx';
use Mojo::Base 'Dist::Conformance::Check', -signatures;

use Dist::Conformance::Schema();


sub config_schema ($) {
    return {
        required   => ['directory'],
        properties => {
            directory => $Dist::Conformance::Schema::PATH,
            required  => { type => 'object', additionalProperties => { %$Dist::Conformance::Schema::PATH, nullable => 1 }, default => {} },
        },
    };
}


sub missing_workflows ( $self, $snapshot ) {
    my ( $directory, $required ) = @{ $self->config }{qw{directory required}};
    my @missing = grep { !$snapshot->contains("$directory/$_") } sort keys %$required;
    return @missing;
}


sub check ( $self, $snapshot ) {
    my ( $directory, $required ) = @{ $self->config }{qw{directory required}};
    if ( !%$required ) {
        my @have = grep { index( $_, q{/} ) < 0 } $snapshot->under($directory);
        return ( 'info', @have ? 'present: ' . join ', ', @have : 'none' );
    }
    my @missing = $self->missing_workflows($snapshot);
    return ( 'fail', 'missing: ' . join ', ', map { "$directory/$_" } @missing ) if @missing;
    return ( 'pass', 'all present' );
}


sub update ( $self, $update ) {
    my ( $directory, $required ) = @{ $self->config }{qw{directory required}};
    for my $name ( $self->missing_workflows( $update->snapshot ) ) {
        if ( defined $required->{$name} ) {
            $self->write_template( $update, "$directory/$name", $required->{$name} );
        }
        else {
            $update->by_hand("Write $directory/$name by hand: the flavor names no template for it");
        }
    }
    return;
}

__END__

=pod

=encoding UTF-8

=head1 NAME

Dist::Conformance::Check::Workflows - The CI workflows exist

=head1 VERSION

version 0.003

=head1 DESCRIPTION

The workflow files in C<directory>.  With none in C<required>, the check only
lists the ones present, as C<info>.  Otherwise it fails when a required
workflow is missing, and passes when none is.

The update writes each missing workflow from its template.

=head1 METHODS

=head2 missing_workflows

C<($snapshot)>.  The required workflows that the snapshot does not have.

=head2 check

=head2 update

Writes each missing workflow from its template.

=head1 IN A FLAVOR

    checks:
      Workflows:
        directory: .github/workflows
        required:
          ci.yml: templates/workflows/ci.yml

=head1 CONFIGURATION

=over

=item directory



( run in 1.577 second using v1.01-cache-2.11-cpan-1236ad508bc )