From 8226e9d62df08285a3471a2d2a0c67f5842c8d46 Mon Sep 17 00:00:00 2001 From: sergiopaniego Date: Wed, 25 Nov 2026 11:25:51 +0100 Subject: [PATCH 01/11] Publish the docs to GitHub Pages with versions and PR previews Build the docs with HF doc-builder in GitHub Actions and publish them to GitHub Pages from the gh-pages branch, with no Hugging Face token: main, one folder per release tag, and a preview per pull request that is removed when it closes. docs/pages adds the layout that huggingface.co provides for doc-builder pages (sidebar, styles, version picker, redirects). Remove the huggingface.co doc workflows, which fail since the move to the openenv org because their HF secrets do not exist here. A weekly workflow opens an issue when huggingface/doc-builder moves ahead of the pinned commit. --- .github/workflows/build_documentation.yml | 19 -- .github/workflows/build_pr_documentation.yml | 20 -- .github/workflows/docs.yml | 172 +++++++++++ .github/workflows/docs_builder_update.yml | 56 ++++ .github/workflows/docs_pr_preview.yml | 115 ++++++++ .github/workflows/upload_pr_documentation.yml | 18 -- docs/README.md | 23 ++ docs/pages/build_css.mjs | 47 +++ docs/pages/build_site.py | 238 +++++++++++++++ docs/pages/publish.sh | 80 +++++ docs/pages/shell.css | 274 ++++++++++++++++++ 11 files changed, 1005 insertions(+), 57 deletions(-) delete mode 100644 .github/workflows/build_documentation.yml delete mode 100644 .github/workflows/build_pr_documentation.yml create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/docs_builder_update.yml create mode 100644 .github/workflows/docs_pr_preview.yml delete mode 100644 .github/workflows/upload_pr_documentation.yml create mode 100644 docs/pages/build_css.mjs create mode 100644 docs/pages/build_site.py create mode 100755 docs/pages/publish.sh create mode 100644 docs/pages/shell.css diff --git a/.github/workflows/build_documentation.yml b/.github/workflows/build_documentation.yml deleted file mode 100644 index 4a3c902d70..0000000000 --- a/.github/workflows/build_documentation.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Build documentation - -on: - push: - branches: - - main - - doc-builder* - - v*-release - -jobs: - build: - uses: huggingface/doc-builder/.github/workflows/build_main_documentation.yml@7b35a31ae9844db8b177ef3ca869184a79d791f8 # main - with: - commit_sha: ${{ github.sha }} - package: openenv - repo_owner: openenv - version_tag_suffix: "" - secrets: - hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }} diff --git a/.github/workflows/build_pr_documentation.yml b/.github/workflows/build_pr_documentation.yml deleted file mode 100644 index 4f722ef322..0000000000 --- a/.github/workflows/build_pr_documentation.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Build PR Documentation - -on: - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - build: - if: github.event.pull_request.draft == false - uses: huggingface/doc-builder/.github/workflows/build_pr_documentation.yml@7b35a31ae9844db8b177ef3ca869184a79d791f8 # main - with: - commit_sha: ${{ github.event.pull_request.head.sha }} - pr_number: ${{ github.event.number }} - package: openenv - repo_owner: openenv - version_tag_suffix: "" -# doc-builder registry now provides tomli for the light install diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000000..0a59aa001c --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,172 @@ +name: Docs + +# Builds the docs with HF doc-builder and publishes them to GitHub Pages (gh-pages +# branch), with no Hugging Face token: +# - push to main -> /main/ +# - release tag vX.Y.Z -> /vX.Y.Z/ +# - manual run + version -> rebuilds that release from its tag +# - pull request -> build only; docs_pr_preview.yml publishes it to +# /pr-preview/pr-N/ +# docs/pages/ adds the site layout that huggingface.co provides for doc-builder pages. + +on: + push: + branches: + - main + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + pull_request: + types: [opened, synchronize, reopened, labeled] + paths: + - "docs/**" + - "src/openenv/**" + - ".github/workflows/docs.yml" + workflow_dispatch: + inputs: + version: + description: "Release tag to rebuild, e.g. v0.14.0. Leave empty to rebuild main." + required: false + default: "" + +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || inputs.version || github.ref }} + cancel-in-progress: true + +env: + # doc-builder commit used for the build. docs_builder_update.yml opens an issue + # when huggingface/doc-builder moves ahead of it. + DOC_BUILDER_SHA: 07d98817a2624c1fe067d4268e1f80d1988cfe71 + # Set the DOCS_SITE_URL repository variable when moving to a custom domain. + ROOT_URL: ${{ vars.DOCS_SITE_URL || 'https://openenv.github.io/OpenEnv' }} + +jobs: + build: + # Labeling a PR only rebuilds it for the docs-preview label (see docs_pr_preview.yml). + if: github.event.action != 'labeled' || github.event.label.name == 'docs-preview' + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + dest: ${{ steps.target.outputs.dest }} + publish: ${{ steps.target.outputs.publish }} + steps: + - name: Pick the target + id: target + env: + EVENT: ${{ github.event_name }} + PR_NUMBER: ${{ github.event.pull_request.number }} + INPUT_VERSION: ${{ inputs.version }} + run: | + if [ "$EVENT" = pull_request ]; then + version=main dest="pr-preview/pr-$PR_NUMBER" label="PR #$PR_NUMBER" ref="$GITHUB_SHA" publish=false + elif [ -n "$INPUT_VERSION" ]; then + version="$INPUT_VERSION" dest="$INPUT_VERSION" label="$INPUT_VERSION" ref="refs/tags/$INPUT_VERSION" + elif [ "$GITHUB_REF_TYPE" = tag ]; then + version="$GITHUB_REF_NAME" dest="$GITHUB_REF_NAME" label="$GITHUB_REF_NAME" ref="$GITHUB_SHA" + else + version=main dest=main label=main ref="$GITHUB_SHA" + fi + if [[ ! "$version" =~ ^(main|v[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + echo "::error::Not a release tag: $version" + exit 1 + fi + if [ "$EVENT" != pull_request ]; then + # Only main publishes (a manual run from another branch only builds). + if [ "$GITHUB_REF" = refs/heads/main ] || [ "$GITHUB_REF_TYPE" = tag ]; then publish=true; else publish=false; fi + versions_url="$ROOT_URL/versions.json" + fi + { + echo "version=$version" + echo "dest=$dest" + echo "label=$label" + echo "ref=$ref" + echo "publish=$publish" + echo "versions_url=${versions_url:-}" + } >> "$GITHUB_OUTPUT" + + # doc-builder derives the "Update on GitHub" links from this folder name. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ steps.target.outputs.ref }} + path: OpenEnv + persist-credentials: false + + # Site scripts come from this commit, so older release tags can be rebuilt. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: tools + sparse-checkout: docs/pages + persist-credentials: false + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: huggingface/doc-builder + ref: ${{ env.DOC_BUILDER_SHA }} + path: doc-builder + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: "20" + + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + + - name: Install doc-builder and OpenEnv + run: | + uv venv --python 3.11 + uv pip install ./doc-builder "./OpenEnv[core,cli]" + + - name: Build pages with doc-builder + env: + NODE_OPTIONS: --max-old-space-size=6656 + VERSION: ${{ steps.target.outputs.version }} + run: | + source .venv/bin/activate + cd doc-builder + doc-builder build openenv ../OpenEnv/docs/source \ + --build_dir ../build --html --clean --version "$VERSION" \ + --repo_owner openenv --repo_name OpenEnv --version_tag_suffix "" + + - name: Add the site layout + env: + VERSION: ${{ steps.target.outputs.version }} + DEST: ${{ steps.target.outputs.dest }} + LABEL: ${{ steps.target.outputs.label }} + VERSIONS_URL: ${{ steps.target.outputs.versions_url }} + run: | + source .venv/bin/activate + python tools/docs/pages/build_site.py "build/openenv/$VERSION/en" site \ + --site-url "$ROOT_URL/$DEST" --version-label "$LABEL" \ + ${VERSIONS_URL:+--versions-url "$VERSIONS_URL"} + + - name: Compile the stylesheet + run: | + npm ci --prefix doc-builder/kit --no-audit --no-fund + node tools/docs/pages/build_css.mjs doc-builder/kit site site/docs.css + + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: docs-site + path: site + retention-days: 7 + + publish: + needs: build + if: needs.build.outputs.publish == 'true' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: docs-site + path: site + + - name: Publish to gh-pages + env: + DEST: ${{ needs.build.outputs.dest }} + run: docs/pages/publish.sh "$DEST" site diff --git a/.github/workflows/docs_builder_update.yml b/.github/workflows/docs_builder_update.yml new file mode 100644 index 0000000000..b324034067 --- /dev/null +++ b/.github/workflows/docs_builder_update.yml @@ -0,0 +1,56 @@ +name: doc-builder update check + +# Dependabot cannot see the doc-builder commit pinned in docs.yml (it is not a +# `uses:` reference), so check it weekly and keep one issue open while +# huggingface/doc-builder main is ahead of the pin. + +on: + schedule: + - cron: "0 7 * * 1" + workflow_dispatch: + +permissions: {} + +jobs: + check: + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + TITLE: "Update the pinned doc-builder commit" + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + sparse-checkout: .github/workflows/docs.yml + sparse-checkout-cone-mode: false + persist-credentials: false + + - name: Compare the pin with doc-builder main + run: | + pinned=$(sed -nE 's/^ *DOC_BUILDER_SHA: ([0-9a-f]{40}).*/\1/p' .github/workflows/docs.yml) + latest=$(gh api repos/huggingface/doc-builder/commits/main --jq .sha) + issue=$(gh issue list -R "$REPO" --state open --search "\"$TITLE\" in:title" \ + --json number,title --jq "map(select(.title == \"$TITLE\")) | .[0].number // empty") + if [ "$pinned" = "$latest" ]; then + echo "doc-builder pin is up to date" + if [ -n "$issue" ]; then + gh issue close "$issue" -R "$REPO" --comment "The pin now matches doc-builder main." + fi + exit 0 + fi + ahead=$(gh api "repos/huggingface/doc-builder/compare/$pinned...$latest" --jq .ahead_by) + body="huggingface/doc-builder main is $ahead commit(s) ahead of the commit pinned in \`.github/workflows/docs.yml\`. + + - Pinned: \`$pinned\` + - Latest: \`$latest\` + - Changes: https://github.com/huggingface/doc-builder/compare/$pinned...$latest + + To update, set \`DOC_BUILDER_SHA\` in \`.github/workflows/docs.yml\` to the latest commit and check the docs preview on the pull request. This issue closes on its own once the pin matches." + if [ -n "$issue" ]; then + gh issue edit "$issue" -R "$REPO" --body "$body" + else + gh issue create -R "$REPO" --title "$TITLE" --body "$body" + fi diff --git a/.github/workflows/docs_pr_preview.yml b/.github/workflows/docs_pr_preview.yml new file mode 100644 index 0000000000..68e544bb87 --- /dev/null +++ b/.github/workflows/docs_pr_preview.yml @@ -0,0 +1,115 @@ +name: Docs PR preview + +# Publishes the docs built by docs.yml for a pull request to +# /pr-preview/pr-N/ and removes them when the pull request closes. +# +# docs.yml builds pull requests without write access (forks included). This +# workflow runs from main with write access and never runs pull request code: it +# only copies the static files the build uploaded. Previews are served from the +# docs domain, so pull requests from outside contributors are published only +# after a maintainer adds the docs-preview label. + +on: + workflow_run: + workflows: [Docs] + types: [completed] + pull_request_target: + types: [closed] + +permissions: {} + +jobs: + publish: + if: >- + github.event_name == 'workflow_run' && + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + permissions: + actions: read + contents: write + pull-requests: write + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + ROOT_URL: ${{ vars.DOCS_SITE_URL || 'https://openenv.github.io/OpenEnv' }} + steps: + - name: Find the pull request + id: pr + env: + HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }} + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + RUN_ID: ${{ github.event.workflow_run.id }} + run: | + # Runs triggered by other labels skip the build and upload nothing. + if ! gh api "repos/$REPO/actions/runs/$RUN_ID/artifacts" --jq '.artifacts[].name' | grep -qx docs-site; then + echo "This run did not build the docs." + exit 0 + fi + pr=$(gh api -X GET "repos/$REPO/pulls" -f state=open -f head="$HEAD_OWNER:$HEAD_BRANCH" \ + | jq --arg sha "$HEAD_SHA" 'map(select(.head.sha == $sha)) | first // empty') + if [ -z "$pr" ]; then + echo "No open pull request at $HEAD_SHA (closed or pushed again)." + exit 0 + fi + echo "number=$(jq -r .number <<<"$pr")" >> "$GITHUB_OUTPUT" + jq -r --arg repo "$REPO" '"trusted=" + ( + .head.repo.full_name == $repo + or (.author_association | IN("OWNER", "MEMBER", "COLLABORATOR")) + or any(.labels[]; .name == "docs-preview") + | tostring)' <<<"$pr" >> "$GITHUB_OUTPUT" + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + if: steps.pr.outputs.trusted == 'true' + + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + if: steps.pr.outputs.trusted == 'true' + with: + name: docs-site + path: site + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Publish the preview + if: steps.pr.outputs.trusted == 'true' + env: + NUMBER: ${{ steps.pr.outputs.number }} + run: docs/pages/publish.sh "pr-preview/pr-$NUMBER" site + + - name: Comment on the pull request + if: steps.pr.outputs.number != '' + env: + NUMBER: ${{ steps.pr.outputs.number }} + TRUSTED: ${{ steps.pr.outputs.trusted }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + run: | + marker="" + if [ "$TRUSTED" = true ]; then + body="$marker + The docs for this pull request are available at $ROOT_URL/pr-preview/pr-$NUMBER/ (commit ${HEAD_SHA:0:7}). The preview may take a minute to update and is removed when the pull request closes." + else + body="$marker + The docs for this pull request built successfully. A maintainer can add the \`docs-preview\` label to publish a preview." + fi + id=$(gh api --paginate "repos/$REPO/issues/$NUMBER/comments" \ + --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1) + if [ -n "$id" ]; then + gh api -X PATCH "repos/$REPO/issues/comments/$id" -f body="$body" >/dev/null + else + gh api "repos/$REPO/issues/$NUMBER/comments" -f body="$body" >/dev/null + fi + + remove: + if: github.event_name == 'pull_request_target' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + # Checks out main, not the pull request. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Remove the preview + env: + NUMBER: ${{ github.event.pull_request.number }} + run: docs/pages/publish.sh "pr-preview/pr-$NUMBER" diff --git a/.github/workflows/upload_pr_documentation.yml b/.github/workflows/upload_pr_documentation.yml deleted file mode 100644 index 53c067b76c..0000000000 --- a/.github/workflows/upload_pr_documentation.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Upload PR Documentation - -on: - workflow_run: - workflows: ["Build PR Documentation"] - types: - - completed - -jobs: - build: - uses: huggingface/doc-builder/.github/workflows/upload_pr_documentation.yml@7b35a31ae9844db8b177ef3ca869184a79d791f8 # main - with: - package_name: openenv - repo_owner: openenv - secrets: - hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }} - comment_bot_app_id: ${{ secrets.COMMENT_BOT_APP_ID }} - comment_bot_secret_pem: ${{ secrets.COMMENT_BOT_SECRET_PEM }} diff --git a/docs/README.md b/docs/README.md index afbab3d9ef..65619521e4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -26,6 +26,29 @@ doc-builder preview openenv docs/source Then open the URL printed in the terminal and navigate to `/index` (usually `http://localhost:5173/index`). +## Publishing to GitHub Pages + +The docs are built with doc-builder in GitHub Actions and published to GitHub Pages from the `gh-pages` branch, with no Hugging Face token: + +| Trigger | Published at | +|---|---| +| Push to `main` | `https://openenv.github.io/OpenEnv/main/` | +| Release tag `vX.Y.Z` | `https://openenv.github.io/OpenEnv/vX.Y.Z/` | +| Pull request | `https://openenv.github.io/OpenEnv/pr-preview/pr-N/`, linked from a comment on the PR and removed when it closes | + +The site root redirects to `main`, and the version picker in the header lists `main` and every published release. To publish an older release, run the **Docs** workflow from `main` with its tag as `version`. + +Pull requests from outside contributors build without write access and get a preview only after a maintainer adds the `docs-preview` label, since previews are served from the docs domain. + +How it fits together: + +- [`docs.yml`](../.github/workflows/docs.yml) builds the docs and publishes `main` and releases. +- [`docs_pr_preview.yml`](../.github/workflows/docs_pr_preview.yml) publishes and removes PR previews. It runs from `main` and only copies the files the PR build uploaded. +- [`docs_builder_update.yml`](../.github/workflows/docs_builder_update.yml) checks every week whether `huggingface/doc-builder` moved ahead of the commit pinned in `docs.yml` and keeps an issue open until the pin is updated. +- doc-builder renders each page as a fragment that huggingface.co wraps in its own layout, so [`docs/pages/`](pages/) adds that layout. `build_site.py` wraps each page with a sidebar from `_toctree.yml`, an "On this page" list, the version picker and redirect pages from `_redirects.yml`. `build_css.mjs` compiles the doc-builder stylesheet, which doc-builder leaves empty in production builds. `shell.css` styles the layout and the code highlighting. `publish.sh` updates one folder of `gh-pages`. + +To build the site locally, clone [doc-builder](https://github.com/huggingface/doc-builder) at the commit pinned in `docs.yml` next to this repo and run the steps of the `build` job. + ## Adding an Environment to the Docs Every environment page is generated from the environment's own `README.md`. There are three steps: diff --git a/docs/pages/build_css.mjs b/docs/pages/build_css.mjs new file mode 100644 index 0000000000..9b23865bd1 --- /dev/null +++ b/docs/pages/build_css.mjs @@ -0,0 +1,47 @@ +// Compile the doc-builder kit stylesheet for the standalone GitHub Pages site. +// +// doc-builder empties every CSS file in production builds (kit/postcss.config.cjs) +// because huggingface.co injects its own Tailwind. Outside the Hub we need that +// CSS back, so this script runs the kit's own `src/app.css` through Tailwind, +// scanning the already built pages so only the classes in use are emitted. +// +// Usage: node build_css.mjs +// The kit's node_modules must be installed (`npm ci` inside the kit). + +import { readFileSync, writeFileSync } from "node:fs"; +import { createRequire } from "node:module"; +import path from "node:path"; + +const [kitArg, siteArg, outArg] = process.argv.slice(2); +if (!kitArg || !siteArg || !outArg) { + console.error("usage: node build_css.mjs "); + process.exit(2); +} +const kitDir = path.resolve(kitArg); +const siteDir = path.resolve(siteArg); +const outFile = path.resolve(outArg); + +// Resolve postcss and plugins from the kit's node_modules, not from this repo. +const kitRequire = createRequire(path.join(kitDir, "package.json")); +const postcss = kitRequire("postcss"); +const tailwind = kitRequire("@tailwindcss/postcss"); +const autoprefixer = kitRequire("autoprefixer"); + +const entry = path.join(kitDir, "src", "app.css"); +let css = readFileSync(entry, "utf8"); + +// The kit scans `./routes`, which only exists while doc-builder builds. +// Scan the built HTML and JS chunks instead. +const sourceLine = '@source "./routes";'; +if (!css.includes(sourceLine)) { + console.error(`expected ${sourceLine} in ${entry}; the kit changed, update this script`); + process.exit(1); +} +css = css.replace(sourceLine, `@source "${siteDir.replaceAll("\\", "/")}";`); + +const result = await postcss([tailwind({ base: kitDir }), autoprefixer]).process(css, { + from: entry, + to: outFile, +}); +writeFileSync(outFile, result.css); +console.log(`wrote ${outFile} (${(result.css.length / 1024).toFixed(0)} KiB)`); diff --git a/docs/pages/build_site.py b/docs/pages/build_site.py new file mode 100644 index 0000000000..52e190271c --- /dev/null +++ b/docs/pages/build_site.py @@ -0,0 +1,238 @@ +"""Turn a doc-builder HTML build into a standalone static site for GitHub Pages. + +doc-builder renders each page as a fragment that huggingface.co wraps in its own +shell (navbar, sidebar, styles). This script adds that shell: a full HTML +document per page with a sidebar built from `_toctree.yml`, an "On this page" +list, the stylesheet compiled by `build_css.mjs`, and redirect pages from +`_redirects.yml`. + +Usage: + python docs/pages/build_site.py \ + --site-url https://openenv.github.io/OpenEnv/main --version-label main \ + --versions-url https://openenv.github.io/OpenEnv/versions.json +""" + +import argparse +import html +import json +import re +import shutil +from pathlib import Path +from urllib.parse import urlparse + +import yaml + +DOC_BUILDER_BASE = "/docs/openenv/main/en" +HUB_DOCS_URL = "https://huggingface.co/docs/openenv/main" +REPO_URL = "https://github.com/openenv/OpenEnv" +SHELL_DIR = Path(__file__).parent + +METADATA_RE = re.compile(r'') +CSS_PRELOAD_RE = re.compile(r'\n?') + + +def page_url(base: str, local: str) -> str: + return f"{base}/" if local == "index" else f"{base}/{local}" + + +def render_sidebar(sections: list, base: str, current: str) -> tuple[str, bool]: + """Returns the sidebar HTML for `sections` and whether it contains `current`.""" + items, has_current = [], False + for section in sections: + if "sections" in section: + inner, inner_current = render_sidebar(section["sections"], base, current) + has_current |= inner_current + is_open = inner_current or section.get("isExpanded", True) + items.append( + f"
  • " + f"{html.escape(section['title'])}{inner}
  • " + ) + else: + is_current = section["local"] == current + has_current |= is_current + items.append( + f'
  • " + f"{html.escape(section['title'])}
  • " + ) + return f"
      {''.join(items)}
    ", has_current + + +def render_toc(sections: list) -> str: + items = [] + for section in sections: + sub = render_toc(section["sections"]) if section.get("depth", 2) < 3 else "" + items.append( + f'
  • {html.escape(section["title"])}{sub}
  • ' + ) + return f"
      {''.join(items)}
    " if items else "" + + +VERSION_SCRIPT = """""" + + +def render_version(version: str, versions_url: str | None, local: str) -> str: + """Version picker when the site lists its versions, a plain label otherwise.""" + if not versions_url: + return f'{html.escape(version)}' + page = "" if local in {"index", "404"} else local + return ( + f'" + ) + + +def render_page( + fragment: str, + toctree: list, + base: str, + local: str, + version: str, + versions_url: str | None, +) -> str: + match = METADATA_RE.search(fragment) + metadata = json.loads(html.unescape(match.group(1))) if match else {} + title = metadata.get("title", "OpenEnv") + sidebar, _ = render_sidebar(toctree, base, local) + toc = render_toc(metadata.get("sections", [])) + toc_block = ( + f'' if toc else "" + ) + # The kit's CSS files are empty in production builds, build_css.mjs compiles the real one. + fragment = CSS_PRELOAD_RE.sub("", fragment) + return f""" + + + + +{html.escape(title)} | OpenEnv + + + + + + + + + + +
    + +
    +
    +{fragment} +
    +
    +{toc_block} +
    +{VERSION_SCRIPT if versions_url else ""} + + +""" + + +def redirect_page(target: str) -> str: + return f""" + +Redirecting + + +Moved to {target} +""" + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument( + "build_dir", type=Path, help="doc-builder output, e.g. build/openenv/main/en" + ) + parser.add_argument("output_dir", type=Path) + parser.add_argument( + "--site-url", required=True, help="e.g. https://openenv.github.io/OpenEnv" + ) + parser.add_argument( + "--version-label", default="main", help="e.g. main, v0.15.0, PR #12" + ) + parser.add_argument( + "--versions-url", help="versions.json listing the published versions" + ) + args = parser.parse_args() + site_url = args.site_url.rstrip("/") + base = urlparse(site_url).path + + shutil.rmtree(args.output_dir, ignore_errors=True) + shutil.copytree(args.build_dir, args.output_dir) + out = args.output_dir + toctree = yaml.safe_load((out / "_toctree.yml").read_text()) + + for path in out.rglob("*"): + if path.suffix in {".md", ".txt"}: + text = path.read_text(encoding="utf-8") + text = text.replace(HUB_DOCS_URL, site_url).replace( + DOC_BUILDER_BASE, site_url + ) + path.write_text(text, encoding="utf-8") + if path.suffix not in {".html", ".js"}: + continue + text = path.read_text(encoding="utf-8").replace(DOC_BUILDER_BASE, base) + if path.suffix == ".html": + local = path.relative_to(out).with_suffix("").as_posix() + text = render_page( + text, toctree, base, local, args.version_label, args.versions_url + ) + path.write_text(text, encoding="utf-8") + + redirects = yaml.safe_load((out / "_redirects.yml").read_text()) or {} + for source, target in redirects.items(): + page = out / f"{source}.html" + if not page.exists(): + page.parent.mkdir(parents=True, exist_ok=True) + page.write_text(redirect_page(page_url(base, target)), encoding="utf-8") + + (out / "404.html").write_text( + render_page( + "

    Page not found

    This page does not exist. " + f'Go back to the OpenEnv docs.

    ', + toctree, + base, + "404", + args.version_label, + args.versions_url, + ), + encoding="utf-8", + ) + shutil.copy(SHELL_DIR / "shell.css", out / "shell.css") + (out / ".nojekyll").touch() + print(f"site written to {out}") + + +if __name__ == "__main__": + main() diff --git a/docs/pages/publish.sh b/docs/pages/publish.sh new file mode 100755 index 0000000000..692ecb456e --- /dev/null +++ b/docs/pages/publish.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Publish a built docs site to a folder of the gh-pages branch, or remove that folder. +# +# publish.sh main site/ # docs for main +# publish.sh v0.15.0 site/ # docs for a release +# publish.sh pr-preview/pr-123 site/ # PR preview +# publish.sh pr-preview/pr-123 # remove a PR preview +# +# Run from a checkout of this repo whose credentials can push. gh-pages is kept as +# a single commit so it does not grow with every publish. --force-with-lease makes +# concurrent publishes retry on top of each other instead of overwriting. +set -euo pipefail + +dest=$1 +site=${2:-} +if [[ ! "$dest" =~ ^(main|v[0-9]+\.[0-9]+\.[0-9]+|pr-preview/pr-[0-9]+)$ ]]; then + echo "refusing to publish to '$dest'" >&2 + exit 1 +fi +if [ -n "$site" ]; then + site=$(cd "$site" && pwd) +fi + +pages=$(mktemp -d)/gh-pages +git config user.name "github-actions[bot]" +git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + +for attempt in 1 2 3 4 5; do + git worktree remove --force "$pages" 2>/dev/null || true + if git ls-remote --exit-code --heads origin gh-pages >/dev/null; then + git fetch --quiet --depth 1 origin gh-pages + lease=$(git rev-parse FETCH_HEAD) + git worktree add --quiet --detach "$pages" FETCH_HEAD + else + lease="" + git worktree add --quiet --detach "$pages" + git -C "$pages" rm -rq --ignore-unmatch . + fi + + rm -rf "${pages:?}/$dest" + if [ -n "$site" ]; then + mkdir -p "$(dirname "$pages/$dest")" + cp -R "$site" "$pages/$dest" + fi + + # Root files: version list for the version picker, redirect to main, shared 404. + python3 - "$pages" <<'EOF' +import json, re, shutil, sys +from pathlib import Path + +pages = Path(sys.argv[1]) +releases = [p.name for p in pages.iterdir() if re.fullmatch(r"v\d+\.\d+\.\d+", p.name)] +releases.sort(key=lambda v: [int(x) for x in v[1:].split(".")], reverse=True) +versions = (["main"] if (pages / "main").is_dir() else []) + releases +(pages / "versions.json").write_text(json.dumps(versions) + "\n") +(pages / "index.html").write_text( + '\n\nOpenEnv docs\n' + '\nOpenEnv docs\n' +) +if (pages / "main" / "404.html").exists(): + shutil.copy(pages / "main" / "404.html", pages / "404.html") +(pages / ".nojekyll").touch() +EOF + + git -C "$pages" add -A + tree=$(git -C "$pages" write-tree) + if [ -n "$lease" ] && [ "$tree" = "$(git rev-parse "$lease^{tree}")" ]; then + echo "gh-pages already up to date" + exit 0 + fi + commit=$(git commit-tree "$tree" -m "Publish docs ($dest)") + if git push --force-with-lease="refs/heads/gh-pages:$lease" origin "$commit:refs/heads/gh-pages"; then + echo "updated $dest" + exit 0 + fi + echo "gh-pages moved, retrying ($attempt)" + sleep $((attempt * 5)) +done +echo "could not publish $dest" >&2 +exit 1 diff --git a/docs/pages/shell.css b/docs/pages/shell.css new file mode 100644 index 0000000000..647a45f9c5 --- /dev/null +++ b/docs/pages/shell.css @@ -0,0 +1,274 @@ +/* Shell around the doc-builder pages: header, sidebar, "On this page" list and + code colors. The page content itself is styled by docs.css (build_css.mjs). */ + +:root { + --shell-bg: #ffffff; + --shell-fg: #1f2937; + --shell-muted: #6b7280; + --shell-border: #e5e7eb; + --shell-hover: #f3f4f6; + --shell-accent: #2563eb; + --hl-keyword: #cf222e; + --hl-string: #0a3069; + --hl-number: #0550ae; + --hl-comment: #6e7781; + --hl-title: #8250df; + --hl-builtin: #953800; +} + +html.dark { + --shell-bg: #0b0f19; + --shell-fg: #e5e7eb; + --shell-muted: #9ca3af; + --shell-border: #1f2937; + --shell-hover: #141c2e; + --shell-accent: #60a5fa; + --hl-keyword: #ff7b72; + --hl-string: #a5d6ff; + --hl-number: #79c0ff; + --hl-comment: #8b949e; + --hl-title: #d2a8ff; + --hl-builtin: #ffa657; +} + +html, +body { + margin: 0; + background: var(--shell-bg); + color: var(--shell-fg); + font-family: "Source Sans 3", "Source Sans Pro", system-ui, sans-serif; +} + +.site-header { + position: sticky; + top: 0; + z-index: 20; + display: flex; + align-items: center; + gap: 1rem; + height: 3.5rem; + padding: 0 1rem; + background: var(--shell-bg); + border-bottom: 1px solid var(--shell-border); +} + +.site-header a { + color: var(--shell-fg); + text-decoration: none; +} + +.site-title { + font-size: 1.15rem; + font-weight: 700; +} + +.version-select, +.version-badge { + border: 1px solid var(--shell-border); + border-radius: 0.375rem; + background: var(--shell-bg); + color: var(--shell-muted); + padding: 0.1rem 0.5rem; + font-size: 0.85rem; +} + +.version-select { + width: auto; + padding-right: 2rem; +} + +.site-header .spacer { + flex: 1; +} + +.site-header button { + border: 1px solid var(--shell-border); + border-radius: 0.375rem; + background: none; + color: var(--shell-fg); + padding: 0.15rem 0.5rem; + font-size: 1rem; +} + +.menu-button { + display: none; +} + +.site-layout { + display: flex; + align-items: flex-start; +} + +.site-nav, +.page-toc { + position: sticky; + top: 3.5rem; + flex-shrink: 0; + max-height: calc(100vh - 3.5rem); + overflow-y: auto; + box-sizing: border-box; + font-size: 0.94rem; +} + +.site-nav { + width: 270px; + padding: 1rem 0.75rem 2rem; + border-right: 1px solid var(--shell-border); +} + +.site-nav ul, +.page-toc ul { + list-style: none; + margin: 0; + padding: 0; +} + +.site-nav ul ul { + padding-left: 0.75rem; +} + +.site-nav summary { + cursor: pointer; + padding: 0.3rem 0.5rem; + font-weight: 600; +} + +.site-nav > ul > li > details > summary { + margin-top: 0.5rem; + color: var(--shell-muted); + font-size: 0.8rem; + text-transform: uppercase; + letter-spacing: 0.04em; +} + +.site-nav a { + display: block; + padding: 0.25rem 0.5rem; + border-radius: 0.375rem; + color: var(--shell-muted); + text-decoration: none; +} + +.site-nav a:hover { + background: var(--shell-hover); + color: var(--shell-fg); +} + +.site-nav a[aria-current="page"] { + background: var(--shell-hover); + color: var(--shell-fg); + font-weight: 600; +} + +.site-main { + flex: 1; + min-width: 0; + padding: 1.5rem 1.5rem 4rem; +} + +.page-toc { + width: 250px; + padding: 1.5rem 1rem; +} + +.page-toc p { + margin: 0 0 0.5rem; + font-weight: 600; +} + +.page-toc ul ul { + padding-left: 0.75rem; +} + +.page-toc a { + display: block; + padding: 0.15rem 0; + color: var(--shell-muted); + text-decoration: none; +} + +.page-toc a:hover { + color: var(--shell-accent); +} + +/* docs.css hardcodes light text colors that huggingface.co overrides in dark mode. */ +html.dark .prose.prose-doc :is(h1, h2, h3, h4, h5, th, code, strong) { + color: #e5e7eb; +} + +html.dark .prose.prose-doc > p > em { + color: var(--shell-muted); +} + +html.dark .prose.prose-doc .code-block pre { + border-color: var(--shell-border); +} + +.hljs-keyword, +.hljs-selector-tag, +.hljs-meta .hljs-keyword { + color: var(--hl-keyword); +} + +.hljs-string, +.hljs-regexp, +.hljs-attr { + color: var(--hl-string); +} + +.hljs-number, +.hljs-literal, +.hljs-variable, +.hljs-params { + color: var(--hl-number); +} + +.hljs-comment, +.hljs-quote { + color: var(--hl-comment); + font-style: italic; +} + +.hljs-title, +.hljs-section, +.hljs-name { + color: var(--hl-title); +} + +.hljs-built_in, +.hljs-type, +.hljs-symbol { + color: var(--hl-builtin); +} + +@media (max-width: 1200px) { + .page-toc { + display: none; + } +} + +@media (max-width: 768px) { + .menu-button { + display: inline-block; + } + + .site-nav { + display: none; + position: fixed; + top: 3.5rem; + left: 0; + bottom: 0; + z-index: 10; + width: 100%; + max-height: none; + background: var(--shell-bg); + } + + body.nav-open .site-nav { + display: block; + } + + .site-main { + padding: 1rem 1rem 3rem; + } +} From 34f26d13c32f474c1223bd4f7c8c7115556f7c97 Mon Sep 17 00:00:00 2001 From: sergiopaniego Date: Wed, 25 Nov 2026 11:43:16 +0100 Subject: [PATCH 02/11] Do not rebuild the docs when a pull request is labeled Label events shared the build's concurrency group, so a bot adding labels cancelled the build in progress and the labeled run then skipped itself. Maintainers re-run the Docs check after adding docs-preview instead. --- .github/workflows/docs.yml | 3 --- .github/workflows/docs_pr_preview.yml | 10 ++-------- docs/README.md | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0a59aa001c..b1c4cf8f60 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,7 +16,6 @@ on: tags: - "v[0-9]+.[0-9]+.[0-9]+" pull_request: - types: [opened, synchronize, reopened, labeled] paths: - "docs/**" - "src/openenv/**" @@ -43,8 +42,6 @@ env: jobs: build: - # Labeling a PR only rebuilds it for the docs-preview label (see docs_pr_preview.yml). - if: github.event.action != 'labeled' || github.event.label.name == 'docs-preview' runs-on: ubuntu-latest permissions: contents: read diff --git a/.github/workflows/docs_pr_preview.yml b/.github/workflows/docs_pr_preview.yml index 68e544bb87..5cfcef3f3a 100644 --- a/.github/workflows/docs_pr_preview.yml +++ b/.github/workflows/docs_pr_preview.yml @@ -7,7 +7,7 @@ name: Docs PR preview # workflow runs from main with write access and never runs pull request code: it # only copies the static files the build uploaded. Previews are served from the # docs domain, so pull requests from outside contributors are published only -# after a maintainer adds the docs-preview label. +# after a maintainer adds the docs-preview label and re-runs their Docs check. on: workflow_run: @@ -40,13 +40,7 @@ jobs: HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }} HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} HEAD_SHA: ${{ github.event.workflow_run.head_sha }} - RUN_ID: ${{ github.event.workflow_run.id }} run: | - # Runs triggered by other labels skip the build and upload nothing. - if ! gh api "repos/$REPO/actions/runs/$RUN_ID/artifacts" --jq '.artifacts[].name' | grep -qx docs-site; then - echo "This run did not build the docs." - exit 0 - fi pr=$(gh api -X GET "repos/$REPO/pulls" -f state=open -f head="$HEAD_OWNER:$HEAD_BRANCH" \ | jq --arg sha "$HEAD_SHA" 'map(select(.head.sha == $sha)) | first // empty') if [ -z "$pr" ]; then @@ -90,7 +84,7 @@ jobs: The docs for this pull request are available at $ROOT_URL/pr-preview/pr-$NUMBER/ (commit ${HEAD_SHA:0:7}). The preview may take a minute to update and is removed when the pull request closes." else body="$marker - The docs for this pull request built successfully. A maintainer can add the \`docs-preview\` label to publish a preview." + The docs for this pull request built successfully. A maintainer can publish a preview by adding the \`docs-preview\` label and re-running the Docs check." fi id=$(gh api --paginate "repos/$REPO/issues/$NUMBER/comments" \ --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1) diff --git a/docs/README.md b/docs/README.md index 65619521e4..2c562de47f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,7 +38,7 @@ The docs are built with doc-builder in GitHub Actions and published to GitHub Pa The site root redirects to `main`, and the version picker in the header lists `main` and every published release. To publish an older release, run the **Docs** workflow from `main` with its tag as `version`. -Pull requests from outside contributors build without write access and get a preview only after a maintainer adds the `docs-preview` label, since previews are served from the docs domain. +Pull requests from outside contributors build without write access and get a preview only after a maintainer adds the `docs-preview` label and re-runs the PR's **Docs** check, since previews are served from the docs domain. How it fits together: From 4c9b6ee94572ca2ca7417d4978e8ea1506634031 Mon Sep 17 00:00:00 2001 From: sergiopaniego Date: Wed, 25 Nov 2026 12:27:34 +0100 Subject: [PATCH 03/11] Rewrite doc-builder paths for release builds, not only main doc-builder links pages under /docs/openenv//en, so the prefix is now taken from the build folder. Release builds kept the huggingface.co paths in links and script imports before. --- docs/pages/build_site.py | 13 ++++-- tests/scripts/test_docs_pages_build_site.py | 51 +++++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tests/scripts/test_docs_pages_build_site.py diff --git a/docs/pages/build_site.py b/docs/pages/build_site.py index 52e190271c..79246dfddc 100644 --- a/docs/pages/build_site.py +++ b/docs/pages/build_site.py @@ -22,8 +22,6 @@ import yaml -DOC_BUILDER_BASE = "/docs/openenv/main/en" -HUB_DOCS_URL = "https://huggingface.co/docs/openenv/main" REPO_URL = "https://github.com/openenv/OpenEnv" SHELL_DIR = Path(__file__).parent @@ -187,6 +185,11 @@ def main() -> None: args = parser.parse_args() site_url = args.site_url.rstrip("/") base = urlparse(site_url).path + # doc-builder writes to /openenv//en and links pages under the + # same path on huggingface.co. + version = args.build_dir.resolve().parent.name + doc_builder_base = f"/docs/openenv/{version}/en" + hub_docs_url = f"https://huggingface.co/docs/openenv/{version}" shutil.rmtree(args.output_dir, ignore_errors=True) shutil.copytree(args.build_dir, args.output_dir) @@ -196,13 +199,13 @@ def main() -> None: for path in out.rglob("*"): if path.suffix in {".md", ".txt"}: text = path.read_text(encoding="utf-8") - text = text.replace(HUB_DOCS_URL, site_url).replace( - DOC_BUILDER_BASE, site_url + text = text.replace(hub_docs_url, site_url).replace( + doc_builder_base, site_url ) path.write_text(text, encoding="utf-8") if path.suffix not in {".html", ".js"}: continue - text = path.read_text(encoding="utf-8").replace(DOC_BUILDER_BASE, base) + text = path.read_text(encoding="utf-8").replace(doc_builder_base, base) if path.suffix == ".html": local = path.relative_to(out).with_suffix("").as_posix() text = render_page( diff --git a/tests/scripts/test_docs_pages_build_site.py b/tests/scripts/test_docs_pages_build_site.py new file mode 100644 index 0000000000..5c51e0d52d --- /dev/null +++ b/tests/scripts/test_docs_pages_build_site.py @@ -0,0 +1,51 @@ +"""Regression checks for the GitHub Pages docs site built from doc-builder output.""" + +import importlib.util +import sys +from pathlib import Path + +import pytest + +spec = importlib.util.spec_from_file_location( + "build_site", Path(__file__).parents[2] / "docs" / "pages" / "build_site.py" +) +build_site = importlib.util.module_from_spec(spec) +spec.loader.exec_module(build_site) + + +@pytest.mark.parametrize("version", ["main", "v1.2.3"]) +def test_rewrites_doc_builder_paths_for_every_version(tmp_path, monkeypatch, version): + build = tmp_path / "build" / "openenv" / version / "en" + (build / "_app").mkdir(parents=True) + hub_base = f"/docs/openenv/{version}/en" + (build / "_toctree.yml").write_text( + "- title: Get Started\n sections:\n - local: index\n title: Overview\n" + ) + (build / "_redirects.yml").write_text("old-page: index\n") + (build / "index.html").write_text( + '' + f'core' + f'' + ) + (build / "_app" / "start.js").write_text(f'const base = "{hub_base}";') + (build / "llms.txt").write_text( + f"- [Overview](https://huggingface.co/docs/openenv/{version}/index.md)\n" + ) + out = tmp_path / "site" + site_url = f"https://example.github.io/OpenEnv/{version}" + monkeypatch.setattr( + sys, "argv", ["build_site.py", str(build), str(out), "--site-url", site_url] + ) + + build_site.main() + + for path in out.rglob("*"): + if path.is_file(): + assert "/docs/openenv/" not in path.read_text(), path + page = (out / "index.html").read_text() + assert f'href="/OpenEnv/{version}/reference/core#x"' in page + assert f'import("/OpenEnv/{version}/_app/start.js")' in page + assert 'class="site-nav"' in page + assert f'"/OpenEnv/{version}"' in (out / "_app" / "start.js").read_text() + assert f"{site_url}/index.md" in (out / "llms.txt").read_text() + assert f"url=/OpenEnv/{version}/" in (out / "old-page.html").read_text() From 66f526faa2b836f4f803f8de3867e7cae280df0f Mon Sep 17 00:00:00 2001 From: sergiopaniego Date: Wed, 25 Nov 2026 12:58:31 +0100 Subject: [PATCH 04/11] Tighten PR previews and fix API source links - The docs-preview label approves one commit: the preview workflow removes it after publishing, so later pushes from outside contributors need a new review. - Publishing and removing the preview of the same pull request no longer run in parallel, so a preview published while the pull request closes is still removed. - API reference source links point to src/openenv/ (doc-builder's default suffix) instead of a path that does not exist. - Changes to pyproject.toml and uv.lock rebuild the docs on pull requests, since the build installs the package for autodoc. --- .github/workflows/docs.yml | 4 +++- .github/workflows/docs_pr_preview.yml | 27 +++++++++++++++++++++------ docs/README.md | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b1c4cf8f60..6d00251cce 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -19,6 +19,8 @@ on: paths: - "docs/**" - "src/openenv/**" + - "pyproject.toml" + - "uv.lock" - ".github/workflows/docs.yml" workflow_dispatch: inputs: @@ -124,7 +126,7 @@ jobs: cd doc-builder doc-builder build openenv ../OpenEnv/docs/source \ --build_dir ../build --html --clean --version "$VERSION" \ - --repo_owner openenv --repo_name OpenEnv --version_tag_suffix "" + --repo_owner openenv --repo_name OpenEnv - name: Add the site layout env: diff --git a/.github/workflows/docs_pr_preview.yml b/.github/workflows/docs_pr_preview.yml index 5cfcef3f3a..ec45e7b36f 100644 --- a/.github/workflows/docs_pr_preview.yml +++ b/.github/workflows/docs_pr_preview.yml @@ -8,6 +8,7 @@ name: Docs PR preview # only copies the static files the build uploaded. Previews are served from the # docs domain, so pull requests from outside contributors are published only # after a maintainer adds the docs-preview label and re-runs their Docs check. +# The label is removed once used, so each new commit needs a new review. on: workflow_run: @@ -18,6 +19,13 @@ on: permissions: {} +# Publishing and removing the preview of the same pull request run one at a time, +# so a preview published while its pull request closes is still removed. +concurrency: + group: >- + ${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name || github.event.pull_request.head.repo.full_name }}:${{ github.event.workflow_run.head_branch || github.event.pull_request.head.ref }} + cancel-in-progress: false + jobs: publish: if: >- @@ -48,11 +56,11 @@ jobs: exit 0 fi echo "number=$(jq -r .number <<<"$pr")" >> "$GITHUB_OUTPUT" - jq -r --arg repo "$REPO" '"trusted=" + ( - .head.repo.full_name == $repo - or (.author_association | IN("OWNER", "MEMBER", "COLLABORATOR")) - or any(.labels[]; .name == "docs-preview") - | tostring)' <<<"$pr" >> "$GITHUB_OUTPUT" + jq -r --arg repo "$REPO" ' + (.head.repo.full_name == $repo or (.author_association | IN("OWNER", "MEMBER", "COLLABORATOR"))) as $member + | any(.labels[]; .name == "docs-preview") as $label + | "trusted=\($member or $label)\nlabel_only=\(($member | not) and $label)" + ' <<<"$pr" >> "$GITHUB_OUTPUT" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 if: steps.pr.outputs.trusted == 'true' @@ -71,6 +79,13 @@ jobs: NUMBER: ${{ steps.pr.outputs.number }} run: docs/pages/publish.sh "pr-preview/pr-$NUMBER" site + # The label approves one commit: later pushes need a maintainer to add it again. + - name: Remove the docs-preview label + if: steps.pr.outputs.label_only == 'true' + env: + NUMBER: ${{ steps.pr.outputs.number }} + run: gh api -X DELETE "repos/$REPO/issues/$NUMBER/labels/docs-preview" >/dev/null + - name: Comment on the pull request if: steps.pr.outputs.number != '' env: @@ -84,7 +99,7 @@ jobs: The docs for this pull request are available at $ROOT_URL/pr-preview/pr-$NUMBER/ (commit ${HEAD_SHA:0:7}). The preview may take a minute to update and is removed when the pull request closes." else body="$marker - The docs for this pull request built successfully. A maintainer can publish a preview by adding the \`docs-preview\` label and re-running the Docs check." + The docs for this pull request built successfully. A maintainer can publish a preview of this commit by adding the \`docs-preview\` label and re-running the Docs check." fi id=$(gh api --paginate "repos/$REPO/issues/$NUMBER/comments" \ --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1) diff --git a/docs/README.md b/docs/README.md index 2c562de47f..656e0c3c88 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,7 +38,7 @@ The docs are built with doc-builder in GitHub Actions and published to GitHub Pa The site root redirects to `main`, and the version picker in the header lists `main` and every published release. To publish an older release, run the **Docs** workflow from `main` with its tag as `version`. -Pull requests from outside contributors build without write access and get a preview only after a maintainer adds the `docs-preview` label and re-runs the PR's **Docs** check, since previews are served from the docs domain. +Pull requests from outside contributors build without write access and get a preview only after a maintainer adds the `docs-preview` label and re-runs the PR's **Docs** check, since previews are served from the docs domain. The label is removed once the preview is published, so each new commit needs a new review. How it fits together: From 7a48c73964d29d682ab5bc45f16c2f6e652563de Mon Sep 17 00:00:00 2001 From: sergiopaniego Date: Wed, 25 Nov 2026 14:44:28 +0100 Subject: [PATCH 05/11] TEMPORARY: publish the docs preview of this pull request Revert before merging. docs_pr_preview.yml only runs from main, so this job publishes the preview of #1728 from the pull request itself. --- .github/workflows/docs.yml | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 6d00251cce..0827b85f5e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -169,3 +169,42 @@ jobs: env: DEST: ${{ needs.build.outputs.dest }} run: docs/pages/publish.sh "$DEST" site + + # TEMPORARY, remove before merging: publishes the preview of this pull request + # (#1728) from the pull request itself, since docs_pr_preview.yml only runs + # once it is on main. Same-repo branch, so the token can write. + temp-preview-pr-1728: + needs: build + if: github.event_name == 'pull_request' && github.event.pull_request.number == 1728 && github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: docs-site + path: site + + - name: Publish the preview + run: docs/pages/publish.sh pr-preview/pr-1728 site + + - name: Comment on the pull request + env: + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + marker="" + body="$marker + The docs for this pull request are available at $ROOT_URL/pr-preview/pr-1728/ (commit ${HEAD_SHA:0:7}). The preview may take a minute to update and is removed when the pull request closes." + id=$(gh api --paginate "repos/$REPO/issues/1728/comments" \ + --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n 1) + if [ -n "$id" ]; then + gh api -X PATCH "repos/$REPO/issues/comments/$id" -f body="$body" >/dev/null + else + gh api "repos/$REPO/issues/1728/comments" -f body="$body" >/dev/null + fi From 3b15db7d859da1106bca7f53d46b0dca28b1fc1d Mon Sep 17 00:00:00 2001 From: sergiopaniego Date: Wed, 25 Nov 2026 14:59:23 +0100 Subject: [PATCH 06/11] Add the OpenEnv icon, link previews and noindex for PR previews - Favicon and touch icon drawn from the OpenEnv cube logo, replacing the Svelte icon doc-builder ships with its kit. - Description, Open Graph and Twitter tags on every page, with a social card cropped from the OpenEnv banner, so shared links get a preview. - PR previews are marked noindex so search engines only index main and releases. - Page titles that already name OpenEnv no longer repeat it. - Hide doc-builder's Connect to MCP Client entry, which points to the huggingface.co docs server. --- .github/workflows/docs.yml | 6 +- docs/pages/apple-touch-icon.png | Bin 0 -> 3720 bytes docs/pages/build_site.py | 82 ++++++++++++++------ docs/pages/favicon.png | Bin 0 -> 1039 bytes docs/pages/favicon.svg | 7 ++ docs/pages/og-image.png | Bin 0 -> 62782 bytes docs/pages/shell.css | 6 ++ tests/scripts/test_docs_pages_build_site.py | 9 ++- 8 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 docs/pages/apple-touch-icon.png create mode 100644 docs/pages/favicon.png create mode 100644 docs/pages/favicon.svg create mode 100644 docs/pages/og-image.png diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0827b85f5e..8fc9c4e129 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -59,7 +59,7 @@ jobs: INPUT_VERSION: ${{ inputs.version }} run: | if [ "$EVENT" = pull_request ]; then - version=main dest="pr-preview/pr-$PR_NUMBER" label="PR #$PR_NUMBER" ref="$GITHUB_SHA" publish=false + version=main dest="pr-preview/pr-$PR_NUMBER" label="PR #$PR_NUMBER" ref="$GITHUB_SHA" publish=false noindex=true elif [ -n "$INPUT_VERSION" ]; then version="$INPUT_VERSION" dest="$INPUT_VERSION" label="$INPUT_VERSION" ref="refs/tags/$INPUT_VERSION" elif [ "$GITHUB_REF_TYPE" = tag ]; then @@ -83,6 +83,7 @@ jobs: echo "ref=$ref" echo "publish=$publish" echo "versions_url=${versions_url:-}" + echo "noindex=${noindex:-}" } >> "$GITHUB_OUTPUT" # doc-builder derives the "Update on GitHub" links from this folder name. @@ -134,11 +135,12 @@ jobs: DEST: ${{ steps.target.outputs.dest }} LABEL: ${{ steps.target.outputs.label }} VERSIONS_URL: ${{ steps.target.outputs.versions_url }} + NOINDEX: ${{ steps.target.outputs.noindex }} run: | source .venv/bin/activate python tools/docs/pages/build_site.py "build/openenv/$VERSION/en" site \ --site-url "$ROOT_URL/$DEST" --version-label "$LABEL" \ - ${VERSIONS_URL:+--versions-url "$VERSIONS_URL"} + ${VERSIONS_URL:+--versions-url "$VERSIONS_URL"} ${NOINDEX:+--noindex} - name: Compile the stylesheet run: | diff --git a/docs/pages/apple-touch-icon.png b/docs/pages/apple-touch-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c1da695f3e57180c87d35e6778266ff310be3f42 GIT binary patch literal 3720 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') CSS_PRELOAD_RE = re.compile(r'\n?') +PARAGRAPH_RE = re.compile(r"]*>(.*?)

    ", re.S) +# Icons and social card, copied to the site root. +ASSETS = ["favicon.svg", "favicon.png", "apple-touch-icon.png", "og-image.png"] + + +@dataclasses.dataclass +class Site: + url: str # e.g. https://openenv.github.io/OpenEnv/main + base: str # URL path of the site, e.g. /OpenEnv/main + toctree: list + version: str + versions_url: str | None + noindex: bool def page_url(base: str, local: str) -> str: @@ -94,18 +108,25 @@ def render_version(version: str, versions_url: str | None, local: str) -> str: ) -def render_page( - fragment: str, - toctree: list, - base: str, - local: str, - version: str, - versions_url: str | None, -) -> str: +def page_description(fragment: str) -> str: + """First paragraph of the page as plain text, for search and link previews.""" + for paragraph in PARAGRAPH_RE.findall(fragment): + text = " ".join(html.unescape(re.sub(r"<[^>]+>", "", paragraph)).split()) + if text: + return text if len(text) <= 200 else text[:197].rsplit(" ", 1)[0] + "..." + return "" + + +def render_page(fragment: str, local: str, site: Site) -> str: match = METADATA_RE.search(fragment) metadata = json.loads(html.unescape(match.group(1))) if match else {} title = metadata.get("title", "OpenEnv") - sidebar, _ = render_sidebar(toctree, base, local) + if "OpenEnv" not in title: + title = f"{title} | OpenEnv" + title = html.escape(title) + description = html.escape(page_description(fragment)) + base = site.base + sidebar, _ = render_sidebar(site.toctree, base, local) toc = render_toc(metadata.get("sections", [])) toc_block = ( f'' if toc else "" @@ -117,8 +138,19 @@ def render_page( -{html.escape(title)} | OpenEnv - +{title} + +{'' if site.noindex else ""} + + + + + + + + + + @@ -137,7 +169,7 @@ def render_page(