gitea API 오류시 재시도 로직 추가
Some checks failed
Git Repository Mirroring / mirror (push) Failing after 31m20s
Some checks failed
Git Repository Mirroring / mirror (push) Failing after 31m20s
This commit is contained in:
@@ -91,10 +91,21 @@ jobs:
|
||||
|
||||
set_default_branch_main() {
|
||||
local repo_name="$1"
|
||||
local response http_status body
|
||||
response=$(curl -s -w "\n%{http_code}" -X PATCH -H "Content-Type: application/json" -H "${AUTH_HEADER}" -d "{\"default_branch\":\"main\"}" "${BASE_GITEA_URL}/api/v1/repos/${CENTER_ORG}/${repo_name}")
|
||||
http_status=$(echo "${response}" | tail -n1)
|
||||
body=$(echo "${response}" | sed '$d')
|
||||
local response http_status body attempt max_api_retry
|
||||
max_api_retry=3
|
||||
attempt=1
|
||||
while (( attempt<=max_api_retry )); do
|
||||
response=$(curl -s -w "\n%{http_code}" -X PATCH -H "Content-Type: application/json" -H "${AUTH_HEADER}" -d "{\"default_branch\":\"main\"}" "${BASE_GITEA_URL}/api/v1/repos/${CENTER_ORG}/${repo_name}")
|
||||
http_status=$(echo "${response}" | tail -n1)
|
||||
body=$(echo "${response}" | sed '$d')
|
||||
if [[ "${http_status}" == "000" || "${http_status}" =~ ^5 || "${http_status}" == "429" ]]; then
|
||||
echo "::warning::Retrying default branch set (HTTP ${http_status}) for ${repo_name} (${attempt}/3)..."
|
||||
sleep 5
|
||||
((attempt++))
|
||||
continue
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
if [[ "${http_status}" != "200" ]]; then
|
||||
echo "::warning::Failed to set default branch to 'main' for ${CENTER_ORG}/${repo_name} (status ${http_status})"
|
||||
@@ -107,7 +118,7 @@ jobs:
|
||||
}
|
||||
|
||||
process_entry() {
|
||||
local entry_raw entry alias_name branch_name source_repo source_repo_url start_epoch backup_mode
|
||||
local entry_raw entry alias_name branch_name source_repo source_repo_url start_epoch backup_mode attempt max_api_retry
|
||||
entry_raw="$1"
|
||||
# Remove inline comments and trim
|
||||
entry="${entry_raw%%#*}"
|
||||
@@ -177,18 +188,39 @@ jobs:
|
||||
# Check if repository exists on Gitea
|
||||
repo_exists=false
|
||||
just_created=false
|
||||
http_status=$(curl -s -o /dev/null -w "%{http_code}" -H "${AUTH_HEADER}" "${BASE_GITEA_URL}/api/v1/repos/${CENTER_ORG}/${repo_name}")
|
||||
max_api_retry=3
|
||||
attempt=1
|
||||
while (( attempt<=max_api_retry )); do
|
||||
http_status=$(curl -s -o /dev/null -w "%{http_code}" -H "${AUTH_HEADER}" "${BASE_GITEA_URL}/api/v1/repos/${CENTER_ORG}/${repo_name}")
|
||||
if [[ "${http_status}" == "000" || "${http_status}" =~ ^5 || "${http_status}" == "429" ]]; then
|
||||
echo "::warning::Repo check HTTP ${http_status} for ${repo_name} (${attempt}/3); retrying in 5s..."
|
||||
sleep 5
|
||||
((attempt++))
|
||||
continue
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
if [ "${http_status}" == "404" ]; then
|
||||
echo "Repository 'center_dev/${repo_name}' does not exist. Creating it..."
|
||||
create_tmp="$(mktemp)"
|
||||
create_status=$(curl -s -o "${create_tmp}" -w "%{http_code}" -X POST -H "Content-Type: application/json" -H "${AUTH_HEADER}" -d "{\"name\":\"${repo_name}\",\"private\":true,\"default_branch\":\"main\"}" "${BASE_GITEA_URL}/api/v1/orgs/${CENTER_ORG}/repos")
|
||||
attempt=1
|
||||
while (( attempt<=max_api_retry )); do
|
||||
create_status=$(curl -s -o "${create_tmp}" -w "%{http_code}" -X POST -H "Content-Type: application/json" -H "${AUTH_HEADER}" -d "{\"name\":\"${repo_name}\",\"private\":true,\"default_branch\":\"main\"}" "${BASE_GITEA_URL}/api/v1/orgs/${CENTER_ORG}/repos")
|
||||
if [[ "${create_status}" == "000" || "${create_status}" =~ ^5 || "${create_status}" == "429" ]]; then
|
||||
echo "::warning::Repo create HTTP ${create_status} for ${repo_name} (${attempt}/3); retrying in 5s..."
|
||||
sleep 5
|
||||
((attempt++))
|
||||
continue
|
||||
fi
|
||||
break
|
||||
done
|
||||
if [[ "${create_status}" != "201" ]]; then
|
||||
echo "::error::Failed to create repository. HTTP ${create_status}"
|
||||
cat "${create_tmp}"
|
||||
rm -f "${create_tmp}"
|
||||
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "repo 생성 실패 (HTTP ${create_status})"
|
||||
exit 1
|
||||
return
|
||||
fi
|
||||
echo "Repository created successfully."
|
||||
repo_exists=true
|
||||
@@ -197,7 +229,7 @@ jobs:
|
||||
elif [ "${http_status}" != "200" ]; then
|
||||
echo "::error::Error checking repository. HTTP status: ${http_status}"
|
||||
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "repo 조회 실패 (HTTP ${http_status})"
|
||||
exit 1
|
||||
return
|
||||
else
|
||||
echo "Repository 'center_dev/${repo_name}' already exists."
|
||||
repo_exists=true
|
||||
|
||||
Reference in New Issue
Block a user