Skip to content

Commit 550d841

Browse files
committed
perf(ci): enable fast selective pre-commit and robust path detection for single-volume edits
1 parent b2d38ae commit 550d841

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

.github/workflows/book-validate-dev.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,22 @@ jobs:
161161
echo "🔧 Installing pre-commit hooks..."
162162
pre-commit install --install-hooks
163163
164-
echo "🔄 Running pre-commit on all files..."
165164
echo "Python version: $(python --version)"
166-
if pre-commit run --all-files --verbose; then
165+
if [ "${{ github.event_name }}" = "pull_request" ]; then
166+
echo "🔄 Running pre-commit on PR changes (origin/${{ github.base_ref }}..HEAD)..."
167+
CMD="pre-commit run --from-ref origin/${{ github.base_ref }} --to-ref HEAD --verbose"
168+
elif [ "${{ github.event_name }}" = "push" ] && git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
169+
echo "🔄 Running pre-commit on push changes (HEAD~1..HEAD)..."
170+
CMD="pre-commit run --from-ref HEAD~1 --to-ref HEAD --verbose"
171+
else
172+
echo "🔄 Running pre-commit on all files..."
173+
CMD="pre-commit run --all-files --verbose"
174+
fi
175+
176+
if eval "$CMD"; then
167177
echo "✅ Pre-commit checks: PASSED"
168178
else
169179
echo "❌ Pre-commit checks: FAILED"
170-
echo "📋 Showing detailed output:"
171-
pre-commit run --all-files --verbose || true
172180
exit 1
173181
fi
174182
@@ -229,7 +237,11 @@ jobs:
229237
TARGET="dev"
230238
231239
# Selective auto-detection of modified volume paths
232-
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
240+
if [ "${{ github.event_name }}" = "pull_request" ]; then
241+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }} HEAD 2>/dev/null || echo "")
242+
else
243+
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
244+
fi
233245
echo "📝 Changed files: $CHANGED_FILES"
234246
235247
HAS_VOL1=false
@@ -240,11 +252,11 @@ jobs:
240252
241253
while IFS= read -r file; do
242254
[ -z "$file" ] && continue
243-
if [[ "$file" =~ ^books/vol1/ ]]; then HAS_VOL1=true; fi
244-
if [[ "$file" =~ ^books/vol2/ ]]; then HAS_VOL2=true; fi
245-
if [[ "$file" =~ ^books/vol3/ ]]; then HAS_VOL3=true; fi
246-
if [[ "$file" =~ ^books/vol4/ ]]; then HAS_VOL4=true; fi
247-
if [[ "$file" =~ ^publishing/ || "$file" =~ ^shared/ || "$file" =~ ^\.github/ ]]; then HAS_SHARED=true; fi
255+
if [[ "$file" =~ ^books/vol1/ ]] || [[ "$file" =~ ^publishing/quarto/contents/vol1/ ]]; then HAS_VOL1=true; fi
256+
if [[ "$file" =~ ^books/vol2/ ]] || [[ "$file" =~ ^publishing/quarto/contents/vol2/ ]]; then HAS_VOL2=true; fi
257+
if [[ "$file" =~ ^books/vol3/ ]] || [[ "$file" =~ ^publishing/quarto/contents/vol3/ ]]; then HAS_VOL3=true; fi
258+
if [[ "$file" =~ ^books/vol4/ ]] || [[ "$file" =~ ^publishing/quarto/contents/vol4/ ]]; then HAS_VOL4=true; fi
259+
if [[ "$file" =~ ^publishing/binder ]] || [[ "$file" =~ ^shared/ ]] || [[ "$file" =~ ^\.github/ ]]; then HAS_SHARED=true; fi
248260
done <<< "$CHANGED_FILES"
249261
250262
if [ "$HAS_SHARED" = true ]; then

0 commit comments

Comments
 (0)