Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions scripts/verify-docs-archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,50 @@ for version in "${ARCHIVED_VERSIONS[@]}"; do
done

# Archive pages must never depend on the mutable root-level asset hashes from
# the current site. Keeping this invariant makes the one-time output portable.
if rg -l "(href|src)=['\"]?/assets/" "$ARCHIVE_ROOT" --glob '*.html' >/dev/null; then
echo "Archive HTML contains root-level /assets/ references" >&2
rg -l "(href|src)=['\"]?/assets/" "$ARCHIVE_ROOT" --glob '*.html' | head -n 20 >&2
exit 1
fi
# the current site. Use Python for this scan because GitHub's runner image does
# not guarantee that ripgrep is installed.
python3 - "$ARCHIVE_ROOT" <<'PY'
import re
import sys
from pathlib import Path

if ! rg -l '/archive/assets/' "$ARCHIVE_ROOT" --glob '*.html' >/dev/null; then
echo "Archive HTML does not reference namespaced /archive/assets/ files" >&2
exit 1
fi
archive_root = Path(sys.argv[1])
unexpected_versions = []
for docs_root in (archive_root / "docs", archive_root / "zh-CN" / "docs"):
for child in docs_root.iterdir():
if child.is_dir() and (
child.name == "next" or re.fullmatch(r"1[.]\d+[.]\d+", child.name)
):
unexpected_versions.append(str(child))

if unexpected_versions:
print("Archive contains current or 1.x docs:", file=sys.stderr)
for path in unexpected_versions:
print(path, file=sys.stderr)
raise SystemExit(1)

root_asset_pattern = re.compile(r'''(?:href|src)=["']?/assets/''')
root_asset_pages = []
has_archive_assets = False
for html_path in archive_root.rglob("*.html"):
html = html_path.read_text(encoding="utf-8", errors="ignore")
if root_asset_pattern.search(html):
root_asset_pages.append(str(html_path))
if "/archive/assets/" in html:
has_archive_assets = True

if root_asset_pages:
print("Archive HTML contains root-level /assets/ references:", file=sys.stderr)
for path in root_asset_pages[:20]:
print(path, file=sys.stderr)
raise SystemExit(1)

if not has_archive_assets:
print(
"Archive HTML does not reference namespaced /archive/assets/ files",
file=sys.stderr,
)
raise SystemExit(1)
PY

echo "Verified $total_pages archived HTML pages in $ARCHIVE_ROOT"
Loading