PerlAlien / Alien

Create and use external (non-Perl) dependencies for CPAN!
4 stars 0 forks source link

set .gitattributes files to render alienfiles as perl across PerlAlien repos #8

Open shawnlaffan opened 1 year ago

shawnlaffan commented 1 year ago

alienfiles are pure perl code but render on GitHub as plain text. This can be corrected by adding this line to a .gitattributes file in each repo:

alienfile linguist-language=perl

I would submit PRs but there are too many repos under the organisation for this to be efficient. The script below is one approach to automation assuming all repos are at the same level.

use 5.010;
use strict;
use warnings;

use Path::Tiny;
use Cwd qw /getcwd/;

my @dirs = grep {-d} (path (getcwd())->children);

foreach my $dir (@dirs) {
    my $has_alienfile = grep {path($_)->basename eq 'alienfile'} (path($dir)->children);
    next if !$has_alienfile;
    my $file = path($dir, '.gitattributes');
    $file->touch;
    my $contents = $file->slurp;
    if (not $contents =~ /alienfile/ms) {
        $file->append("alienfile linguist-language=perl\n");
    }
}
plicease commented 1 year ago

Good point. I have a script which can make this change to all the repos in this org (and some in PerlFFI + uperl orgs which also have alienfile), but I usually only run it when I have a batch of changes to make, often when I have to bump CI for new Perls. I've added a note to do it then.

shawnlaffan commented 1 year ago

Thanks. Doing it as part of the next batch update sounds good to me.