feat: add runner conversion scripts and strengthen cutover automation
This commit is contained in:
@@ -9,6 +9,18 @@ PHASE10_REPO_PATHS=()
|
||||
PHASE10_GITHUB_URLS=()
|
||||
PHASE10_DUPLICATES=()
|
||||
|
||||
phase10_repo_index_by_name() {
|
||||
local repo_name="$1"
|
||||
local i
|
||||
for i in "${!PHASE10_REPO_NAMES[@]}"; do
|
||||
if [[ "${PHASE10_REPO_NAMES[$i]}" == "$repo_name" ]]; then
|
||||
printf '%s' "$i"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
printf '%s' "-1"
|
||||
}
|
||||
|
||||
# Parse common git remote URL formats into: host|owner|repo
|
||||
# Supports:
|
||||
# - https://host/owner/repo(.git)
|
||||
@@ -89,6 +101,109 @@ phase10_canonical_gitea_url() {
|
||||
printf 'https://%s/%s/%s.git' "$domain" "$org" "$repo"
|
||||
}
|
||||
|
||||
# Resolve which local remote currently represents GitHub for this repo path.
|
||||
# Prefers "github" remote, then "origin".
|
||||
phase10_find_github_remote_url() {
|
||||
local repo_path="$1" github_owner="$2"
|
||||
local github_url=""
|
||||
|
||||
if github_url=$(git -C "$repo_path" remote get-url github 2>/dev/null); then
|
||||
if phase10_url_is_github_repo "$github_url" "$github_owner"; then
|
||||
printf '%s' "$github_url"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if github_url=$(git -C "$repo_path" remote get-url origin 2>/dev/null); then
|
||||
if phase10_url_is_github_repo "$github_url" "$github_owner"; then
|
||||
printf '%s' "$github_url"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Add or update a discovered repo entry.
|
||||
# If repo already exists and path differs, explicit path wins.
|
||||
phase10_upsert_repo_entry() {
|
||||
local repo_name="$1" repo_path="$2" github_url="$3"
|
||||
local idx existing_path
|
||||
|
||||
idx="$(phase10_repo_index_by_name "$repo_name")"
|
||||
if [[ "$idx" -ge 0 ]]; then
|
||||
existing_path="${PHASE10_REPO_PATHS[$idx]}"
|
||||
if [[ "$existing_path" != "$repo_path" ]]; then
|
||||
PHASE10_REPO_PATHS[idx]="$repo_path"
|
||||
PHASE10_GITHUB_URLS[idx]="$github_url"
|
||||
log_info "${repo_name}: using explicit include path ${repo_path} (replacing ${existing_path})"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
PHASE10_REPO_NAMES+=("$repo_name")
|
||||
PHASE10_REPO_PATHS+=("$repo_path")
|
||||
PHASE10_GITHUB_URLS+=("$github_url")
|
||||
return 0
|
||||
}
|
||||
|
||||
# Add one explicitly included repo path into discovery arrays.
|
||||
# Validates path is a git toplevel and maps to github.com/<owner>/repo.
|
||||
phase10_include_repo_path() {
|
||||
local include_path="$1" github_owner="$2"
|
||||
local abs_path top github_url parsed host owner repo canonical
|
||||
|
||||
if [[ ! -d "$include_path" ]]; then
|
||||
log_error "Include path not found: ${include_path}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
abs_path="$(cd "$include_path" && pwd)"
|
||||
if ! git -C "$abs_path" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
log_error "Include path is not a git repo: ${abs_path}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
top="$(git -C "$abs_path" rev-parse --show-toplevel 2>/dev/null || true)"
|
||||
if [[ "$top" != "$abs_path" ]]; then
|
||||
log_error "Include path must be repo root (git toplevel): ${abs_path}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
github_url="$(phase10_find_github_remote_url "$abs_path" "$github_owner" 2>/dev/null || true)"
|
||||
if [[ -z "$github_url" ]]; then
|
||||
# Explicit include-path may point to a local repo with no GitHub remote yet.
|
||||
# In that case, derive the repo slug from folder name and assume GitHub URL.
|
||||
repo="$(basename "$abs_path")"
|
||||
canonical="$(phase10_canonical_github_url "$github_owner" "$repo")"
|
||||
log_warn "Include path has no GitHub remote; assuming ${canonical}"
|
||||
else
|
||||
parsed=$(phase10_parse_git_url "$github_url" 2>/dev/null) || {
|
||||
log_error "Could not parse GitHub remote URL for include path: ${abs_path}"
|
||||
return 1
|
||||
}
|
||||
IFS='|' read -r host owner repo <<< "$parsed"
|
||||
canonical="$(phase10_canonical_github_url "$owner" "$repo")"
|
||||
fi
|
||||
|
||||
phase10_upsert_repo_entry "$repo" "$abs_path" "$canonical"
|
||||
return 0
|
||||
}
|
||||
|
||||
phase10_enforce_expected_count() {
|
||||
local expected_count="$1" root="$2"
|
||||
local i
|
||||
|
||||
if [[ "$expected_count" -gt 0 ]] && [[ "${#PHASE10_REPO_NAMES[@]}" -ne "$expected_count" ]]; then
|
||||
log_error "Expected ${expected_count} local repos under ${root}; found ${#PHASE10_REPO_NAMES[@]}"
|
||||
for i in "${!PHASE10_REPO_NAMES[@]}"; do
|
||||
log_error " - ${PHASE10_REPO_NAMES[$i]} -> ${PHASE10_REPO_PATHS[$i]}"
|
||||
done
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Stable in-place sort by repo name (keeps arrays aligned).
|
||||
phase10_sort_repo_arrays() {
|
||||
local i j tmp
|
||||
@@ -154,18 +269,7 @@ phase10_discover_local_repos() {
|
||||
top=$(git -C "$dir" rev-parse --show-toplevel 2>/dev/null || true)
|
||||
[[ "$top" == "$dir" ]] || continue
|
||||
|
||||
github_url=""
|
||||
if github_url=$(git -C "$dir" remote get-url github 2>/dev/null); then
|
||||
if ! phase10_url_is_github_repo "$github_url" "$github_owner"; then
|
||||
github_url=""
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$github_url" ]] && github_url=$(git -C "$dir" remote get-url origin 2>/dev/null); then
|
||||
if ! phase10_url_is_github_repo "$github_url" "$github_owner"; then
|
||||
github_url=""
|
||||
fi
|
||||
fi
|
||||
github_url="$(phase10_find_github_remote_url "$dir" "$github_owner" 2>/dev/null || true)"
|
||||
|
||||
[[ -n "$github_url" ]] || continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user