Files
cs249r_book/docs/PRE_COMMIT_VALIDATION_SUMMARY.md
Vijay Janapa Reddi 14c37b846b Add pre-commit part key validation system
- 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
2025-07-31 01:35:46 -04:00

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 .qmd files
  • Result: Blocks commit if invalid keys found

2. Validation Script

  • Location: scripts/validate_part_keys.py
  • Function: Scans all 65+ .qmd files
  • 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:

  1. Catches issues early - before commit, not after push
  2. Faster feedback - no waiting for CI/CD
  3. Prevents broken commits - keeps history clean
  4. Developer-friendly - immediate feedback
  5. 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.