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:
@@ -1,21 +1,22 @@
|
||||
#!/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
|
||||
#
|
||||
# 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 " (Use 'git push --no-verify' to skip)"
|
||||
echo "🚀 Preparing to push..."
|
||||
echo ""
|
||||
|
||||
# Detect which environment is running
|
||||
SAIL_RUNNING=false
|
||||
K8S_RUNNING=false
|
||||
|
||||
# Check if Sail is running
|
||||
if docker ps --format '{{.Names}}' | grep -q "sail" 2>/dev/null; then
|
||||
# Check if Sail is running (use vendor/bin/sail ps which works for all project names)
|
||||
if [ -f ./vendor/bin/sail ] && ./vendor/bin/sail ps 2>/dev/null | grep -q "Up"; then
|
||||
SAIL_RUNNING=true
|
||||
echo "📦 Detected Sail environment"
|
||||
fi
|
||||
|
||||
# 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
|
||||
K8S_RUNNING=true
|
||||
echo "☸️ Detected K8s environment (namespace: $K8S_NS)"
|
||||
fi
|
||||
|
||||
# Run tests in appropriate environment
|
||||
if [ "$SAIL_RUNNING" = true ]; then
|
||||
./vendor/bin/sail artisan test --parallel
|
||||
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"
|
||||
# Offer to run tests if environment is available
|
||||
if [ "$SAIL_RUNNING" = true ] || [ "$K8S_RUNNING" = true ]; then
|
||||
echo "💡 Tests will run automatically in CI/CD"
|
||||
echo ""
|
||||
read -p "Continue push anyway? (y/n) " -n 1 -r
|
||||
read -p "Run tests locally before push? (y/N) " -n 1 -r
|
||||
echo ""
|
||||
if [ ! "$REPLY" = "y" ] && [ ! "$REPLY" = "Y" ]; then
|
||||
echo "Push aborted"
|
||||
exit 1
|
||||
echo ""
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
echo "⚡ Pushing to remote (CI will run full test suite)..."
|
||||
echo ""
|
||||
echo "✅ All tests passed! Pushing..."
|
||||
|
||||
exit 0
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -62,3 +62,5 @@ core.*
|
||||
!resources/**/*.jpg
|
||||
!resources/**/*.jpeg
|
||||
.claude/settings.local.json
|
||||
storage/tmp/*
|
||||
!storage/tmp/.gitignore
|
||||
|
||||
@@ -17,6 +17,7 @@ services:
|
||||
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
|
||||
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
|
||||
IGNITION_LOCAL_SITES_PATH: '${PWD}'
|
||||
TMPDIR: '/var/www/html/storage/tmp'
|
||||
volumes:
|
||||
- '.:/var/www/html'
|
||||
networks:
|
||||
|
||||
2
storage/tmp/.gitignore
vendored
Normal file
2
storage/tmp/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user