Files
gitea-migration/phase3_post_check.sh
S f4a6b04d14 feat: rework runner config to INI format with full field support
Replace pipe-delimited runners.conf with INI-style sections supporting
host resolution, container images, repo-scoped tokens, resource limits,
capacity, and SSH key passthrough. All defaults pulled from .env.

- Add INI parsing helpers (ini_list_sections, ini_get, ini_set) to common.sh
- Add SSH key support (UNRAID_SSH_KEY, FEDORA_SSH_KEY) to ssh_exec/scp_to
- Add .env vars: RUNNER_DEFAULT_IMAGE, RUNNER_DEFAULT_CAPACITY,
  RUNNER_DEFAULT_DATA_PATH, LOCAL_RUNNER_DATA_PATH, LOCAL_REGISTRY
- Rewrite manage_runner.sh with host/image/token resolution and resource limits
- Rewrite configure_runners.sh wizard for INI format with all 9 fields
- Update phase3 scripts to use ini_list_sections instead of pipe parsing
- Add runners.conf INI validation to preflight.sh (check 5b)
- Update templates to use resolved labels, capacity, and deploy resources

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 23:14:46 -05:00

84 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# phase3_post_check.sh — Verify Phase 3 (Runners) succeeded
# Checks that every runner defined in runners.conf is registered and online
# in the Gitea admin panel.
# Exits 0 only if ALL checks pass.
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
load_env
require_vars GITEA_INTERNAL_URL GITEA_ADMIN_TOKEN
log_info "=== Phase 3 Post-Check ==="
RUNNERS_CONF="${SCRIPT_DIR}/runners.conf"
if [[ ! -f "$RUNNERS_CONF" ]]; then
log_error "runners.conf not found"
exit 1
fi
PASS=0
FAIL=0
# ---------------------------------------------------------------------------
# Fetch all registered runners from Gitea admin API (single call)
# This avoids making N API calls — one per runner — which would be slow.
# ---------------------------------------------------------------------------
API_RUNNERS=$(gitea_api GET "/admin/runners" 2>/dev/null || echo "[]")
# ---------------------------------------------------------------------------
# Check each runner: exists in API response AND status is online/idle/active
# A runner that registered but is not running will show as "offline".
# ---------------------------------------------------------------------------
while IFS= read -r name; do
[[ -z "$name" ]] && continue
# Look up runner by name in the API response
local_status=$(printf '%s' "$API_RUNNERS" | jq -r --arg n "$name" '.[] | select(.name == $n) | .status' 2>/dev/null || true)
if [[ -z "$local_status" ]]; then
log_error "FAIL: Runner '${name}' not found in Gitea admin"
FAIL=$((FAIL + 1))
elif [[ "$local_status" == "offline" ]]; then
log_error "FAIL: Runner '${name}' is registered but offline"
FAIL=$((FAIL + 1))
else
log_success "Runner '${name}' is ${local_status}"
PASS=$((PASS + 1))
fi
done < <(ini_list_sections "$RUNNERS_CONF")
# ---------------------------------------------------------------------------
# Check: runner count matches runners.conf
# ---------------------------------------------------------------------------
EXPECTED_COUNT=$(ini_list_sections "$RUNNERS_CONF" | wc -l | xargs)
ACTUAL_COUNT=$(printf '%s' "$API_RUNNERS" | jq 'length' 2>/dev/null || echo 0)
if [[ "$ACTUAL_COUNT" -ge "$EXPECTED_COUNT" ]]; then
log_success "Runner count OK: ${ACTUAL_COUNT} registered (${EXPECTED_COUNT} expected)"
PASS=$((PASS + 1))
else
log_error "FAIL: Only ${ACTUAL_COUNT} runners registered (expected ${EXPECTED_COUNT})"
FAIL=$((FAIL + 1))
fi
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
printf '\n'
log_info "Results: ${PASS} passed, ${FAIL} failed"
if [[ $FAIL -gt 0 ]]; then
log_error "Phase 3 post-check FAILED"
exit 1
else
log_success "Phase 3 post-check PASSED — all runners are online"
exit 0
fi