mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-04-29 00:59:07 -05:00
- Add validate-part-keys hook to .pre-commit-config.yaml - Create validate_part_keys.py script for comprehensive validation - Enhance inject-parts.lua with better error handling and pre-scan - Add documentation for part key validation system - Remove validation from GitHub workflow (moved to pre-commit) - Add utility scripts for key checking and build cleanup This catches invalid part keys before commit rather than in CI/CD
2.3 KiB
2.3 KiB
Pre-commit Part Key Validation - Summary
What We Implemented
You were absolutely right! Instead of doing validation in the GitHub workflow, we moved it to pre-commit hooks where it belongs. This catches issues before they even get committed, let alone pushed to the workflow.
✅ What's Now in Place:
1. Pre-commit Hook
- Location:
.pre-commit-config.yaml - Trigger: Runs on every commit
- Action: Validates all part keys in
.qmdfiles - Result: Blocks commit if invalid keys found
2. Validation Script
- Location:
scripts/validate_part_keys.py - Function: Scans all 65+
.qmdfiles - Checks: Validates against
book/part_summaries.yml - Output: Detailed error report with file/line numbers
3. Easy-to-Use Tools
- Quick check:
pre-commit run validate-part-keys --all-files - Wrapper script:
./scripts/check_keys.sh - Direct validation:
python3 scripts/validate_part_keys.py
🚀 Benefits of Pre-commit Approach:
- Catches issues early - before commit, not after push
- Faster feedback - no waiting for CI/CD
- Prevents broken commits - keeps history clean
- Developer-friendly - immediate feedback
- Reduces CI/CD load - fewer failed builds
📊 Current Status:
- ✅ 15 valid keys in
part_summaries.yml - ✅ 65+ .qmd files scanned
- ✅ 0 issues found
- ✅ Pre-commit hook working perfectly
🔧 How to Use:
For Developers:
# Normal workflow (validation runs automatically)
git add .
git commit -m "Your changes"
# If invalid keys found, commit is blocked
For Manual Testing:
# Test validation
pre-commit run validate-part-keys --all-files
# Or run directly
python3 scripts/validate_part_keys.py
🛠️ Removed from Workflow:
- ❌ Removed validation step from
.github/workflows/quarto-build.yml - ✅ Validation now happens in pre-commit hooks
- ✅ Faster, more efficient, developer-friendly
🎯 Result:
The key:xxx error you were seeing will now be caught before commit, preventing it from ever reaching the build process. This is much more efficient and user-friendly than catching it in the workflow.
This approach is much better because it catches issues at the source (during development) rather than after they've been pushed to the repository.