echo "๐งช Running tests before push to ensure code quality..."
echo "๐ก This prevents broken code from being pushed to GitHub."
echo ""
# Detect if this push contains only tags (read refs from stdin)
TMP_REFS=$(mktemp 2>/dev/null || echo ./.prepush_tmp)
cat - > "$TMP_REFS"
TAGS_ONLY=true
if [ ! -s "$TMP_REFS" ]; then
# If no stdin provided, assume this is not a tags-only push
TAGS_ONLY=false
else
while read -r LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA; do
case "$LOCAL_REF" in
refs/tags/*) : ;; # tag, ok
*) TAGS_ONLY=false ;;
esac
done < "$TMP_REFS"
fi
rm -f "$TMP_REFS" 2>/dev/null || true
# Run linting first to catch syntax and style issues
echo "๐ Running ESLint to catch linting issues..."
pnpm run lint
if [ $? -ne 0 ]; then
echo ""
echo "โ Lint failed! Push blocked to prevent broken code on GitHub."
echo "๐ก Run 'pnpm run lint' to see all errors, or 'pnpm run lint:fix' for auto-fixes."
exit 1
fi
echo "โ
Lint passed!"
echo ""
# Clean build to ensure no stale artifacts
echo "๐จ Running clean build to ensure fresh compilation..."
npm run clean
npm run build
if [ $? -ne 0 ]; then
echo ""
echo "โ Build failed! Push blocked to prevent broken code on GitHub."
echo "๐ก Fix build errors before pushing."
exit 1
fi
echo "โ
Build successful!"
echo ""
# Run tests (reduced suite for tag-only pushes to match release CI)
if [ "$TAGS_ONLY" = true ]; then
echo ""
echo "๐ Tag-only push detected. Running reduced CI tests (no e2e, no python) to match release workflow..."
npm run test:ci-no-python
else
# Run the full test suite
npm test
fi
if [ $? -eq 0 ]; then
echo ""
echo "โ
All tests passed! Push will proceed."
echo "๐ Code quality maintained for GitHub repository."
else
echo ""
echo "โ Tests failed! Push blocked to prevent broken code on GitHub."
echo "๐ก Fix failing tests or use 'git push --no-verify' for emergency pushes."
echo "๐ง You can still make local commits for WIP - tests only run on push."
exit 1
fi