diff --git a/.github/workflows/check-formats.yml b/.github/workflows/check-formats.yml index 5c06bdbc10..863b02d988 100644 --- a/.github/workflows/check-formats.yml +++ b/.github/workflows/check-formats.yml @@ -26,7 +26,21 @@ jobs: run: | git config --global --add safe.directory "$GITHUB_WORKSPACE" shopt -s extglob globstar nullglob - perltidy --pro=./.perltidyrc -b -bext='/' ./**/*.p[lm] ./**/*.t ./**/*.at && git diff --exit-code + + perl_files=(./**/*.p[lm] ./**/*.t ./**/*.at) + + for f in bin/* bin/dev_scripts/*; do + if [[ -f "$f" && ! "$f" == *.* ]]; then + if head -n 1 "$f" | grep -qE '^#!.*(\bperl\b)'; then + perl_files+=("$f") + fi + fi + done + + if [ ${#perl_files[@]} -gt 0 ]; then + perltidy --pro=./.perltidyrc -b -bext='/' "${perl_files[@]}" + git diff --exit-code + fi prettier: name: Check JavaScript, style, and HTML file formatting with prettier diff --git a/bin/addadmin b/bin/addadmin old mode 100755 new mode 100644 diff --git a/bin/dev_scripts/run-perltidy.pl b/bin/dev_scripts/run-perltidy.pl index cc471d2436..0883ce2bd0 100755 --- a/bin/dev_scripts/run-perltidy.pl +++ b/bin/dev_scripts/run-perltidy.pl @@ -45,7 +45,7 @@ =head1 OPTIONS use Perl::Tidy; use File::Find qw(find); -use Mojo::File qw(curfile); +use Mojo::File qw(curfile path); my $webwork_root = curfile->dirname->dirname->dirname; @@ -91,7 +91,17 @@ =head1 OPTIONS return; } - return unless $path =~ /\.p[lm]$/ || $path =~ /\.t$/ || $path =~ /\.at$/; + my $isPerlScript = 0; + if (($dir =~ /\/bin$/ || $dir =~ /\/bin\/dev_scripts$/) + && $path !~ /\.p[lm]$/ + && -f $path + && (my $fh = path($path)->open('<'))) + { + $isPerlScript = <$fh> =~ /^#!.*\bperl\b/; + $fh->close; + } + + return unless $path =~ /\.p[lm]$/ || $path =~ /\.t$/ || $path =~ /\.at$/ || $isPerlScript; say "Tidying file: $path" if $verbose;