feat: add orchestration (run_all.sh, teardown_all.sh)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
S
2026-02-26 15:33:51 -06:00
parent e643caa0b0
commit 40fe847755
2 changed files with 295 additions and 0 deletions

161
run_all.sh Executable file
View File

@@ -0,0 +1,161 @@
#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# run_all.sh — Orchestrate the full Gitea migration pipeline
# Runs: setup → preflight → phase 1-9 (each with post-check) sequentially.
# Stops on first failure, prints summary of what completed.
#
# Usage:
# ./run_all.sh # Full run: setup + preflight + phases 1-9
# ./run_all.sh --skip-setup # Skip setup scripts, start at preflight
# ./run_all.sh --start-from=3 # Run preflight, then start at phase 3
# ./run_all.sh --skip-setup --start-from=5
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# ---------------------------------------------------------------------------
# Parse arguments
# ---------------------------------------------------------------------------
SKIP_SETUP=false
START_FROM=0
for arg in "$@"; do
case "$arg" in
--skip-setup) SKIP_SETUP=true ;;
--start-from=*)
START_FROM="${arg#*=}"
if ! [[ "$START_FROM" =~ ^[0-9]+$ ]]; then
log_error "--start-from must be a number (1-9)"
exit 1
fi
;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--skip-setup Skip configure_env + machine setup, start at preflight
--start-from=N Skip phases before N (still runs preflight)
--help Show this help
Examples:
$(basename "$0") Full run
$(basename "$0") --skip-setup Skip setup, start at preflight
$(basename "$0") --start-from=3 Run preflight, then phases 3-9
EOF
exit 0 ;;
*) log_error "Unknown argument: $arg"; exit 1 ;;
esac
done
# ---------------------------------------------------------------------------
# Execution tracking
# We track each step's status for the summary at the end.
# ---------------------------------------------------------------------------
declare -a STEP_NAMES
declare -a STEP_RESULTS
record_step() {
local name="$1" result="$2"
STEP_NAMES+=("$name")
STEP_RESULTS+=("$result")
}
# Run a script, record pass/fail, stop on failure
run_step() {
local name="$1" script="$2"
log_info ">>> Running: ${name}"
if "${SCRIPT_DIR}/${script}"; then
record_step "$name" "PASS"
printf '\n'
else
record_step "$name" "FAIL"
log_error ">>> FAILED: ${name}"
print_summary
exit 1
fi
}
# ---------------------------------------------------------------------------
# Summary printer — shows pass/fail for each step that ran
# ---------------------------------------------------------------------------
print_summary() {
printf '\n'
log_info "===== Execution Summary ====="
for i in "${!STEP_NAMES[@]}"; do
if [[ "${STEP_RESULTS[$i]}" == "PASS" ]]; then
log_success " ${STEP_NAMES[$i]}"
else
log_error " ${STEP_NAMES[$i]} — FAILED"
fi
done
printf '\n'
}
# ---------------------------------------------------------------------------
# Step 0: Setup (configure_env + machine prerequisites)
# Skipped if --skip-setup or --start-from is set (assumes already done).
# configure_env is interactive — don't run it in automated pipelines.
# ---------------------------------------------------------------------------
if [[ "$SKIP_SETUP" == "false" ]] && [[ "$START_FROM" -eq 0 ]]; then
log_info "=== Step 0: Setup ==="
# configure_env.sh is interactive — ask user if they want to run it
# since they may have already filled in .env manually
if [[ -f "${SCRIPT_DIR}/.env" ]]; then
log_info ".env already exists — skipping configure_env.sh"
else
run_step "Configure .env" "setup/configure_env.sh"
fi
run_step "Setup MacBook" "setup/macbook.sh"
run_step "Setup Unraid" "setup/unraid.sh"
run_step "Setup Fedora" "setup/fedora.sh"
else
log_info "Skipping setup (--skip-setup or --start-from=${START_FROM})"
fi
# ---------------------------------------------------------------------------
# Preflight — always runs (validates .env and infrastructure)
# Even with --start-from, preflight ensures the environment is healthy.
# ---------------------------------------------------------------------------
log_info "=== Preflight ==="
run_step "Preflight checks" "preflight.sh"
# ---------------------------------------------------------------------------
# Phases 1-9 — run sequentially, each followed by its post-check
# The phase scripts are the "do" step, post-checks verify success.
# ---------------------------------------------------------------------------
PHASES=(
"1|Phase 1: Gitea on Unraid|phase1_gitea_unraid.sh|phase1_post_check.sh"
"2|Phase 2: Gitea on Fedora|phase2_gitea_fedora.sh|phase2_post_check.sh"
"3|Phase 3: Runners|phase3_runners.sh|phase3_post_check.sh"
"4|Phase 4: Migrate Repos|phase4_migrate_repos.sh|phase4_post_check.sh"
"5|Phase 5: Migrate Pipelines|phase5_migrate_pipelines.sh|phase5_post_check.sh"
"6|Phase 6: GitHub Mirrors|phase6_github_mirrors.sh|phase6_post_check.sh"
"7|Phase 7: Branch Protection|phase7_branch_protection.sh|phase7_post_check.sh"
"8|Phase 8: Cutover|phase8_cutover.sh|phase8_post_check.sh"
"9|Phase 9: Security|phase9_security.sh|phase9_post_check.sh"
)
for phase_entry in "${PHASES[@]}"; do
IFS='|' read -r phase_num phase_name phase_script post_check <<< "$phase_entry"
# Skip phases before --start-from
if [[ "$phase_num" -lt "$START_FROM" ]]; then
log_info "Skipping ${phase_name} (--start-from=${START_FROM})"
continue
fi
run_step "$phase_name" "$phase_script"
run_step "${phase_name} — post-check" "$post_check"
done
# ---------------------------------------------------------------------------
# All done
# ---------------------------------------------------------------------------
print_summary
log_success "Migration complete! Gitea is live."