From 4a13289f233987a1ee6fd0c5644a51f8c71f5ab7 Mon Sep 17 00:00:00 2001 From: Lectom C Han Date: Tue, 16 Dec 2025 09:44:28 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B1=EC=97=85=20=EB=A0=88=ED=8F=AC=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=EC=9D=B4=20=EB=8F=99=EC=9D=BC=ED=95=98?= =?UTF-8?q?=EB=A9=B4=20Skip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/mirror.yml | 17 +++++++++++++++++ to-do.md | 2 ++ 2 files changed, 19 insertions(+) diff --git a/.gitea/workflows/mirror.yml b/.gitea/workflows/mirror.yml index 8ae7bb2..5963823 100644 --- a/.gitea/workflows/mirror.yml +++ b/.gitea/workflows/mirror.yml @@ -52,6 +52,11 @@ jobs: start) text="센터Git ${repo} 백업을 ${ts}에 시작합니다. (branch: ${branch}, mode: ${mode})" ;; + skip) + end_epoch=$(date +%s) + duration=$((end_epoch - start_epoch)) + text="센터Git ${repo} 백업을 건너뜁니다. (branch: ${branch} -> main, mode: ${mode}, duration: ${duration}s, 시각: ${ts})" + ;; success) end_epoch=$(date +%s) duration=$((end_epoch - start_epoch)) @@ -142,6 +147,7 @@ jobs: notify_status "error" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" "source branch 없음/비어 있음" return fi + branch_commit=$(echo "${branch_ref}" | awk '{print $1}') # Check if repository exists on Gitea repo_exists=false @@ -180,6 +186,17 @@ jobs: GITEA_HOSTNAME=$(echo "${BASE_GITEA_URL}" | sed -e 's~^https*://~~' -e 's~/$~~') GITEA_REMOTE="https://${BASE_GITEA_USER}:${BASE_GITEA_TOKEN}@${GITEA_HOSTNAME}/${CENTER_ORG}/${repo_name}.git" + # If target repo exists and refs match, skip heavy operations + if ${repo_exists}; then + target_main_ref=$(git ls-remote "${GITEA_REMOTE}" "refs/heads/main" || true) + target_commit=$(echo "${target_main_ref}" | awk '{print $1}') + if [[ -n "${branch_commit:-}" && -n "${target_commit}" && "${branch_commit}" == "${target_commit}" ]]; then + echo "Target main already at source commit (${branch_commit}). Skipping clone/push." + notify_status "skip" "${repo_name}" "${branch_name}" "${backup_mode}" "${start_epoch}" + return + fi + fi + # Create a temporary directory for cloning CLONE_DIR=$(mktemp -d) echo "Working directory: ${CLONE_DIR}" diff --git a/to-do.md b/to-do.md index 0626c4a..9d7be67 100644 --- a/to-do.md +++ b/to-do.md @@ -12,3 +12,5 @@ --- 2025-12-16 09:04:36 KST 업데이트: mirror.yml에서 대상 저장소를 `git clone --mirror` 대신 `--bare`로 받도록 변경하여 `fatal: --mirror can't be combined with refspecs` 오류를 제거. 기존 저장소가 있을 때는 Gitea 원격을 bare 클론 후 `source` 리모트를 원본 SSH에 추가하고 브랜치만 fetch → `origin`의 `main`으로 강제 푸시하도록 정리. 새 저장소일 때는 원본을 bare 클론해 `origin`을 `source`로 rename 후 Gitea를 `origin`으로 추가, 같은 fetch→push 동작 수행. 작업 루트 경로를 `ROOT_DIR`에 저장해 fetch/push 실패 시에도 항상 원위치로 돌아가며 임시 디렉터리를 정리하도록 수정. +2025-12-16 09:42:00 KST 업데이트: mirror.yml에 NOTIFY_WEBHOOK 기반 상태 알림(start/success/error, 소요시간 포함) 추가 및 heredoc 제거로 문법 오류 수정. 브랜치명 매핑을 확장해 Develop_Net8_* 접두사는 제거, Develop_/develop_ 접두사는 제거하여 `develop_boxzainer` → `boxzainer`로 푸시되도록 수정하고, 접두사 없는 `develop` 등은 그대로 사용. +2025-12-16 09:42:00 KST 추가 업데이트: mirror.yml에서 타겟이 존재할 때 `git ls-remote`로 main 커밋을 조회하고 소스 브랜치 커밋과 동일하면 클론/푸시를 건너뛰도록 최적화. 알림에 skip 상태를 추가해 동일 커밋 시 건너뛰는 로그를 남기도록 개선.