diff --git a/.gitea/workflows/backup.yml b/.gitea/workflows/backup.yml index 757d377..3fb93e8 100644 --- a/.gitea/workflows/backup.yml +++ b/.gitea/workflows/backup.yml @@ -31,7 +31,7 @@ jobs: run: | set -euo pipefail echo "Refreshing mirror repos on 172.16.10.191 ..." - ssh engdev@172.16.10.191 'set -euo pipefail; export GIT_PROGRESS_DELAY=0 GIT_FLUSH=1; shopt -s nullglob; for repo in *.git; do [ -d "${repo}" ] || continue; echo "Updating ${repo}"; (cd "${repo}" && git fetch --progress --mirror --prune); done' + ssh engdev@172.16.10.191 'set -euo pipefail; export GIT_PROGRESS_DELAY=0 GIT_FLUSH=1; shopt -s nullglob; for repo in *.git; do [ -d "${repo}" ] || continue; echo "Updating ${repo}"; (cd "${repo}" && git fetch --progress --prune --prune-tags origin "+refs/*:refs/*"); done' - name: Backup Branches (pre-scan → decision → execution) continue-on-error: true @@ -259,7 +259,7 @@ jobs: fi else echo "Refreshing cache for ${source_repo}" - if ! git -C "${cache_dir}" fetch --progress --mirror --prune; then + if ! git -C "${cache_dir}" fetch --progress --prune --prune-tags origin "+refs/*:refs/*"; then echo "::warning::Failed to refresh cache for ${source_repo} (${SOURCE_SSH_HOST}:${source_repo})" return 1 fi @@ -594,60 +594,61 @@ jobs: if: always() run: | set -euo pipefail - REPORT_DIR="${REPORT_DIR:-${{ github.workspace }}/backup_reports}" + REPORT_DIR="${REPORT_DIR:-${GITHUB_WORKSPACE}/backup_reports}" TS="${REPORT_TS:-}" if [[ -z "${TS}" ]]; then - TS=$(ls -t ${REPORT_DIR}/decisions_*.log 2>/dev/null | head -1 | sed -E 's/.*decisions_([0-9_]+)\\.log/\\1/') - fi - if [[ -z "${TS}" ]]; then - echo "::error::No report timestamp found; cannot build report." - exit 1 + TS=$(ls -t ${REPORT_DIR}/decisions_*.log 2>/dev/null | head -1 | sed -E 's/.*decisions_([0-9_]+)\.log/\1/') fi DECISIONS_LOG="${REPORT_DIR}/decisions_${TS}.log" TIMINGS_LOG="${REPORT_DIR}/timings_${TS}.log" REPORT_MD="${REPORT_DIR}/report_${TS}.md" - SOURCE_SSH_HOST="${SOURCE_SSH_HOST:-${{ env.SOURCE_SSH_HOST }}}" - - if [[ ! -f "${DECISIONS_LOG}" || ! -f "${TIMINGS_LOG}" ]]; then - echo "::error::Missing decisions or timings log." - exit 1 - fi - - total=0; success=0; skip=0; error=0 - while IFS='|' read -r sr br al rr sc tc dc st se de ee xe dt dexe nt; do - [[ -z "${sr}" ]] && continue - ((total++)) - case "${st}" in - success) ((success++)) ;; - skip) ((skip++)) ;; - error) ((error++)) ;; - esac - done < "${TIMINGS_LOG}" + SOURCE_SSH_HOST="${SOURCE_SSH_HOST:-}" SUMMARY_TS=$(TZ=Asia/Seoul date '+%Y-%m-%d %H:%M:%S %Z') + total=0; success=0; skip=0; error=0 + if [[ -f "${TIMINGS_LOG}" ]]; then + while IFS='|' read -r sr br al rr sc tc dc st se de ee xe dt dexe nt; do + [[ -z "${sr}" ]] && continue + ((total++)) + case "${st}" in + success) ((success++)) ;; + skip) ((skip++)) ;; + error) ((error++)) ;; + esac + done < "${TIMINGS_LOG}" + fi + { echo "# Git Backup Report" echo "" echo "- Generated: ${SUMMARY_TS}" echo "- Run ID: ${GITHUB_RUN_ID:-local}" - echo "- Source host: ${SOURCE_SSH_HOST}" + [[ -n "${SOURCE_SSH_HOST}" ]] && echo "- Source host: ${SOURCE_SSH_HOST}" echo "- Total: ${total} (success ${success}, skip ${skip}, error ${error})" echo "" echo "## Decisions (all)" echo "|source_repo|branch|alias|resolved_repo|source_commit|target_commit|decision|note|" echo "|---|---|---|---|---|---|---|---|" - while IFS='|' read -r sr br al rr sc tc dc nt; do - [[ -z "${sr}" ]] && continue - printf "|%s|%s|%s|%s|%s|%s|%s|%s|\n" "$sr" "$br" "$al" "$rr" "$sc" "$tc" "$dc" "$nt" - done < "${DECISIONS_LOG}" + if [[ -f "${DECISIONS_LOG}" ]]; then + while IFS='|' read -r sr br al rr sc tc dc nt; do + [[ -z "${sr}" ]] && continue + printf "|%s|%s|%s|%s|%s|%s|%s|%s|\n" "$sr" "$br" "$al" "$rr" "$sc" "$tc" "$dc" "$nt" + done < "${DECISIONS_LOG}" + else + echo "|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|" + fi echo "" echo "## Timings (all)" echo "|source_repo|branch|alias|resolved_repo|source_commit|target_commit|decision|status|start_epoch|decision_epoch|exec_start_epoch|exec_end_epoch|duration_total(s)|duration_exec(s)|note|" echo "|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|" - while IFS='|' read -r sr br al rr sc tc dc st se de ee xe dt dexe nt; do - [[ -z "${sr}" ]] && continue - printf "|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|\n" "$sr" "$br" "$al" "$rr" "$sc" "$tc" "$dc" "$st" "$se" "$de" "$ee" "$xe" "$dt" "$dexe" "$nt" - done < "${TIMINGS_LOG}" + if [[ -f "${TIMINGS_LOG}" ]]; then + while IFS='|' read -r sr br al rr sc tc dc st se de ee xe dt dexe nt; do + [[ -z "${sr}" ]] && continue + printf "|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|\n" "$sr" "$br" "$al" "$rr" "$sc" "$tc" "$dc" "$st" "$se" "$de" "$ee" "$xe" "$dt" "$dexe" "$nt" + done < "${TIMINGS_LOG}" + else + echo "|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|(missing)|" + fi echo "" } > "${REPORT_MD}" echo "Report generated at ${REPORT_MD}" diff --git a/.gitea/workflows/mirror.yml b/.gitea/workflows/mirror.yml index 159321f..33284a8 100644 --- a/.gitea/workflows/mirror.yml +++ b/.gitea/workflows/mirror.yml @@ -29,7 +29,7 @@ jobs: run: | set -euo pipefail echo "Refreshing mirror repos on 172.16.10.191 ..." - ssh engdev@172.16.10.191 'set -euo pipefail; export GIT_PROGRESS_DELAY=0 GIT_FLUSH=1; shopt -s nullglob; for repo in *.git; do [ -d "${repo}" ] || continue; echo "Updating ${repo}"; (cd "${repo}" && git fetch --progress --mirror --prune); done' + ssh engdev@172.16.10.191 'set -euo pipefail; export GIT_PROGRESS_DELAY=0 GIT_FLUSH=1; shopt -s nullglob; for repo in *.git; do [ -d "${repo}" ] || continue; echo "Updating ${repo}"; (cd "${repo}" && git fetch --progress --prune --prune-tags origin "+refs/*:refs/*"); done' - name: Mirror Branches env: