Files
proxmox/docs/scripts/validate-doc-headers.sh

47 lines
1.4 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
# validate-doc-headers.sh - Check that docs have standard headers (Last Updated, Document Version, Status, ---)
# Usage: run from docs/ or repo root: ./docs/scripts/validate-doc-headers.sh [dir]
# Exit: 0 if all checked files pass, 1 if any fail.
# Optional: Document Version is warned only (not required for pass).
set -e
DOCS_DIR="${1:-.}"
if [[ "$DOCS_DIR" == . ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOCS_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
fi
FAIL=0
WARN=0
while IFS= read -r -d '' f; do
if ! head -20 "$f" | grep -q '\*\*Last Updated:\*\*'; then
echo "Missing 'Last Updated:' in $f"
FAIL=1
fi
if ! head -20 "$f" | grep -q '\*\*Status:\*\*'; then
if ! head -20 "$f" | grep -q 'Status:'; then
echo "Missing 'Status:' in $f"
FAIL=1
fi
fi
if ! head -25 "$f" | grep -q '^---$'; then
echo "Missing '---' separator in first 25 lines of $f"
FAIL=1
fi
if ! head -20 "$f" | grep -q '\*\*Document Version:\*\*'; then
echo "Warning: Missing 'Document Version:' in $f"
WARN=1
fi
done < <(find "$DOCS_DIR" -maxdepth 3 -name '*.md' -not -path '*/archive/*' -print0 2>/dev/null)
if [[ $FAIL -eq 1 ]]; then
echo "One or more documents failed header validation."
exit 1
fi
if [[ $WARN -eq 1 ]]; then
echo "Header validation passed; some docs missing optional 'Document Version:'."
else
echo "Header validation passed for checked documents."
fi
exit 0