Skip to content

Commit c883845

Browse files
authored
Merge pull request #3063 from drgrice1/perltidy-workflow-shebang-check
Make the workflow work for Perl scripts without a Perl extension.
2 parents f2b6811 + 57ff904 commit c883845

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

.github/workflows/check-formats.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@ jobs:
2626
run: |
2727
git config --global --add safe.directory "$GITHUB_WORKSPACE"
2828
shopt -s extglob globstar nullglob
29-
perltidy --pro=./.perltidyrc -b -bext='/' ./**/*.p[lm] ./**/*.t ./**/*.at && git diff --exit-code
29+
30+
perl_files=(./**/*.p[lm] ./**/*.t ./**/*.at)
31+
32+
for f in bin/* bin/dev_scripts/*; do
33+
if [[ -f "$f" && ! "$f" == *.* ]]; then
34+
if head -n 1 "$f" | grep -qE '^#!.*(\bperl\b)'; then
35+
perl_files+=("$f")
36+
fi
37+
fi
38+
done
39+
40+
if [ ${#perl_files[@]} -gt 0 ]; then
41+
perltidy --pro=./.perltidyrc -b -bext='/' "${perl_files[@]}"
42+
git diff --exit-code
43+
fi
3044
3145
prettier:
3246
name: Check JavaScript, style, and HTML file formatting with prettier

bin/addadmin

100755100644
File mode changed.

bin/dev_scripts/run-perltidy.pl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ =head1 OPTIONS
4545

4646
use Perl::Tidy;
4747
use File::Find qw(find);
48-
use Mojo::File qw(curfile);
48+
use Mojo::File qw(curfile path);
4949

5050
my $webwork_root = curfile->dirname->dirname->dirname;
5151

@@ -91,7 +91,17 @@ =head1 OPTIONS
9191
return;
9292
}
9393

94-
return unless $path =~ /\.p[lm]$/ || $path =~ /\.t$/ || $path =~ /\.at$/;
94+
my $isPerlScript = 0;
95+
if (($dir =~ /\/bin$/ || $dir =~ /\/bin\/dev_scripts$/)
96+
&& $path !~ /\.p[lm]$/
97+
&& -f $path
98+
&& (my $fh = path($path)->open('<')))
99+
{
100+
$isPerlScript = <$fh> =~ /^#!.*\bperl\b/;
101+
$fh->close;
102+
}
103+
104+
return unless $path =~ /\.p[lm]$/ || $path =~ /\.t$/ || $path =~ /\.at$/ || $isPerlScript;
95105

96106
say "Tidying file: $path" if $verbose;
97107

0 commit comments

Comments
 (0)