#!/usr/bin/env bash set -euo pipefail # ============================================================================= # phase5_post_check.sh — Verify Phase 5 (Pipeline Migration) succeeded # Checks for each repo: # 1. .gitea/workflows/ directory exists (via Gitea contents API) # 2. At least one .yml file in the directory # Repos without .github/workflows are expected to be skipped. # Exits 0 only if ALL expected checks pass. # ============================================================================= 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 \ REPO_1_NAME REPO_2_NAME REPO_3_NAME log_info "=== Phase 5 Post-Check ===" REPOS=("$REPO_1_NAME" "$REPO_2_NAME" "$REPO_3_NAME") PASS=0 FAIL=0 SKIP=0 for repo in "${REPOS[@]}"; do log_info "--- Checking repo: ${repo} ---" # Check if .gitea/workflows exists via Gitea contents API WORKFLOWS_RESPONSE=$(gitea_api GET "/repos/${GITEA_ORG_NAME}/${repo}/contents/.gitea/workflows" 2>/dev/null || echo "") if [[ -z "$WORKFLOWS_RESPONSE" ]]; then # Directory doesn't exist — check if the repo had GitHub workflows # If not, this is expected (skipped during migration, not a failure) GH_WORKFLOWS=$(gitea_api GET "/repos/${GITEA_ORG_NAME}/${repo}/contents/.github/workflows" 2>/dev/null || echo "") if [[ -z "$GH_WORKFLOWS" ]]; then log_info "${repo}: No .github/workflows/ — skipped (expected)" SKIP=$((SKIP + 1)) else log_error "FAIL: ${repo}: .github/workflows/ exists but .gitea/workflows/ missing" FAIL=$((FAIL + 1)) fi continue fi # Check that at least one .yml file exists in the directory YML_COUNT=$(printf '%s' "$WORKFLOWS_RESPONSE" | jq '[.[] | select(.name | test("\\.(yml|yaml)$"))] | length' 2>/dev/null || echo 0) if [[ "$YML_COUNT" -gt 0 ]]; then log_success "${repo}: .gitea/workflows/ has ${YML_COUNT} workflow file(s)" PASS=$((PASS + 1)) else log_error "FAIL: ${repo}: .gitea/workflows/ exists but has no .yml files" FAIL=$((FAIL + 1)) fi done # Summary printf '\n' log_info "Results: ${PASS} passed, ${SKIP} skipped (no source workflows), ${FAIL} failed" if [[ $FAIL -gt 0 ]]; then log_error "Phase 5 post-check FAILED" exit 1 else log_success "Phase 5 post-check PASSED" exit 0 fi