fix: enhance phase3_teardown.sh with error handling for runner removal

This commit is contained in:
S
2026-03-02 10:50:27 -05:00
parent c5676679e8
commit 65330d4e00

View File

@@ -24,6 +24,11 @@ if [[ ! -f "$RUNNERS_CONF" ]]; then
exit 0 exit 0
fi fi
# Track whether teardown encountered operational errors (not user skips).
TEARDOWN_FAILED=false
REMOVED=0
FAILED=0
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Step 1: Remove each runner via manage_runner.sh # Step 1: Remove each runner via manage_runner.sh
# manage_runner.sh handles its own safety (skips already-removed runners). # manage_runner.sh handles its own safety (skips already-removed runners).
@@ -34,21 +39,36 @@ if [[ "$confirm" =~ ^[Yy]$ ]]; then
while IFS= read -r name; do while IFS= read -r name; do
[[ -z "$name" ]] && continue [[ -z "$name" ]] && continue
log_info "Removing runner: ${name}" log_info "Removing runner: ${name}"
"${SCRIPT_DIR}/manage_runner.sh" remove --name "$name" || true if "${SCRIPT_DIR}/manage_runner.sh" remove --name "$name"; then
REMOVED=$((REMOVED + 1))
else
log_error "Failed to remove runner: ${name}"
FAILED=$((FAILED + 1))
TEARDOWN_FAILED=true
fi
done < <(ini_list_sections "$RUNNERS_CONF") done < <(ini_list_sections "$RUNNERS_CONF")
log_success "All runners removed"
TOTAL=$((REMOVED + FAILED))
log_info "Results: ${REMOVED} removed, ${FAILED} failed (out of ${TOTAL})"
else else
log_info "Skipped runner removal" log_info "Skipped runner removal"
fi fi
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Step 2: Clear the registration token from .env # Step 2: Clear the registration token from .env
# The token is single-use in some Gitea configurations — generating a new one # Only clear if no runners failed — a partial teardown should preserve the
# on next deploy is safer than reusing a potentially stale token. # token so the user can retry without needing to regenerate it.
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
if [[ -n "${GITEA_RUNNER_REGISTRATION_TOKEN:-}" ]]; then if $TEARDOWN_FAILED; then
log_info "Keeping GITEA_RUNNER_REGISTRATION_TOKEN in .env because some runners failed to remove"
elif [[ -n "${GITEA_RUNNER_REGISTRATION_TOKEN:-}" ]]; then
save_env_var "GITEA_RUNNER_REGISTRATION_TOKEN" "" save_env_var "GITEA_RUNNER_REGISTRATION_TOKEN" ""
log_success "GITEA_RUNNER_REGISTRATION_TOKEN cleared from .env" log_success "GITEA_RUNNER_REGISTRATION_TOKEN cleared from .env"
fi fi
if $TEARDOWN_FAILED; then
log_error "Phase 3 teardown completed with errors"
exit 1
fi
log_success "Phase 3 teardown complete" log_success "Phase 3 teardown complete"