File tree Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Report Preview URLs
2
+
3
+ on :
4
+ pull_request :
5
+ branches : ["develop"]
6
+ paths :
7
+ - ' docs/**.rst'
8
+ - ' docs/**.md'
9
+
10
+ jobs :
11
+ report-urls :
12
+ name : Report Preview URLs
13
+ runs-on : ubuntu-latest
14
+ if : github.repository_owner == 'PaddlePaddle'
15
+
16
+ steps :
17
+ - name : Checkout repository
18
+ uses : actions/checkout@v4
19
+ with :
20
+ fetch-depth : 0
21
+
22
+ - name : Generate comment body
23
+ id : generate-comment
24
+ run : |
25
+ chmod +x ci_scripts/report_preview_url.sh
26
+ echo "comment_body=$(./ci_scripts/report_preview_url.sh ${{ github.event.pull_request.number }})" >> $GITHUB_OUTPUT
27
+
28
+ - name : Post or Update Comment
29
+ uses : peter-evans/find-comment@v4
30
+ id : fc
31
+ with :
32
+ issue-number : ${{ github.event.pull_request.number }}
33
+ comment-author : ' github-actions[bot]'
34
+ body-includes : ' 本次 PR 文档预览链接'
35
+
36
+ - name : Create or Update Comment
37
+ uses : peter-evans/create-or-update-comment@v4
38
+ with :
39
+ comment-id : ${{ steps.fc.outputs.comment-id }}
40
+ issue-number : ${{ github.event.pull_request.number }}
41
+ body : ${{ steps.generate-comment.outputs.comment_body }}
42
+ edit-mode : replace
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ pr_id=" $1 "
4
+
5
+ if [ -z " $pr_id " ]; then
6
+ echo " Error: Pull Request ID is not provided."
7
+ exit 1
8
+ fi
9
+
10
+ generate_preview_url () {
11
+ local file_path=" $1 "
12
+ local pr_id=" $2 "
13
+ local path_no_ext=" ${file_path% .* } "
14
+ local base_url=" http://preview-pr-${pr_id} .paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/"
15
+ local final_url=" ${base_url}${path_no_ext} .html"
16
+ echo " $final_url "
17
+ }
18
+
19
+ mapfile -t all_git_files < <( git diff --name-only --diff-filter=ACMR upstream/develop | sed ' s#^docs/##' )
20
+
21
+ output_lines=()
22
+
23
+ for file in " ${all_git_files[@]} " ; do
24
+ if [[ " $file " == * .rst || " $file " == * .md ]]; then
25
+ url=$( generate_preview_url " $file " " $pr_id " )
26
+ output_lines+=(" - \` docs/${file} \` : [点击预览](${url} )" )
27
+ fi
28
+ done
29
+
30
+ if [ ${# output_lines[@]} -gt 0 ]; then
31
+ cat << -EOF
32
+ <details>
33
+ <summary>📚 本次 PR 文档预览链接 (点击展开)</summary>
34
+
35
+ 以下是本次 PR 中变更文档的预览链接:
36
+
37
+ $( printf ' %s\n' " ${output_lines[@]} " )
38
+
39
+ </details>
40
+ EOF
41
+ fi
You can’t perform that action at this time.
0 commit comments