From e027c2772f6635d5e7b6b7291431e5fa06db4643 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 1 Nov 2025 19:25:21 +0000 Subject: [PATCH 1/2] Initial plan From 4eaf89423ba92c9c421429bdb579131538af8cb9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 1 Nov 2025 19:27:57 +0000 Subject: [PATCH 2/2] refactor: extract helper functions and use --dirty flag for Pint Co-authored-by: kevalyq <237265092+kevalyq@users.noreply.github.com> --- scripts/preflight.sh | 76 +++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/scripts/preflight.sh b/scripts/preflight.sh index 93432e5..1ba73dd 100755 --- a/scripts/preflight.sh +++ b/scripts/preflight.sh @@ -43,6 +43,38 @@ if [ "$FORMAT_EXIT" -ne 0 ]; then exit 1 fi +# Helper functions to reduce duplication +run_pint() { + local cmd_prefix="$1" + if [ -x ./vendor/bin/pint ]; then + ${cmd_prefix} ./vendor/bin/pint --dirty + fi +} + +run_phpstan() { + local cmd_prefix="$1" + if [ -x ./vendor/bin/phpstan ]; then + if [ -f phpstan.neon ] || [ -f phpstan.neon.dist ]; then + ${cmd_prefix} php -d memory_limit=512M ./vendor/bin/phpstan analyse + else + ${cmd_prefix} php -d memory_limit=512M ./vendor/bin/phpstan analyse --level=max + fi + fi +} + +run_tests() { + local cmd_prefix="$1" + local test_exit=0 + if [ -f artisan ]; then + ${cmd_prefix} php artisan test --parallel || test_exit=$? + elif [ -x ./vendor/bin/pest ]; then + ${cmd_prefix} ./vendor/bin/pest --parallel || test_exit=$? + elif [ -x ./vendor/bin/phpunit ]; then + ${cmd_prefix} ./vendor/bin/phpunit || test_exit=$? + fi + echo "$test_exit" +} + # 1) PHP / Laravel if [ -f composer.json ]; then if ! command -v composer >/dev/null 2>&1; then @@ -58,51 +90,23 @@ if [ -f composer.json ]; then if [ "$USE_DDEV" = true ]; then # Dependencies are managed within DDEV container (vendor/ is bind-mounted from host) # No need to run composer install here - DDEV setup already handles it - # Run Laravel Pint code style check if available (blocking: aligns with gates) - if [ -x ./vendor/bin/pint ]; then - ddev exec ./vendor/bin/pint --test - fi + # Run Laravel Pint code style check if available (blocking: fixes formatting issues) + run_pint "ddev exec" # Run PHPStan (use configured level from phpstan.neon if exists, else max) - if [ -x ./vendor/bin/phpstan ]; then - if [ -f phpstan.neon ] || [ -f phpstan.neon.dist ]; then - ddev exec php -d memory_limit=512M ./vendor/bin/phpstan analyse - else - ddev exec php -d memory_limit=512M ./vendor/bin/phpstan analyse --level=max - fi - fi + run_phpstan "ddev exec" else composer install --no-interaction --no-progress --prefer-dist --optimize-autoloader - # Run Laravel Pint code style check if available (blocking: aligns with gates) - if [ -x ./vendor/bin/pint ]; then - ./vendor/bin/pint --test - fi + # Run Laravel Pint code style check if available (blocking: fixes formatting issues) + run_pint "" # Run PHPStan (use configured level from phpstan.neon if exists, else max) - if [ -x ./vendor/bin/phpstan ]; then - if [ -f phpstan.neon ] || [ -f phpstan.neon.dist ]; then - php -d memory_limit=512M ./vendor/bin/phpstan analyse - else - php -d memory_limit=512M ./vendor/bin/phpstan analyse --level=max - fi - fi + run_phpstan "" fi # Run tests (Laravel Artisan → Pest → PHPUnit) TEST_EXIT=0 if [ "$USE_DDEV" = true ]; then - if [ -f artisan ]; then - ddev exec php artisan test --parallel || TEST_EXIT=$? - elif [ -x ./vendor/bin/pest ]; then - ddev exec ./vendor/bin/pest --parallel || TEST_EXIT=$? - elif [ -x ./vendor/bin/phpunit ]; then - ddev exec ./vendor/bin/phpunit || TEST_EXIT=$? - fi + TEST_EXIT=$(run_tests "ddev exec") else - if [ -f artisan ]; then - php artisan test --parallel || TEST_EXIT=$? - elif [ -x ./vendor/bin/pest ]; then - ./vendor/bin/pest --parallel || TEST_EXIT=$? - elif [ -x ./vendor/bin/phpunit ]; then - ./vendor/bin/phpunit || TEST_EXIT=$? - fi + TEST_EXIT=$(run_tests "") # Show warning only after test failure when DDEV not available if [ "$TEST_EXIT" -ne 0 ]; then echo "⚠️ Tests failed without DDEV - database connection may be unavailable" >&2