chore: improve git hooks and fix parallel test execution

Updated git hooks to follow Laravel best practices:
- Pre-commit: Keep fast Pint formatting (already optimal)
- Pre-push: Make tests optional with user prompt (defaults to No)
  - Sail detection now works for all project directory names
  - Emphasizes that CI/CD will run comprehensive tests
  - Faster developer workflow while maintaining quality gates

Fixed --parallel test execution:
- Set TMPDIR to /var/www/html/storage/tmp in docker-compose.yml
- Created storage/tmp directory for test cache
- Prevents "Permission denied" errors when running parallel tests

This approach:
 Speeds up local development (no mandatory slow pre-push tests)
 Maintains code quality (formatting is automatic, tests in CI)
 Works across all developer environments
 Follows Laravel/Pest CI/CD best practices

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jon Leopard
2025-11-16 13:12:17 -07:00
parent 94e67c5955
commit 07c5a1e336
4 changed files with 47 additions and 36 deletions

View File

@@ -1,21 +1,22 @@
#!/bin/sh #!/bin/sh
# #
# Pre-push hook - Runs tests before pushing (supports both Sail and K8s) # Pre-push hook - Optionally run tests before pushing
# Can be skipped with: git push --no-verify # Can be skipped with: git push --no-verify
# #
# This is OPTIONAL - CI/CD will run comprehensive tests automatically.
# Running tests locally can catch issues faster, but it's not required.
#
echo "🧪 Running tests before push..." echo "🚀 Preparing to push..."
echo " (Use 'git push --no-verify' to skip)"
echo "" echo ""
# Detect which environment is running # Detect which environment is running
SAIL_RUNNING=false SAIL_RUNNING=false
K8S_RUNNING=false K8S_RUNNING=false
# Check if Sail is running # Check if Sail is running (use vendor/bin/sail ps which works for all project names)
if docker ps --format '{{.Names}}' | grep -q "sail" 2>/dev/null; then if [ -f ./vendor/bin/sail ] && ./vendor/bin/sail ps 2>/dev/null | grep -q "Up"; then
SAIL_RUNNING=true SAIL_RUNNING=true
echo "📦 Detected Sail environment"
fi fi
# Check if k8s namespace exists for this worktree # Check if k8s namespace exists for this worktree
@@ -24,41 +25,46 @@ K8S_NS=$(echo "$BRANCH" | sed 's/feature\//feat-/' | sed 's/bugfix\//fix-/' | se
if kubectl get namespace "$K8S_NS" >/dev/null 2>&1; then if kubectl get namespace "$K8S_NS" >/dev/null 2>&1; then
K8S_RUNNING=true K8S_RUNNING=true
echo "☸️ Detected K8s environment (namespace: $K8S_NS)"
fi fi
# Run tests in appropriate environment # Offer to run tests if environment is available
if [ "$SAIL_RUNNING" = true ]; then if [ "$SAIL_RUNNING" = true ] || [ "$K8S_RUNNING" = true ]; then
./vendor/bin/sail artisan test --parallel echo "💡 Tests will run automatically in CI/CD"
TEST_EXIT_CODE=$?
elif [ "$K8S_RUNNING" = true ]; then
echo " Running tests in k8s pod..."
kubectl -n "$K8S_NS" exec deploy/web -- php artisan test
TEST_EXIT_CODE=$?
else
echo "⚠️ No environment running (Sail or K8s)"
echo " Skipping tests - please run tests manually"
echo "" echo ""
read -p "Continue push anyway? (y/n) " -n 1 -r read -p "Run tests locally before push? (y/N) " -n 1 -r
echo "" echo ""
if [ ! "$REPLY" = "y" ] && [ ! "$REPLY" = "Y" ]; then echo ""
echo "Push aborted"
exit 1 if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
echo "🧪 Running tests..."
echo ""
if [ "$SAIL_RUNNING" = true ]; then
./vendor/bin/sail artisan test --parallel
TEST_EXIT_CODE=$?
elif [ "$K8S_RUNNING" = true ]; then
kubectl -n "$K8S_NS" exec deploy/web -- php artisan test
TEST_EXIT_CODE=$?
fi
if [ $TEST_EXIT_CODE -ne 0 ]; then
echo ""
echo "❌ Tests failed!"
echo ""
echo "Options:"
echo " 1. Fix the failing tests (recommended)"
echo " 2. Push anyway - CI will catch failures: git push --no-verify"
echo ""
exit 1
fi
echo ""
echo "✅ All tests passed!"
echo ""
fi fi
exit 0
fi
# Check test results
if [ $TEST_EXIT_CODE -ne 0 ]; then
echo ""
echo "❌ Tests failed!"
echo ""
echo "Options:"
echo " 1. Fix the failing tests (recommended)"
echo " 2. Push anyway with: git push --no-verify"
echo ""
exit 1
fi fi
echo "⚡ Pushing to remote (CI will run full test suite)..."
echo "" echo ""
echo "✅ All tests passed! Pushing..."
exit 0

2
.gitignore vendored
View File

@@ -62,3 +62,5 @@ core.*
!resources/**/*.jpg !resources/**/*.jpg
!resources/**/*.jpeg !resources/**/*.jpeg
.claude/settings.local.json .claude/settings.local.json
storage/tmp/*
!storage/tmp/.gitignore

View File

@@ -17,6 +17,7 @@ services:
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}' XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
IGNITION_LOCAL_SITES_PATH: '${PWD}' IGNITION_LOCAL_SITES_PATH: '${PWD}'
TMPDIR: '/var/www/html/storage/tmp'
volumes: volumes:
- '.:/var/www/html' - '.:/var/www/html'
networks: networks:

2
storage/tmp/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore