feat: add Phase 6 — GitHub Push Mirrors

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
S
2026-02-26 15:27:13 -06:00
parent 6e3b4c66d1
commit 058b85e146
3 changed files with 248 additions and 0 deletions

79
phase6_post_check.sh Executable file
View File

@@ -0,0 +1,79 @@
#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# phase6_post_check.sh — Verify Phase 6 (GitHub Push Mirrors) succeeded
# Checks for each repo:
# 1. Push mirror config exists in Gitea
# 2. Triggers sync and verifies GitHub has matching latest commit
# Exits 0 only if ALL checks pass.
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
load_env
require_vars GITEA_ADMIN_TOKEN GITEA_INTERNAL_URL GITEA_ORG_NAME \
GITHUB_USERNAME GITHUB_TOKEN \
REPO_1_NAME REPO_2_NAME REPO_3_NAME
log_info "=== Phase 6 Post-Check ==="
REPOS=("$REPO_1_NAME" "$REPO_2_NAME" "$REPO_3_NAME")
PASS=0
FAIL=0
run_check() {
local description="$1"; shift
if "$@" 2>/dev/null; then
log_success "$description"
PASS=$((PASS + 1))
else
log_error "FAIL: $description"
FAIL=$((FAIL + 1))
fi
}
for repo in "${REPOS[@]}"; do
log_info "--- Checking repo: ${repo} ---"
# Check 1: Push mirror exists
check_mirror_exists() {
local mirrors
mirrors=$(gitea_api GET "/repos/${GITEA_ORG_NAME}/$1/push_mirrors")
local count
count=$(printf '%s' "$mirrors" | jq 'length')
[[ "$count" -gt 0 ]]
}
run_check "Push mirror exists for ${repo}" check_mirror_exists "$repo"
# Check 2: Latest commit SHA matches between Gitea and GitHub
# Trigger a sync first, then compare HEAD commits
check_commit_sync() {
# Trigger sync
gitea_api POST "/repos/${GITEA_ORG_NAME}/$1/push_mirrors-sync" "" >/dev/null 2>&1 || true
# Brief wait for sync to propagate
sleep 3
# Get Gitea's latest commit
local gitea_sha github_sha
gitea_sha=$(gitea_api GET "/repos/${GITEA_ORG_NAME}/$1/commits?limit=1" | jq -r '.[0].sha')
# Get GitHub's latest commit
github_sha=$(github_api GET "/repos/${GITHUB_USERNAME}/$1/commits?per_page=1" | jq -r '.[0].sha')
[[ "$gitea_sha" == "$github_sha" ]]
}
run_check "Latest commit synced to GitHub for ${repo}" check_commit_sync "$repo"
done
# Summary
printf '\n'
log_info "Results: ${PASS} passed, ${FAIL} failed"
if [[ $FAIL -gt 0 ]]; then
log_error "Phase 6 post-check FAILED"
exit 1
else
log_success "Phase 6 post-check PASSED — push mirrors working"
exit 0
fi