From 7a28dbdb244ed90b3e99e7821501712df3cf5b6a Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Mon, 6 Oct 2025 22:20:39 +0800 Subject: [PATCH 1/2] [CI] Add Report Preview URLs Workflow --- .github/workflows/preview-url-comment.yml | 58 ++++++++++++++++++++++ .github/workflows/preview-url-generate.yml | 52 +++++++++++++++++++ ci_scripts/report_preview_url.sh | 42 ++++++++++++++++ docs/api/paddle/abs_cn.rst | 2 +- docs/api/paddle/amax_cn.rst | 2 +- 5 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/preview-url-comment.yml create mode 100644 .github/workflows/preview-url-generate.yml create mode 100644 ci_scripts/report_preview_url.sh diff --git a/.github/workflows/preview-url-comment.yml b/.github/workflows/preview-url-comment.yml new file mode 100644 index 00000000000..830013a1eb0 --- /dev/null +++ b/.github/workflows/preview-url-comment.yml @@ -0,0 +1,58 @@ +name: Comment Preview URLs + +on: + workflow_run: + workflows: ["Generate Preview URLs"] + types: + - completed + +jobs: + comment: + name: Post Preview URLs Comment + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + permissions: + pull-requests: write + + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Read PR metadata + id: pr-metadata + run: | + PR_NUMBER=$(find . -name "pr_number.txt" -exec cat {} \;) + PR_SHA=$(find . -name "pr_sha.txt" -exec cat {} \;) + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT + echo "pr_sha=$PR_SHA" >> $GITHUB_OUTPUT + + - name: Read preview URLs + id: preview-urls + run: | + PREVIEW_CONTENT=$(find . -name "preview_urls.txt" -exec cat {} \;) + { + echo 'content<> $GITHUB_OUTPUT + + - name: Find existing comment + uses: peter-evans/find-comment@v4 + id: fc + with: + issue-number: ${{ steps.pr-metadata.outputs.pr_number }} + comment-author: 'github-actions[bot]' + body-includes: '本次 PR 文档预览链接' + + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ steps.pr-metadata.outputs.pr_number }} + body: ${{ steps.preview-urls.outputs.content }} + edit-mode: replace diff --git a/.github/workflows/preview-url-generate.yml b/.github/workflows/preview-url-generate.yml new file mode 100644 index 00000000000..e12f9b74056 --- /dev/null +++ b/.github/workflows/preview-url-generate.yml @@ -0,0 +1,52 @@ +name: Generate Preview URLs + +on: + pull_request: + branches: ["develop"] + paths: + - 'docs/**.rst' + - 'docs/**.md' + +jobs: + generate-urls: + name: Generate Preview URLs + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Fetch base branch + run: | + git fetch origin develop:develop + + - name: Generate preview URLs + id: generate + run: | + chmod +x ci_scripts/report_preview_url.sh + ./ci_scripts/report_preview_url.sh ${{ github.event.pull_request.number }} > preview_urls.txt + + - name: Upload preview URLs as artifact + uses: actions/upload-artifact@v4 + with: + name: preview-urls-${{ github.event.pull_request.number }} + path: preview_urls.txt + retention-days: 1 + + - name: Save PR metadata + run: | + echo "${{ github.event.pull_request.number }}" > pr_number.txt + echo "${{ github.event.pull_request.head.sha }}" > pr_sha.txt + + - name: Upload PR metadata + uses: actions/upload-artifact@v4 + with: + name: pr-metadata-${{ github.event.pull_request.number }} + path: | + pr_number.txt + pr_sha.txt + retention-days: 1 diff --git a/ci_scripts/report_preview_url.sh b/ci_scripts/report_preview_url.sh new file mode 100644 index 00000000000..993bd53da18 --- /dev/null +++ b/ci_scripts/report_preview_url.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +pr_id="$1" + +if [ -z "$pr_id" ]; then + echo "Error: Pull Request ID is not provided." + exit 1 +fi + +generate_preview_url() { + local file_path="$1" + local pr_id="$2" + local path_no_ext="${file_path%.*}" + local base_url="http://preview-pr-${pr_id}.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/" + local final_url="${base_url}${path_no_ext}.html" + echo "$final_url" +} + +mapfile -t all_git_files < <(git diff --name-only --diff-filter=ACMR develop | sed 's#^docs/##') + +output_lines=() + +for file in "${all_git_files[@]}"; do + if [[ "$file" == *.rst || "$file" == *.md ]]; then + url=$(generate_preview_url "$file" "$pr_id") + output_lines+=("- \`docs/${file}\`: [点击预览](${url})") + fi +done + + +if [ ${#output_lines[@]} -gt 0 ]; then + cat <<-EOF +
+📚 本次 PR 文档预览链接 (点击展开) + +以下是本次 PR 中变更文档的预览链接: + +$(printf '%s\n' "${output_lines[@]}") + +
+EOF +fi diff --git a/docs/api/paddle/abs_cn.rst b/docs/api/paddle/abs_cn.rst index 83fa2c88d48..5baa79658a6 100644 --- a/docs/api/paddle/abs_cn.rst +++ b/docs/api/paddle/abs_cn.rst @@ -15,7 +15,7 @@ abs 参数 ::::::::: - - **x** (Tensor) - 输入的 Tensor,数据类型为:int32、int64、float16、float32、float64、complex64、complex128。 + - **x** (Tensor) - 输入的 Tensor,数据类型为:int32、int64、float16、float32、float64、complex64 和 complex128。 - **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 返回 diff --git a/docs/api/paddle/amax_cn.rst b/docs/api/paddle/amax_cn.rst index 238a1a0bd9b..ae20e11b9ab 100644 --- a/docs/api/paddle/amax_cn.rst +++ b/docs/api/paddle/amax_cn.rst @@ -15,7 +15,7 @@ amax 参数 ::::::::: - - **x** (Tensor) - Tensor,支持数据类型为 float32、float64、int32、int64,维度不超过 4 维。 + - **x** (Tensor) - Tensor,支持数据类型为 float32、float64、int32 和 int64,维度不超过 4 维。 ``别名:input`` - **axis** (int|list|tuple,可选) - 求最大值运算的维度。如果为 None,则计算所有元素的最大值并返回包含单个元素的 Tensor 变量,否则必须在 :math:`[-x.ndim, x.ndim]` 范围内。如果 :math:`axis[i] <0`,则维度将变为 :math:`x.ndim+axis[i]`,默认值为 None。 ``别名:dim`` From fd6eddd58d6a2f77e912efacf0d6807581618c15 Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Tue, 7 Oct 2025 14:38:08 +0800 Subject: [PATCH 2/2] revert api doc change --- docs/api/paddle/abs_cn.rst | 2 +- docs/api/paddle/amax_cn.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/paddle/abs_cn.rst b/docs/api/paddle/abs_cn.rst index 5baa79658a6..83fa2c88d48 100644 --- a/docs/api/paddle/abs_cn.rst +++ b/docs/api/paddle/abs_cn.rst @@ -15,7 +15,7 @@ abs 参数 ::::::::: - - **x** (Tensor) - 输入的 Tensor,数据类型为:int32、int64、float16、float32、float64、complex64 和 complex128。 + - **x** (Tensor) - 输入的 Tensor,数据类型为:int32、int64、float16、float32、float64、complex64、complex128。 - **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 返回 diff --git a/docs/api/paddle/amax_cn.rst b/docs/api/paddle/amax_cn.rst index ae20e11b9ab..238a1a0bd9b 100644 --- a/docs/api/paddle/amax_cn.rst +++ b/docs/api/paddle/amax_cn.rst @@ -15,7 +15,7 @@ amax 参数 ::::::::: - - **x** (Tensor) - Tensor,支持数据类型为 float32、float64、int32 和 int64,维度不超过 4 维。 + - **x** (Tensor) - Tensor,支持数据类型为 float32、float64、int32、int64,维度不超过 4 维。 ``别名:input`` - **axis** (int|list|tuple,可选) - 求最大值运算的维度。如果为 None,则计算所有元素的最大值并返回包含单个元素的 Tensor 变量,否则必须在 :math:`[-x.ndim, x.ndim]` 范围内。如果 :math:`axis[i] <0`,则维度将变为 :math:`x.ndim+axis[i]`,默认值为 None。 ``别名:dim``