From a0349c01f76e887ed54de8fc011ff40c3e5a0098 Mon Sep 17 00:00:00 2001 From: luk384090-cloud Date: Mon, 23 Nov 2026 18:29:42 +0800 Subject: [PATCH 1/3] chore(docs): add automated docs build and release notes integration - Introduce GitHub Actions workflow for MkDocs Material site build and deployment - Enable docs build on PRs, pushes to main, and release publishing events - Add hooks.py to provide dynamic substitutions for SDK version and release notes - Implement localized rendering of release notes with support for English and Chinese - Add release-notes.md in English and Chinese with changelog overview and 2.0 highlights - Refine sidebar navigation and prune 404 pages from sitemap for i18n builds - Re-export applications subpackage for improved type checking and documentation cohesion (cherry picked from commit 6368a5bbec1fc05f8fb771d06b0faba53bd66de4) --- .github/workflows/docs.yml | 22 +++++++-- docs/en/release-notes.md | 14 ++---- docs/hooks.py | 92 ++++++++++++++++++++++++++++++++++++-- docs/zh/release-notes.md | 13 ++---- 4 files changed, 113 insertions(+), 28 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 158097b8..5ab082a9 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -2,8 +2,9 @@ name: Docs # FastAPI-style docs pipeline: every PR and main push builds the MkDocs # Material site to validate it; pushes to main additionally deploy the HTML -# to GitHub Pages. Docs track main (latest), independent of the tag-driven -# release.yml flow. +# to GitHub Pages. Publishing a GitHub Release also rebuilds and deploys: +# the Release Notes page renders published releases at build time, so the +# tag-driven release.yml flow refreshes the docs without touching them. on: push: branches: [main] @@ -20,6 +21,8 @@ on: - 'mkdocs.yml' - 'requirements-doc.txt' - '.github/workflows/docs.yml' + release: + types: [published] workflow_dispatch: permissions: @@ -33,7 +36,10 @@ jobs: build: runs-on: ubuntu-latest steps: + # Release events carry a tag ref; docs always track main (latest). - uses: actions/checkout@v4 + with: + ref: ${{ github.event_name == 'release' && 'refs/heads/main' || github.ref }} - uses: actions/setup-python@v5 with: python-version: '3.12' @@ -41,16 +47,24 @@ jobs: # doc toolchain (httpx/pydantic etc. come in as runtime dependencies). - run: python -m pip install -r requirements-doc.txt . - name: Build HTML + # GITHUB_TOKEN lifts the anonymous GitHub API rate limit for the + # release-notes rendering in docs/hooks.py (public data, read-only). + env: + GITHUB_TOKEN: ${{ github.token }} run: mkdocs build --strict - name: Upload site artifact - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + if: >- + (github.event_name == 'push' && github.ref == 'refs/heads/main') + || github.event_name == 'release' uses: actions/upload-pages-artifact@v3 with: path: site deploy: needs: build - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + if: >- + (github.event_name == 'push' && github.ref == 'refs/heads/main') + || github.event_name == 'release' runs-on: ubuntu-latest permissions: pages: write diff --git a/docs/en/release-notes.md b/docs/en/release-notes.md index 580f7980..6e24fdb0 100644 --- a/docs/en/release-notes.md +++ b/docs/en/release-notes.md @@ -5,18 +5,12 @@ description: "Release notes and changelog pointers for the dashscope Python SDK, The authoritative, per-release changelog is published on [GitHub Releases](https://github.com/dashscope/dashscope-sdk-python/releases). -This page summarizes the major lines and links to recent tags. +The recent-releases table below is rendered from GitHub Releases at docs +build time, so it refreshes automatically when a release is published; +each tag links to its full release notes. Current SDK version: **{{ sdk_version }}**. -## Recent releases - -| Tag | Notes | -| --- | --- | -| v2.1.0 | [See release page](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.1.0) | -| v2.0.4 | [See release page](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.0.4) | -| v2.0.3 | [See release page](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.0.3) | -| v2.0.2 | [See release page](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.0.2) | -| v2.0.1 | [See release page](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.0.1) | +{{ release_notes }} ## 2.0 highlights diff --git a/docs/hooks.py b/docs/hooks.py index bbac5edc..a65711ee 100644 --- a/docs/hooks.py +++ b/docs/hooks.py @@ -1,10 +1,18 @@ # -*- coding: utf-8 -*- -"""MkDocs hooks: surface the SDK version from dashscope/version.py in pages. +"""MkDocs hooks: build-time substitution for version and release notes. -Pages opt in with the ``{{ sdk_version }}`` placeholder; the value is read -from the source of truth at build time so docs never drift from the package. +Pages opt in with placeholders; values are read from their source of +truth at build time so docs never drift: + +- ``{{ sdk_version }}`` <- dashscope/version.py +- ``{{ release_notes }}`` <- published GitHub Releases (latest-release + table linking to each release page), so publishing a release is all it + takes to refresh the docs. """ +import json +import os import re +import urllib.request from pathlib import Path from mkdocs.structure.toc import AnchorLink, TableOfContents @@ -12,12 +20,23 @@ # Reference pages listing dozens of API symbols: even a section+symbol # outline floods the sidebar (80-110 entries), so their "On this page" # nav keeps only the h2 section titles. Applies to both locales. +# release-notes.md joins them for a consistent section-only outline. _SECTION_ONLY_TOC_PAGES = { "reference/agentstudio.md", "reference/legacy.md", "reference/resources.md", + "release-notes.md", } +_RELEASES_URL = ( + "https://api.github.com/repos/dashscope/dashscope-sdk-python" + "/releases?per_page=20" +) +_RELEASES_PAGE = "https://github.com/dashscope/dashscope-sdk-python/releases" +_RELEASES_SHOWN = 5 +# Fetch once per build process; the i18n plugin runs two locale passes. +_RELEASES_CACHE = None + # The theme's static 404.html template renders once per i18n pass and the # last (zh) pass overwrites site/404.html, shipping a mixed-language shell. # Stash the en pass render context and reuse it for every later pass. @@ -33,6 +52,63 @@ def _read_version(docs_dir: str) -> str: return match.group(1) if match else "unknown" +def _fetch_releases(): + """Published releases, newest first; None when the API is unreachable. + + Drafts are excluded so the skeleton rendered by release.yml never + leaks into the docs before a maintainer publishes it. GITHUB_TOKEN + (set in CI) only lifts the anonymous rate limit; the data is public. + """ + global _RELEASES_CACHE + if _RELEASES_CACHE is not None: + return _RELEASES_CACHE or None + headers = { + "Accept": "application/vnd.github+json", + "User-Agent": "dashscope-sdk-docs-build", + } + token = os.environ.get("GITHUB_TOKEN") + if token: + headers["Authorization"] = "Bearer " + token + try: + request = urllib.request.Request(_RELEASES_URL, headers=headers) + with urllib.request.urlopen(request, timeout=10) as response: + releases = json.load(response) + releases = [r for r in releases if not r.get("draft")] + releases.sort(key=lambda r: r.get("published_at") or "", reverse=True) + _RELEASES_CACHE = releases + return releases or None + except Exception: + _RELEASES_CACHE = [] + return None + + +def _render_release_notes(lang: str) -> str: + releases = _fetch_releases() + zh = lang == "zh" + if not releases: + return ( + "构建时未能加载 GitHub Releases,完整变更日志请参阅" + f"[GitHub Releases]({_RELEASES_PAGE})。" + if zh + else "Release notes could not be loaded at build time; see " + f"[GitHub Releases]({_RELEASES_PAGE}) for the full changelog." + ) + releases = releases[:_RELEASES_SHOWN] + parts = ["## 近期发布" if zh else "## Recent releases", ""] + parts.append("| Tag | 说明 |" if zh else "| Tag | Notes |") + parts.append("| --- | --- |") + for release in releases: + tag = release.get("tag_name") or "" + if release.get("prerelease"): + tag += "(预发布)" if zh else " (pre-release)" + date = (release.get("published_at") or "")[:10] + label = "发布说明" if zh else "Release notes" + parts.append( + f"| {tag} | {date} · [{label}]({release.get('html_url')}) |" + ) + return "\n".join(parts) + + def on_config(config): config.extra["sdk_version"] = _read_version(config.docs_dir) # mkdocstrings inserts its stylesheet on every per-locale on_config @@ -65,10 +141,18 @@ def on_page_content(html, *, page, config, files): def on_page_markdown(markdown, *, page, config, files): - return markdown.replace( + markdown = markdown.replace( "{{ sdk_version }}", config.extra.get("sdk_version", "unknown"), ) + if "{{ release_notes }}" in markdown: + # i18n folder structure prefixes src_uri with the locale (en/ zh/) + lang = "zh" if page.file.src_uri.startswith("zh/") else "en" + markdown = markdown.replace( + "{{ release_notes }}", + _render_release_notes(lang), + ) + return markdown def _snapshot_404_context(context, config): diff --git a/docs/zh/release-notes.md b/docs/zh/release-notes.md index e80912ff..85344c1d 100644 --- a/docs/zh/release-notes.md +++ b/docs/zh/release-notes.md @@ -5,18 +5,11 @@ description: "dashscope Python SDK 发行说明与变更日志指引,含 2.0 逐版本的权威变更日志发布在 [GitHub Releases](https://github.com/dashscope/dashscope-sdk-python/releases)。 -本页概述主要版本线并链接近期 tag。 +下方近期发布表格在文档构建时从 GitHub Releases 渲染, +发布新版本后会自动刷新;点击各 tag 可查看完整发布说明。 当前 SDK 版本:**{{ sdk_version }}**。 -## 近期发布 - -| Tag | 说明 | -| --- | --- | -| v2.1.0 | [请参阅发布页面](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.1.0) | -| v2.0.4 | [请参阅发布页面](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.0.4) | -| v2.0.3 | [请参阅发布页面](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.0.3) | -| v2.0.2 | [请参阅发布页面](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.0.2) | -| v2.0.1 | [请参阅发布页面](https://github.com/dashscope/dashscope-sdk-python/releases/tag/v2.0.1) | +{{ release_notes }} ## 2.0 亮点 From dd272b4f7ef0be8ad17ff0e402d6fbb906aade95 Mon Sep 17 00:00:00 2001 From: luk384090-cloud Date: Tue, 24 Nov 2026 09:36:52 +0800 Subject: [PATCH 2/3] fix(docs): add missing comma in release notes table formatting (cherry picked from commit e2167a21180a91843b31615526ec8dde7d24df8f) --- docs/hooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hooks.py b/docs/hooks.py index a65711ee..47314033 100644 --- a/docs/hooks.py +++ b/docs/hooks.py @@ -104,7 +104,7 @@ def _render_release_notes(lang: str) -> str: date = (release.get("published_at") or "")[:10] label = "发布说明" if zh else "Release notes" parts.append( - f"| {tag} | {date} · [{label}]({release.get('html_url')}) |" + f"| {tag} | {date} · [{label}]({release.get('html_url')}) |", ) return "\n".join(parts) From 935c7db5b687928a8409beee7352b47bc4e91310 Mon Sep 17 00:00:00 2001 From: luk384090-cloud Date: Tue, 24 Nov 2026 11:52:33 +0800 Subject: [PATCH 3/3] test(cli): add test to verify silence on dumb terminal - Set environment variables to simulate consistent fake TTY behavior in tests - Add test to ensure Rich spinner produces no output on TERM=dumb - Patch sleep function to speed up test execution - Validate that no escape sequences are emitted on dumb terminals during job wait - Ensure text assertions are consistent across different CI and terminal environments --- tests/cli/test_progress.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/cli/test_progress.py b/tests/cli/test_progress.py index 064b454c..ade9a355 100644 --- a/tests/cli/test_progress.py +++ b/tests/cli/test_progress.py @@ -41,6 +41,16 @@ def isatty(self): # sys.stderr patch made during fixture setup. @pytest.fixture def tty_stderr(monkeypatch): + # Rich gates live output on TERM/FORCE_COLOR/TTY_COMPATIBLE as well as + # isatty(); a runner exporting TERM=dumb (CI, sandboxed shells) would + # silence the spinner and fail the text assertions. Pin them so the + # fake TTY behaves identically on every runner; monkeypatch restores + # the process environment afterwards. + monkeypatch.setenv("TERM", "xterm-256color") + monkeypatch.delenv("FORCE_COLOR", raising=False) + monkeypatch.delenv("TTY_COMPATIBLE", raising=False) + monkeypatch.setenv("NO_COLOR", "1") + def install() -> _TtyStderr: stream = _TtyStderr() monkeypatch.setattr("sys.stderr", stream) @@ -187,6 +197,24 @@ def test_repeated_polls_do_not_stack_the_suffix( text = stream.getvalue() assert text.count("elapsed) waiting for") == 0 + def test_dumb_terminal_stays_silent(self, tty_stderr, monkeypatch): + """Rich refuses escape sequences on TERM=dumb; silence is correct.""" + stream = tty_stderr() + monkeypatch.setenv("TERM", "dumb") + monkeypatch.setattr( + "dashscope.cli.progress.time.sleep", + lambda s: None, + ) + waiter = _RecordingWait(result=None) + wait_job( + _client(waiter), + "job-1", + timeout=5, + renderer=Renderer("table"), + ) + waiter.calls[0][1]["_sleep"](0) + assert stream.getvalue() == "" + def test_custom_label(self, tty_stderr, monkeypatch): stream = tty_stderr() monkeypatch.setattr(