From 57ff9046e2c169ca1505e82aabb09e14e64391db Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Thu, 16 Jul 2026 05:02:20 -0500 Subject: [PATCH] Make the workflow work for Perl scripts without a Perl extension. This works by checking the first line of the file for a `perl` shebang. That is it checks to see if the first line of a file starts with `#!` and contains `perl` after that. Note that only files in `bin` and `bin/dev_scripts` that do not have the extension `.pl` or `.pm` are checked for the shebang (and not files in a subdirectory of one of those). That is to prevent the workflow and script from becoming much more resource intensive than they already are, and also to skip `conf` files such as `conf/localOverrides.conf.dist` that is not currently "tidy". Both the GitHub workflow and the `bin/dev_scripts/run-perltidy.pl` script are updated for this. All of these files were perltidied in a recent pull request, so this ensures that they stay that way. Also remove the executable bit from `bin/addadmin`. That is a `wwsh` script, and not a script that can be directly executed from the shell. So it should not have the executable bit. --- .github/workflows/check-formats.yml | 16 +++++++++++++++- bin/addadmin | 0 bin/dev_scripts/run-perltidy.pl | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) mode change 100755 => 100644 bin/addadmin 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;