Skip to content
Draft
Show file tree
Hide file tree
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
58 changes: 58 additions & 0 deletions .github/workflows/preview-url-comment.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF'
echo "$PREVIEW_CONTENT"
echo EOF
} >> $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
52 changes: 52 additions & 0 deletions .github/workflows/preview-url-generate.yml
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions ci_scripts/report_preview_url.sh
Original file line number Diff line number Diff line change
@@ -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
<details>
<summary>📚 本次 PR 文档预览链接 (点击展开)</summary>

以下是本次 PR 中变更文档的预览链接:

$(printf '%s\n' "${output_lines[@]}")

</details>
EOF
fi
2 changes: 1 addition & 1 deletion docs/api/paddle/abs_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abs

参数
:::::::::
- **x** (Tensor) - 输入的 Tensor,数据类型为:int32、int64、float16、float32、float64、complex64complex128。
- **x** (Tensor) - 输入的 Tensor,数据类型为:int32、int64、float16、float32、float64、complex64complex128。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。

返回
Expand Down
2 changes: 1 addition & 1 deletion docs/api/paddle/amax_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ amax

参数
:::::::::
- **x** (Tensor) - Tensor,支持数据类型为 float32、float64、int32int64,维度不超过 4 维。
- **x** (Tensor) - Tensor,支持数据类型为 float32、float64、int32int64,维度不超过 4 维。
``别名:input``
- **axis** (int|list|tuple,可选) - 求最大值运算的维度。如果为 None,则计算所有元素的最大值并返回包含单个元素的 Tensor 变量,否则必须在 :math:`[-x.ndim, x.ndim]` 范围内。如果 :math:`axis[i] <0`,则维度将变为 :math:`x.ndim+axis[i]`,默认值为 None。
``别名:dim``
Expand Down