forked from PaddlePaddle/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport_preview_url.sh
More file actions
63 lines (49 loc) · 1.84 KB
/
report_preview_url.sh
File metadata and controls
63 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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%.*}"
# Check if file ends with _en (English version)
# _en.rst will only reach English preview, _en.md can be reached in both English and Chinese previews
# To Simplify, we treat all _en files as English version
if [[ "$path_no_ext" == *_en ]]; then
local base_url="http://preview-pr-${pr_id}.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/en/"
else
# Use /zh/ path for Chinese version
local base_url="http://preview-pr-${pr_id}.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/"
fi
local final_url="${base_url}${path_no_ext}.html"
echo "$final_url"
}
# Use merge-base to find the common ancestor between PR branch and develop
# This ensures we only get changes from this PR, excluding commits merged to develop after PR creation
BASE_COMMIT=$(git merge-base HEAD develop 2>/dev/null || echo "develop")
mapfile -t all_git_files < <(git diff --name-only --diff-filter=ACMR "$BASE_COMMIT" | 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>
<table>
<tr>
<td>
ℹ️ <b>预览提醒</b><br>
请等待 <code>Docs-NEW</code> 流水线运行完成后再点击预览链接,否则可能会看到旧版本内容或遇到链接无法访问的情况。
</td>
</tr>
</table>
$(printf '%s\n' "${output_lines[@]}")
</details>
EOF
fi