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>
This commit is contained in:
@@ -1 +1,2 @@
|
||||
npm test
|
||||
npx lint-staged
|
||||
bash scripts/pre-commit-tests.sh
|
||||
|
||||
35
scripts/pre-commit-tests.sh
Executable file
35
scripts/pre-commit-tests.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user