chore(pre-commit): add docusaurus build guard for changed docs sites

Add a local pre-commit hook that builds Docusaurus when files under
docs/user or docs/developer are staged.

Introduced scripts/docs/build-changed-sites to detect which docs site
was touched and run only the required npm build(s).

Impact: Prevents broken MDX/Docusaurus changes from being committed by
failing fast in pre-commit before CI.
This commit is contained in:
Julian Pawlowski 2026-04-09 18:41:41 +00:00
parent 06eedee410
commit aee1920292
2 changed files with 52 additions and 0 deletions

View file

@ -21,3 +21,12 @@ repos:
language: system
types: [python]
require_serial: true
# Build changed Docusaurus site(s) to catch MDX/build errors early
- id: docusaurus-build-changed-sites
name: docusaurus build (changed sites)
entry: bash scripts/docs/build-changed-sites
language: system
files: ^docs/(user|developer)/
pass_filenames: true
require_serial: true

View file

@ -0,0 +1,43 @@
#!/usr/bin/env bash
# Build only Docusaurus site(s) impacted by current staged file set.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$REPO_ROOT"
build_user=false
build_developer=false
for file in "$@"; do
case "$file" in
docs/user/*)
build_user=true
;;
docs/developer/*)
build_developer=true
;;
esac
done
if [[ "$build_user" == false && "$build_developer" == false ]]; then
exit 0
fi
if [[ "$build_user" == true ]]; then
echo "Building user docs (docs/user)..."
(
cd docs/user
npm run build
)
fi
if [[ "$build_developer" == true ]]; then
echo "Building developer docs (docs/developer)..."
(
cd docs/developer
npm run build
)
fi
echo "Docusaurus build check passed for changed docs site(s)."