#!/usr/bin/env bash
set -xeuo pipefail

ROOT=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
source "$ROOT/lib.sh"

remote_config=${CONFIG_PATH}
local_config=/tmp/base-config.yaml
download_blob "${remote_config}" "${local_config}"

argocd_repo=tidbcloud/app-delivery
region=$(yq '.region' "${local_config}")
logical_region_name=$(yq '.name' "${local_config}")
env=$(yq '.env' "${local_config}")
cloud=$(yq '.cloudProvider' "${local_config}")
cluster=$(yq '.k8s.name' "${local_config}")
job_id=$(yq '.jobId' "${local_config}")
output=$(yq '.outputPath' "${local_config}")

# Deploy application services by invoking deploy-new-region action in $argocd_repo
common_params="-f cloud=${cloud} -f region=${region} -f env=${env} -f cluster=${cluster} -f jobId=${job_id} -f logicalRegionName=${logical_region_name}"
export GH_REPO="${argocd_repo}"
gh workflow run deploy-new-region-gateway-api-crds.yaml ${common_params}

