|
1 | 1 | #!/usr/bin/env sh |
2 | | -. "$(dirname -- "$0")/_/husky.sh" |
3 | 2 |
|
4 | | -cd frontend && npm run lint && npm run test:ci |
| 3 | +# Get the range of commits being pushed |
| 4 | +# For the remote branch that doesn't exist yet, use the empty tree object |
| 5 | +RANGE="$(git rev-parse --verify HEAD)" |
| 6 | + |
| 7 | +echo "Checking commit range: $RANGE" |
| 8 | + |
| 9 | +# Check if any frontend files were modified in the commits being pushed |
| 10 | +FRONTEND_CHANGES=$(git diff --name-only $RANGE | grep "^frontend/" || true) |
| 11 | + |
| 12 | +# Only run frontend tests if frontend files were modified |
| 13 | +if [ -n "$FRONTEND_CHANGES" ]; then |
| 14 | + echo "Frontend changes detected. Running frontend tests..." |
| 15 | + |
| 16 | + # Navigate to frontend directory |
| 17 | + cd frontend || exit 1 |
| 18 | + |
| 19 | + . "$(dirname -- "$0")/_/husky.sh" |
| 20 | + |
| 21 | + cd frontend && npm run lint && npm run test:ci |
| 22 | + |
| 23 | + # Capture the exit code |
| 24 | + TEST_EXIT_CODE=$? |
| 25 | + |
| 26 | + # Return to the original directory |
| 27 | + cd .. |
| 28 | + |
| 29 | + # If tests failed, prevent the push |
| 30 | + if [ $TEST_EXIT_CODE -ne 0 ]; then |
| 31 | + echo "Frontend tests failed. Push aborted." |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + |
| 35 | + echo "Frontend tests passed." |
| 36 | +else |
| 37 | + echo "No frontend changes detected. Skipping frontend tests." |
| 38 | +fi |
| 39 | + |
| 40 | +# Check if any backend files were modified in the commits being pushed |
| 41 | +BACKEND_CHANGES=$(git diff --name-only $RANGE | grep "^backend/" || true) |
| 42 | + |
| 43 | +if [ -n "$BACKEND_CHANGES" ]; then |
| 44 | + echo "Backend changes detected. Running backend lint..." |
| 45 | + |
| 46 | + . "$(dirname -- "$0")/_/husky.sh" |
| 47 | + cd backend && npm run lint |
| 48 | +else |
| 49 | + echo "No backend changes detected. Skipping backend tests." |
| 50 | +fi |
| 51 | + |
| 52 | +# Continue with the push |
| 53 | +exit 0 |
0 commit comments