Files
goodgo-platform/scripts/pre-commit-tests.sh
Ho Ngoc Hai 0aa4fec615 feat(infra): scope pre-commit test hook to staged packages (GOO-228)
Replace blanket `npm test` with lint-staged for linting/formatting and
a turbo --filter script that runs tests only for workspace packages
that have staged .ts/.tsx files.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-25 18:34:38 +07:00

36 lines
776 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Detect which workspace packages have staged .ts/.tsx files and run tests
# only for those packages via turbo --filter.
STAGED_TS_FILES=$(git diff --cached --name-only --diff-filter=ACMR -- '*.ts' '*.tsx')
if [ -z "$STAGED_TS_FILES" ]; then
exit 0
fi
FILTERS=""
SEEN=""
while IFS= read -r file; do
case "$file" in
apps/api/*) pkg="@goodgo/api" ;;
apps/web/*) pkg="@goodgo/web" ;;
libs/mcp-servers/*) pkg="@goodgo/mcp-servers" ;;
*) continue ;;
esac
if [[ ! " $SEEN " =~ " $pkg " ]]; then
SEEN="$SEEN $pkg"
FILTERS="$FILTERS --filter=$pkg"
fi
done <<< "$STAGED_TS_FILES"
if [ -z "$FILTERS" ]; then
exit 0
fi
echo "Running tests for affected packages:$SEEN"
exec npx turbo run test $FILTERS