fix: use file for curl data to avoid argument list too long
This commit is contained in:
parent
92526feba2
commit
9647054b67
@ -238,14 +238,19 @@ jobs:
|
|||||||
SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7)
|
SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7)
|
||||||
DEST_PATH="reports/grade_report_${SHORT_SHA}.${REPORT_FILE##*.}"
|
DEST_PATH="reports/grade_report_${SHORT_SHA}.${REPORT_FILE##*.}"
|
||||||
|
|
||||||
# Base64 编码
|
# Base64 编码并保存到临时文件(避免命令行参数过长)
|
||||||
CONTENT=$(base64 -w 0 "$REPORT_FILE")
|
CONTENT=$(base64 -w 0 "$REPORT_FILE")
|
||||||
|
|
||||||
|
# 创建请求 JSON 文件
|
||||||
|
cat > /tmp/upload_request.json << EOF
|
||||||
|
{"message": "Add grade report for $SHORT_SHA", "content": "$CONTENT"}
|
||||||
|
EOF
|
||||||
|
|
||||||
# 先尝试 POST 创建新文件
|
# 先尝试 POST 创建新文件
|
||||||
RESULT=$(curl -s -X POST -H "Authorization: token $TOKEN" \
|
RESULT=$(curl -s -X POST -H "Authorization: token $TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
"$API_URL/repos/$REPO/contents/$DEST_PATH" \
|
"$API_URL/repos/$REPO/contents/$DEST_PATH" \
|
||||||
-d "{\"message\": \"Add grade report for $SHORT_SHA\", \"content\": \"$CONTENT\"}")
|
-d @/tmp/upload_request.json)
|
||||||
|
|
||||||
if echo "$RESULT" | grep -q '"content"'; then
|
if echo "$RESULT" | grep -q '"content"'; then
|
||||||
echo "✅ Report uploaded to $DEST_PATH"
|
echo "✅ Report uploaded to $DEST_PATH"
|
||||||
@ -257,10 +262,15 @@ jobs:
|
|||||||
| python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('sha','') if isinstance(d,dict) and 'sha' in d else '')" 2>/dev/null || echo "")
|
| python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('sha','') if isinstance(d,dict) and 'sha' in d else '')" 2>/dev/null || echo "")
|
||||||
|
|
||||||
if [ -n "$SHA" ]; then
|
if [ -n "$SHA" ]; then
|
||||||
|
# 创建更新请求 JSON 文件
|
||||||
|
cat > /tmp/upload_request.json << EOF
|
||||||
|
{"message": "Update grade report for $SHORT_SHA", "content": "$CONTENT", "sha": "$SHA"}
|
||||||
|
EOF
|
||||||
|
|
||||||
RESULT=$(curl -s -X PUT -H "Authorization: token $TOKEN" \
|
RESULT=$(curl -s -X PUT -H "Authorization: token $TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
"$API_URL/repos/$REPO/contents/$DEST_PATH" \
|
"$API_URL/repos/$REPO/contents/$DEST_PATH" \
|
||||||
-d "{\"message\": \"Update grade report for $SHORT_SHA\", \"content\": \"$CONTENT\", \"sha\": \"$SHA\"}")
|
-d @/tmp/upload_request.json)
|
||||||
|
|
||||||
if echo "$RESULT" | grep -q '"content"'; then
|
if echo "$RESULT" | grep -q '"content"'; then
|
||||||
echo "✅ Report updated at $DEST_PATH"
|
echo "✅ Report updated at $DEST_PATH"
|
||||||
@ -271,6 +281,9 @@ jobs:
|
|||||||
echo "⚠️ Could not get file SHA, upload failed"
|
echo "⚠️ Could not get file SHA, upload failed"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 清理临时文件
|
||||||
|
rm -f /tmp/upload_request.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Create metadata
|
- name: Create metadata
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user