From d98f988b75b4473027d82c17c33cedeac2bddefe Mon Sep 17 00:00:00 2001 From: Breakthrough Date: Sun, 22 Nov 2026 21:46:18 -0500 Subject: [PATCH] [docs] Harden deploy workflows, strict link checks, and site tooling --- .github/workflows/check-docs.yml | 8 +- .github/workflows/generate-docs.yml | 18 ++- .github/workflows/generate-website.yml | 18 ++- docs/_ext/doc_versions.py | 73 +++++++---- docs/_templates/layout.html | 4 - website/build.py | 165 +++++++++++++++++++++++-- website/check_layout.py | 28 ++++- website/requirements.txt | 7 +- website/theme/site.js | 5 - 9 files changed, 270 insertions(+), 56 deletions(-) diff --git a/.github/workflows/check-docs.yml b/.github/workflows/check-docs.yml index cb27f184..ea95b28c 100644 --- a/.github/workflows/check-docs.yml +++ b/.github/workflows/check-docs.yml @@ -9,12 +9,16 @@ on: - scenedetect/** - scenedetect.cfg - website/** + - pyproject.toml + - .github/workflows/check-docs.yml push: paths: - docs/** - scenedetect/** - scenedetect.cfg - website/** + - pyproject.toml + - .github/workflows/check-docs.yml branches: - main - 'releases/**' @@ -28,6 +32,8 @@ jobs: # workflow author, who then gets emailed when a fork's nightly build fails. if: github.repository_owner == 'Breakthrough' || github.event_name != 'schedule' runs-on: ubuntu-latest + permissions: + contents: read steps: - uses: actions/checkout@v7.0.1 @@ -61,7 +67,7 @@ jobs: - name: Build Website (--strict) shell: bash run: | - python website/build.py --strict + python website/build.py --strict --sphinx-dir docs/_build/html - name: Check Responsive Layout & Capture Screenshots shell: bash diff --git a/.github/workflows/generate-docs.yml b/.github/workflows/generate-docs.yml index 8e0a89f5..363ce894 100644 --- a/.github/workflows/generate-docs.yml +++ b/.github/workflows/generate-docs.yml @@ -14,7 +14,7 @@ on: workflow_dispatch: concurrency: - group: gh-pages + group: gh-pages-docs cancel-in-progress: false jobs: @@ -93,7 +93,7 @@ jobs: DOCS_DEST: ${{ env.scenedetect_docs_dest }} run: | git fetch origin gh-pages - git checkout gh-pages + git checkout -B gh-pages origin/gh-pages git clean -ffdx git rm "docs/${DOCS_DEST}" -r -f --ignore-unmatch mkdir -p "docs/${DOCS_DEST}" @@ -121,5 +121,17 @@ jobs: git commit -a -m "[docs] @${TRIGGER_ACTOR}: Generate Documentation" \ -m "Source: ${GITHUB_REF_NAME} (${GITHUB_SHA})" \ -m "Destination: ${DOCS_DEST}" - git push + for attempt in 1 2 3 4 5; do + if git push origin gh-pages; then + break + fi + if [[ "${attempt}" -eq 5 ]]; then + echo "Failed to push to gh-pages after ${attempt} attempts." >&2 + exit 1 + fi + echo "Push failed (attempt ${attempt}/5); rebasing onto origin/gh-pages and retrying..." + sleep $((attempt * 2)) + git fetch origin gh-pages + git pull --rebase origin gh-pages + done fi diff --git a/.github/workflows/generate-website.yml b/.github/workflows/generate-website.yml index 5ce2e8f7..25518554 100644 --- a/.github/workflows/generate-website.yml +++ b/.github/workflows/generate-website.yml @@ -24,7 +24,7 @@ on: - clear-staging concurrency: - group: gh-pages + group: gh-pages-website cancel-in-progress: false jobs: @@ -94,7 +94,7 @@ jobs: shell: bash run: | git fetch origin gh-pages - git checkout gh-pages + git checkout -B gh-pages origin/gh-pages git clean -ffdx if [[ "${DEPLOY_TARGET}" == "production" ]]; then @@ -126,7 +126,19 @@ jobs: git commit -a -m "[docs] @${TRIGGER_ACTOR}: Generate Website (${DEPLOY_TARGET})" \ -m "Source: ${GITHUB_REF_NAME} (${GITHUB_SHA})" \ -m "Target: ${DEPLOY_TARGET}" - git push + for attempt in 1 2 3 4 5; do + if git push origin gh-pages; then + break + fi + if [[ "${attempt}" -eq 5 ]]; then + echo "Failed to push to gh-pages after ${attempt} attempts." >&2 + exit 1 + fi + echo "Push failed (attempt ${attempt}/5); rebasing onto origin/gh-pages and retrying..." + sleep $((attempt * 2)) + git fetch origin gh-pages + git pull --rebase origin gh-pages + done fi env: DEPLOY_TARGET: ${{ env.deploy_target }} diff --git a/docs/_ext/doc_versions.py b/docs/_ext/doc_versions.py index 88fc130a..e4e6c656 100644 --- a/docs/_ext/doc_versions.py +++ b/docs/_ext/doc_versions.py @@ -20,39 +20,63 @@ def _entry(slug: str, label: str, group: str) -> dict[str, Any]: def load_doc_versions( repo_dir: Path, fallback_version: str = "" ) -> tuple[str, list[dict[str, Any]]]: - """Load (latest_version, version_entries) from docs/LATEST_VERSION and website/pages/docs.md.""" + """Load (latest_version, version_entries) from docs/LATEST_VERSION and website/pages/docs.md. + + Raises: + ValueError: If LATEST_VERSION cannot be resolved, website/pages/docs.md is missing or + yields no stable/legacy version entries, or LATEST_VERSION is not listed under + the Stable section of website/pages/docs.md. + """ latest_file = repo_dir / "docs" / "LATEST_VERSION" latest_ver = ( latest_file.read_text(encoding="utf-8").strip().lstrip("v") if latest_file.is_file() - else fallback_version.lstrip("v") + else fallback_version.strip().lstrip("v") ) + if not latest_ver: + raise ValueError( + f"Could not determine latest documentation version from {latest_file} " + "(and no fallback_version was provided)." + ) + + docs_md = repo_dir / "website" / "pages" / "docs.md" + if not docs_md.is_file(): + raise ValueError(f"Missing documentation version index: {docs_md}") stable_slugs: list[str] = [] legacy_slugs: list[str] = [] - docs_md = repo_dir / "website" / "pages" / "docs.md" - if docs_md.is_file(): - section = "" - for raw_line in docs_md.read_text(encoding="utf-8").splitlines(): - line = raw_line.strip() - if line.startswith("## "): - section = line[3:].strip().lower() - continue - match = _DOC_LINK_RE.match(line) - if not match: - continue - slug = match.group(2).strip() - if slug in {"latest", "head"}: - continue - if section == "legacy": - legacy_slugs.append(slug) - else: - stable_slugs.append(slug) + section = "" + for raw_line in docs_md.read_text(encoding="utf-8").splitlines(): + line = raw_line.strip() + if line.startswith("## "): + section = line[3:].strip().lower() + continue + match = _DOC_LINK_RE.match(line) + if not match: + continue + slug = match.group(2).strip() + if slug in {"latest", "head"}: + continue + if section == "legacy": + legacy_slugs.append(slug) + elif section == "stable": + stable_slugs.append(slug) - if not stable_slugs and latest_ver: - stable_slugs = [latest_ver, "0.7"] + if not stable_slugs: + raise ValueError( + f"No stable version links found under '## Stable' in {docs_md}; " + "expected '- [vX.Y.Z](/docs/X.Y.Z/)' list items." + ) if not legacy_slugs: - legacy_slugs = ["0.6.7"] + raise ValueError( + f"No legacy version links found under '## Legacy' in {docs_md}; " + "expected '- [vX.Y.Z](/docs/X.Y.Z/)' list items." + ) + if latest_ver not in stable_slugs: + raise ValueError( + f"LATEST_VERSION '{latest_ver}' is not listed under '## Stable' in {docs_md} " + f"(found: {', '.join(stable_slugs)})." + ) entries = [ _entry("latest", f"v{latest_ver} (latest)", "channel"), @@ -60,6 +84,5 @@ def load_doc_versions( ] # Avoid duplicating `latest` as a separate row when it is the current stable release. entries += [_entry(slug, f"v{slug}", "release") for slug in stable_slugs if slug != latest_ver] - if legacy_slugs: - entries.append(_entry(legacy_slugs[0], f"v{legacy_slugs[0]} (legacy)", "legacy")) + entries.append(_entry(legacy_slugs[0], f"v{legacy_slugs[0]} (legacy)", "legacy")) return latest_ver, entries diff --git a/docs/_templates/layout.html b/docs/_templates/layout.html index 49247f46..c5b91586 100644 --- a/docs/_templates/layout.html +++ b/docs/_templates/layout.html @@ -28,10 +28,6 @@ {%- endif %}