Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions scripts/preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down