#!/usr/bin/env bash set -euo pipefail # ============================================================================= # phase5_teardown.sh — Remove .gitea/workflows/ from all repos # Clones each repo, removes the .gitea/workflows/ directory, commits + pushes. # Safe to run if .gitea/workflows/ doesn't exist (skips with info message). # ============================================================================= 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 \ GITEA_ADMIN_USER \ REPO_1_NAME REPO_2_NAME REPO_3_NAME log_warn "=== Phase 5 Teardown: Remove Gitea Workflows ===" REPOS=("$REPO_1_NAME" "$REPO_2_NAME" "$REPO_3_NAME") TEMP_BASE="/tmp/gitea-migration-teardown" cleanup() { rm -rf "$TEMP_BASE" } trap cleanup EXIT printf 'This will remove .gitea/workflows/ from all repos. Continue? [y/N] ' read -r confirm if [[ ! "$confirm" =~ ^[Yy]$ ]]; then log_info "Teardown cancelled" exit 0 fi for repo in "${REPOS[@]}"; do log_info "--- Processing: ${repo} ---" # Check if .gitea/workflows/ exists before cloning (avoid unnecessary work) if ! gitea_api GET "/repos/${GITEA_ORG_NAME}/${repo}/contents/.gitea/workflows" >/dev/null 2>&1; then log_info "No .gitea/workflows/ in ${repo} — already clean" continue fi # Clone, remove, commit, push CLONE_DIR="${TEMP_BASE}/${repo}" rm -rf "$CLONE_DIR" CLONE_URL=$(echo "${GITEA_INTERNAL_URL}" | sed "s|://|://${GITEA_ADMIN_USER}:${GITEA_ADMIN_TOKEN}@|") git clone -q "${CLONE_URL}/${GITEA_ORG_NAME}/${repo}.git" "$CLONE_DIR" if [[ -d "${CLONE_DIR}/.gitea/workflows" ]]; then rm -rf "${CLONE_DIR}/.gitea/workflows" cd "$CLONE_DIR" git config user.name "Gitea Migration" git config user.email "migration@gitea.local" git add -A git commit -q -m "Remove Gitea Actions workflows (teardown)" git push -q origin HEAD cd "$SCRIPT_DIR" log_success "Removed .gitea/workflows/ from ${repo}" else log_info ".gitea/workflows/ not found in clone — already clean" fi done log_success "Phase 5 teardown complete"