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() {
|
set_default_branch_main() {
|
||||||
local repo_name="$1"
|
local repo_name="$1"
|
||||||
local response http_status body
|
local response http_status body attempt max_api_retry
|
||||||
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}")
|
max_api_retry=3
|
||||||
http_status=$(echo "${response}" | tail -n1)
|
attempt=1
|
||||||
body=$(echo "${response}" | sed '$d')
|
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
|
if [[ "${http_status}" != "200" ]]; then
|
||||||
echo "::warning::Failed to set default branch to 'main' for ${CENTER_ORG}/${repo_name} (status ${http_status})"
|
echo "::warning::Failed to set default branch to 'main' for ${CENTER_ORG}/${repo_name} (status ${http_status})"
|
||||||
@@ -107,7 +118,7 @@ jobs:
|
|||||||
}
|
}
|
||||||
|
|
||||||
process_entry() {
|
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"
|
entry_raw="$1"
|
||||||
# Remove inline comments and trim
|
# Remove inline comments and trim
|
||||||
entry="${entry_raw%%#*}"
|
entry="${entry_raw%%#*}"
|
||||||
@@ -177,18 +188,39 @@ jobs:
|
|||||||
# Check if repository exists on Gitea
|
# Check if repository exists on Gitea
|
||||||
repo_exists=false
|
repo_exists=false
|
||||||
just_created=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
|
if [ "${http_status}" == "404" ]; then
|
||||||
echo "Repository 'center_dev/${repo_name}' does not exist. Creating it..."
|
echo "Repository 'center_dev/${repo_name}' does not exist. Creating it..."
|
||||||
create_tmp="$(mktemp)"
|
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
|
if [[ "${create_status}" != "201" ]]; then
|
||||||
echo "::error::Failed to create repository. HTTP ${create_status}"
|
echo "::error::Failed to create repository. HTTP ${create_status}"
|
||||||
cat "${create_tmp}"
|
cat "${create_tmp}"
|
||||||
rm -f "${create_tmp}"
|
rm -f "${create_tmp}"
|
||||||
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "repo 생성 실패 (HTTP ${create_status})"
|
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "repo 생성 실패 (HTTP ${create_status})"
|
||||||
exit 1
|
return
|
||||||
fi
|
fi
|
||||||
echo "Repository created successfully."
|
echo "Repository created successfully."
|
||||||
repo_exists=true
|
repo_exists=true
|
||||||
@@ -197,7 +229,7 @@ jobs:
|
|||||||
elif [ "${http_status}" != "200" ]; then
|
elif [ "${http_status}" != "200" ]; then
|
||||||
echo "::error::Error checking repository. HTTP status: ${http_status}"
|
echo "::error::Error checking repository. HTTP status: ${http_status}"
|
||||||
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "repo 조회 실패 (HTTP ${http_status})"
|
notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "repo 조회 실패 (HTTP ${http_status})"
|
||||||
exit 1
|
return
|
||||||
else
|
else
|
||||||
echo "Repository 'center_dev/${repo_name}' already exists."
|
echo "Repository 'center_dev/${repo_name}' already exists."
|
||||||
repo_exists=true
|
repo_exists=true
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
6) 태그 동기화가 켜져 있으면 태그 fetch/push(강제+prune)
|
6) 태그 동기화가 켜져 있으면 태그 fetch/push(강제+prune)
|
||||||
7) 기본 브랜치를 `main`으로 패치, 임시 디렉터리 정리
|
7) 기본 브랜치를 `main`으로 패치, 임시 디렉터리 정리
|
||||||
8) 소스 서버가 `--shallow-exclude`를 지원하지 않으면 타겟 `main`을 얕게(depth=50) 받아 시드한 뒤 일반 fetch로 재시도
|
8) 소스 서버가 `--shallow-exclude`를 지원하지 않으면 타겟 `main`을 얕게(depth=50) 받아 시드한 뒤 일반 fetch로 재시도
|
||||||
|
9) Gitea API(조회/생성/기본브랜치 설정)는 최대 3회 재시도 후 실패 시 해당 브랜치를 건너뛰고 다음 브랜치로 진행
|
||||||
|
|
||||||
## 알림
|
## 알림
|
||||||
- `NOTIFY_WEBHOOK` 설정 시 시작/성공/실패/건너뛰기 상태를 KST 타임스탬프와 소요시간, 모드(신규/증분)와 함께 전송
|
- `NOTIFY_WEBHOOK` 설정 시 시작/성공/실패/건너뛰기 상태를 KST 타임스탬프와 소요시간, 모드(신규/증분)와 함께 전송
|
||||||
|
|||||||
2
to-do.md
2
to-do.md
@@ -28,3 +28,5 @@
|
|||||||
2025-12-17 08:27:54 KST 추가 업데이트: 스케줄 cron을 UTC 기준임을 명시하고 02:07 KST 실행을 위해 `7 17 * * *`로 설정, 동기화 결과 요약(총/성공/건너뜀/오류) 메시지를 마지막에 출력하고 알림 웹훅으로 전송하도록 추가.
|
2025-12-17 08:27:54 KST 추가 업데이트: 스케줄 cron을 UTC 기준임을 명시하고 02:07 KST 실행을 위해 `7 17 * * *`로 설정, 동기화 결과 요약(총/성공/건너뜀/오류) 메시지를 마지막에 출력하고 알림 웹훅으로 전송하도록 추가.
|
||||||
2025-12-17 08:35:58 KST 추가 업데이트: 소스 서버가 `--shallow-exclude`를 지원하지 않을 때 타겟 main을 depth=50으로 시드한 후 일반 fetch로 재시도하도록 폴백을 추가, README 동작 개요 반영.
|
2025-12-17 08:35:58 KST 추가 업데이트: 소스 서버가 `--shallow-exclude`를 지원하지 않을 때 타겟 main을 depth=50으로 시드한 후 일반 fetch로 재시도하도록 폴백을 추가, README 동작 개요 반영.
|
||||||
2025-12-17 08:48:00 KST 추가 업데이트: 동일 커밋 건너뛰기 시 모드를 “변경 없음”으로 분리하고 shallow-exclude 실패 시 fetch 로그 tail을 실행 로그에 남기며 폴백 모드를 표시하도록 개선.
|
2025-12-17 08:48:00 KST 추가 업데이트: 동일 커밋 건너뛰기 시 모드를 “변경 없음”으로 분리하고 shallow-exclude 실패 시 fetch 로그 tail을 실행 로그에 남기며 폴백 모드를 표시하도록 개선.
|
||||||
|
2025-12-17 09:38:49 KST 추가 업데이트: Gitea API 오류가 발생해도 전체 작업이 중단되지 않도록 exit 대신 return 처리하여 다음 브랜치로 계속 진행하도록 수정.
|
||||||
|
2025-12-17 09:50:00 KST 추가 업데이트: Gitea API(조회/생성/기본 브랜치 설정)에 최대 3회 재시도(5초 대기)를 추가해 일시 오류 발생 시에도 작업이 이어지도록 개선, README 반영.
|
||||||
|
|||||||
Reference in New Issue
Block a user