Skip to content

Commit a856f38

Browse files
authored
[CI] 完善ci脚本,优化映射文档生成代码 (#7556)
* 第二类自动生成(未完成),完善ci脚本 * 添加一列映射分类,精简分类简介 * 修改CI * 更新映射文档分类简介,添加第二类api示例 * 优化CI和示例写法
1 parent 5af11be commit a856f38

File tree

5 files changed

+1573
-1171
lines changed

5 files changed

+1573
-1171
lines changed

ci_scripts/hooks/pre-doc-compile.sh

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,14 @@ API_MAPPING_URL="https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master
2626
GLOBAL_VAR_URL="https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/global_var.py"
2727
ATTRIBUTE_MAPPING_URL="https://raw.githubusercontent.com/PaddlePaddle/PaConvert/master/paconvert/attribute_mapping.json"
2828

29-
# Define backup URLs
30-
BACKUP_API_ALIAS_MAPPING_URL="https://paddle-paconvert.bj.bcebos.com/api_alias_mapping.json"
31-
BACKUP_API_MAPPING_URL="https://paddle-paconvert.bj.bcebos.com/api_mapping.json"
32-
BACKUP_GLOBAL_VAR_URL="https://paddle-paconvert.bj.bcebos.com/global_var.py"
33-
BACKUP_ATTRIBUTE_MAPPING_URL="https://paddle-paconvert.bj.bcebos.com/attribute_mapping.json"
34-
3529
# Check for proxy settings
3630
PROXY=""
3731
if [ -n "$https_proxy" ]; then
3832
PROXY="$https_proxy"
39-
echo "INFO: find proxy"
33+
echo "INFO: Using proxy"
4034
elif [ -n "$http_proxy" ]; then
4135
PROXY="$http_proxy"
42-
echo "INFO: find proxy"
36+
echo "INFO: Using proxy"
4337
else
4438
echo "INFO: No proxy detected, downloading directly."
4539
fi
@@ -51,12 +45,28 @@ else
5145
CURL_PROXY_ARGS=""
5246
fi
5347

54-
# Download API mapping files with retry
48+
# Handle failure: copy cached file and exit
49+
handle_failure() {
50+
local cached_file="${APIMAPPING_ROOT}/cached_pytorch_api_mapping_cn.md"
51+
local target_file="${APIMAPPING_ROOT}/pytorch_api_mapping_cn.md"
52+
53+
if [ -f "$cached_file" ]; then
54+
echo "INFO: Copying cached file to target: $cached_file -> $target_file"
55+
cp "$cached_file" "$target_file"
56+
echo "INFO: Successfully copied cached file to $target_file"
57+
exit 0
58+
else
59+
echo "ERROR: Cached file not found at $cached_file"
60+
exit 1
61+
fi
62+
}
63+
64+
# Download file with retry and failure handling
5565
download_file() {
5666
local url=$1
5767
local dest=$2
5868
local filename=$(basename "$dest")
59-
local max_retries=5
69+
local max_retries=3
6070
local retry_count=0
6171

6272
echo "INFO: Starting download of ${filename} from ${url}"
@@ -75,70 +85,38 @@ download_file() {
7585
done
7686

7787
echo "ERROR: Failed to download ${filename} after $max_retries attempts"
78-
return 1
88+
handle_failure
7989
}
8090

81-
# Download each file with detailed logging
82-
echo "INFO: Downloading API alias mapping file"
83-
if ! download_file "${API_ALIAS_MAPPING_URL}" "${TOOLS_DIR}/api_alias_mapping.json"; then
84-
echo "INFO: Trying backup URL for API alias mapping file"
85-
if ! download_file "${BACKUP_API_ALIAS_MAPPING_URL}" "${TOOLS_DIR}/api_alias_mapping.json"; then
86-
echo "ERROR: API alias mapping download failed (both main and backup URLs). Exiting."
87-
exit 1
88-
fi
89-
fi
90-
91-
echo "INFO: Downloading API mapping file"
92-
if ! download_file "${API_MAPPING_URL}" "${TOOLS_DIR}/api_mapping.json"; then
93-
echo "INFO: Trying backup URL for API mapping file"
94-
if ! download_file "${BACKUP_API_MAPPING_URL}" "${TOOLS_DIR}/api_mapping.json"; then
95-
echo "ERROR: API mapping download failed (both main and backup URLs). Exiting."
96-
exit 1
97-
fi
98-
fi
99-
100-
echo "INFO: Downloading global variable file"
101-
if ! download_file "${GLOBAL_VAR_URL}" "${TOOLS_DIR}/global_var.py"; then
102-
echo "INFO: Trying backup URL for global variable file"
103-
if ! download_file "${BACKUP_GLOBAL_VAR_URL}" "${TOOLS_DIR}/global_var.py"; then
104-
echo "ERROR: Global variable download failed (both main and backup URLs). Exiting."
105-
exit 1
106-
fi
107-
fi
108-
109-
echo "INFO: Downloading attribute mapping file"
110-
if ! download_file "${ATTRIBUTE_MAPPING_URL}" "${TOOLS_DIR}/attribute_mapping.json"; then
111-
echo "INFO: Trying backup URL for attribute mapping file"
112-
if ! download_file "${BACKUP_ATTRIBUTE_MAPPING_URL}" "${TOOLS_DIR}/attribute_mapping.json"; then
113-
echo "ERROR: Attribute mapping download failed (both main and backup URLs). Exiting."
114-
exit 1
115-
fi
116-
fi
117-
118-
# Check if all files exist before proceeding
119-
if [ ! -f "${TOOLS_DIR}/api_alias_mapping.json" ] || \
120-
[ ! -f "${TOOLS_DIR}/api_mapping.json" ] || \
121-
[ ! -f "${TOOLS_DIR}/global_var.py" ] || \
122-
[ ! -f "${TOOLS_DIR}/attribute_mapping.json" ]; then
123-
echo "ERROR: One or more API mapping files are missing after download"
124-
echo "Missing files:"
125-
if [ ! -f "${TOOLS_DIR}/api_alias_mapping.json" ]; then echo " - api_alias_mapping.json"; fi
126-
if [ ! -f "${TOOLS_DIR}/api_mapping.json" ]; then echo " - api_mapping.json"; fi
127-
if [ ! -f "${TOOLS_DIR}/global_var.py" ]; then echo " - global_var.py"; fi
128-
if [ ! -f "${TOOLS_DIR}/attribute_mapping.json" ]; then echo " - attribute_mapping.json"; fi
129-
exit 1
130-
fi
91+
# Download all API mapping files
92+
download_file "${API_ALIAS_MAPPING_URL}" "${TOOLS_DIR}/api_alias_mapping.json"
93+
download_file "${API_MAPPING_URL}" "${TOOLS_DIR}/api_mapping.json"
94+
download_file "${GLOBAL_VAR_URL}" "${TOOLS_DIR}/global_var.py"
95+
download_file "${ATTRIBUTE_MAPPING_URL}" "${TOOLS_DIR}/attribute_mapping.json"
13196

13297
echo "INFO: All API mapping files successfully downloaded"
13398

99+
# Run the remaining scripts with failure handling
134100
echo "INFO: Running get_api_difference_info.py"
135101
if ! python "${APIMAPPING_ROOT}/tools/get_api_difference_info.py"; then
136-
echo "ERROR: get_api_difference_info.py failed. Please check the script."
137-
exit 1
102+
handle_failure
138103
fi
139104

140105
echo "INFO: Running generate_pytorch_api_mapping.py"
141106
if ! python "${APIMAPPING_ROOT}/tools/generate_pytorch_api_mapping.py"; then
142-
echo "ERROR: generate_pytorch_api_mapping.py failed. Please check the script."
143-
exit 1
107+
handle_failure
108+
fi
109+
110+
# Create backup of generated file
111+
BACKUP_FILE="${APIMAPPING_ROOT}/cached_pytorch_api_mapping_cn.md"
112+
GENERATED_FILE="${APIMAPPING_ROOT}/pytorch_api_mapping_cn.md"
113+
114+
if [ -f "$GENERATED_FILE" ]; then
115+
echo "INFO: Generated API mapping file successfully created at $GENERATED_FILE"
116+
echo "INFO: Creating backup file: $BACKUP_FILE"
117+
cp "$GENERATED_FILE" "$BACKUP_FILE"
118+
echo "INFO: Successfully created backup file at $BACKUP_FILE"
119+
else
120+
echo "ERROR: Generated API mapping file not found at $GENERATED_FILE"
121+
handle_failure
144122
fi

0 commit comments

Comments
 (0)