fix: use per-directory API calls to avoid large response truncation
Some checks failed
Deploy to Server / deploy (push) Failing after 10m2s
Some checks failed
Deploy to Server / deploy (push) Failing after 10m2s
This commit is contained in:
@@ -24,28 +24,37 @@ jobs:
|
||||
echo $SUDO_PASSWORD | sudo -S docker compose down
|
||||
|
||||
echo "===== 通过 API 下载代码 ====="
|
||||
# 获取文件树
|
||||
FILE_LIST=$(curl -sk -u "$AUTH" "$API_BASE/repos/$REPO/git/trees/$BRANCH?recursive=true" | python3 -c "
|
||||
|
||||
# 递归下载目录函数
|
||||
download_dir() {
|
||||
local dir_path="$1"
|
||||
local api_path="${dir_path:+$dir_path}"
|
||||
local url="$API_BASE/repos/$REPO/contents/${api_path}?ref=$BRANCH&token="
|
||||
local items
|
||||
items=$(curl -sk -u "$AUTH" "$API_BASE/repos/$REPO/contents/${api_path}?ref=$BRANCH")
|
||||
echo "$items" | python3 -c "
|
||||
import json,sys
|
||||
data = json.load(sys.stdin)
|
||||
for item in data.get('tree', []):
|
||||
if item['type'] == 'blob':
|
||||
print(item['path'])
|
||||
")
|
||||
|
||||
echo "共发现 $(echo "$FILE_LIST" | wc -l) 个文件"
|
||||
|
||||
# 逐个下载文件
|
||||
echo "$FILE_LIST" | while read -r filepath; do
|
||||
# 跳过不需要的文件
|
||||
case "$filepath" in
|
||||
backend/.env|backend/media/*|.git/*) continue ;;
|
||||
esac
|
||||
mkdir -p "$TARGET_DIR/$(dirname "$filepath")"
|
||||
curl -sk -u "$AUTH" -o "$TARGET_DIR/$filepath" \
|
||||
"$API_BASE/repos/$REPO/raw/$filepath?ref=$BRANCH"
|
||||
done
|
||||
try:
|
||||
data = json.load(sys.stdin)
|
||||
for item in data:
|
||||
print(item['type'] + '|' + item['path'])
|
||||
except: pass
|
||||
" | while IFS='|' read -r type path; do
|
||||
case "$path" in
|
||||
backend/.env|.git/*) continue ;;
|
||||
esac
|
||||
if [ "$type" = "dir" ]; then
|
||||
mkdir -p "$TARGET_DIR/$path"
|
||||
download_dir "$path"
|
||||
elif [ "$type" = "file" ]; then
|
||||
mkdir -p "$TARGET_DIR/$(dirname "$path")"
|
||||
curl -sk -u "$AUTH" -o "$TARGET_DIR/$path" \
|
||||
"$API_BASE/repos/$REPO/raw/$path?ref=$BRANCH"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
download_dir ""
|
||||
echo "代码更新完成"
|
||||
|
||||
echo "===== 配置环境变量 ====="
|
||||
|
||||
Reference in New Issue
Block a user