93 lines
2.9 KiB
Bash
Executable File
93 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# =============================================================================
|
|
# phase4_post_check.sh — Verify Phase 4 (Repo Migration) succeeded
|
|
# Checks for each repo:
|
|
# 1. Exists on primary under the org
|
|
# 2. Has at least one commit (migration actually imported content)
|
|
# 3. Default branch matches GitHub source
|
|
# 4. Mirror exists on Fedora under admin user
|
|
# 5. Mirror has mirror=true flag set
|
|
# 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_BACKUP_ADMIN_TOKEN \
|
|
GITEA_INTERNAL_URL GITEA_BACKUP_INTERNAL_URL \
|
|
GITEA_ORG_NAME GITEA_ADMIN_USER \
|
|
GITHUB_USERNAME GITHUB_TOKEN \
|
|
REPO_1_NAME REPO_2_NAME REPO_3_NAME
|
|
|
|
log_info "=== Phase 4 Post-Check ==="
|
|
|
|
REPOS=("$REPO_1_NAME" "$REPO_2_NAME" "$REPO_3_NAME")
|
|
PASS=0
|
|
FAIL=0
|
|
|
|
# Helper: run a check, track results
|
|
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: Repo exists on primary
|
|
run_check "Primary: ${GITEA_ORG_NAME}/${repo} exists" \
|
|
gitea_api GET "/repos/${GITEA_ORG_NAME}/${repo}" -o /dev/null
|
|
|
|
# Check 2: Repo has commits (migration imported content)
|
|
check_commits() {
|
|
local commits
|
|
commits=$(gitea_api GET "/repos/${GITEA_ORG_NAME}/$1/commits?limit=1")
|
|
local count
|
|
count=$(printf '%s' "$commits" | jq 'length')
|
|
[[ "$count" -gt 0 ]]
|
|
}
|
|
run_check "Primary: ${repo} has commits" check_commits "$repo"
|
|
|
|
# Check 3: Default branch matches GitHub source
|
|
check_default_branch() {
|
|
local gitea_branch github_branch
|
|
gitea_branch=$(gitea_api GET "/repos/${GITEA_ORG_NAME}/$1" | jq -r '.default_branch')
|
|
github_branch=$(github_api GET "/repos/${GITHUB_USERNAME}/$1" | jq -r '.default_branch')
|
|
[[ "$gitea_branch" == "$github_branch" ]]
|
|
}
|
|
run_check "Primary: ${repo} default branch matches GitHub" check_default_branch "$repo"
|
|
|
|
# Check 4: Mirror exists on Fedora
|
|
run_check "Fedora: ${GITEA_ADMIN_USER}/${repo} exists" \
|
|
gitea_backup_api GET "/repos/${GITEA_ADMIN_USER}/${repo}" -o /dev/null
|
|
|
|
# Check 5: Mirror has mirror=true
|
|
check_mirror_flag() {
|
|
local is_mirror
|
|
is_mirror=$(gitea_backup_api GET "/repos/${GITEA_ADMIN_USER}/$1" | jq -r '.mirror')
|
|
[[ "$is_mirror" == "true" ]]
|
|
}
|
|
run_check "Fedora: ${repo} has mirror=true" check_mirror_flag "$repo"
|
|
done
|
|
|
|
# Summary
|
|
printf '\n'
|
|
log_info "Results: ${PASS} passed, ${FAIL} failed"
|
|
|
|
if [[ $FAIL -gt 0 ]]; then
|
|
log_error "Phase 4 post-check FAILED"
|
|
exit 1
|
|
else
|
|
log_success "Phase 4 post-check PASSED — all repos migrated and mirrored"
|
|
exit 0
|
|
fi
|