#!/usr/bin/env bash # deploy-by-script-to : run change-to-all-branches (align + deploy test), then checkout target, pull, deploy target. # Centralized in ia_dev. Requires: start on branch test (after /push-by-script). Target: test | pprod | prod. set -euo pipefail if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then echo "[deploy-by-script-to][ERROR] Not in a git repository" >&2 exit 1 fi PROJECT_ROOT="$(git rev-parse --show-toplevel)" SCRIPT_REAL="$(readlink -f "${BASH_SOURCE[0]:-$0}" 2>/dev/null || realpath "${BASH_SOURCE[0]:-$0}" 2>/dev/null || echo "${BASH_SOURCE[0]:-$0}")" DEPLOY_IA="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)" if [[ "$(pwd)" != "$PROJECT_ROOT" ]]; then cd "$PROJECT_ROOT" && exec "$SCRIPT_REAL" "$@" fi TARGET_BRANCH="${1:-}" if [[ -z "$TARGET_BRANCH" ]]; then echo "[deploy-by-script-to][ERROR] Missing argument (expected: test | pprod | prod)" >&2 echo "Usage: ./ia_dev/deploy/deploy-by-script-to.sh (or ./deploy/deploy-by-script-to.sh if deploy wraps ia_dev)" >&2 exit 1 fi if [[ ! "$TARGET_BRANCH" =~ ^(test|pprod|prod)$ ]]; then echo "[deploy-by-script-to][ERROR] Invalid target branch: must be test, pprod or prod (got: '${TARGET_BRANCH}')" >&2 echo "Usage: ./ia_dev/deploy/deploy-by-script-to.sh " >&2 exit 1 fi current="$(git rev-parse --abbrev-ref HEAD)" if [[ "$current" != "test" ]]; then echo "[deploy-by-script-to][ERROR] Must be on branch 'test' to run change-to-all-branches first (current: '${current}')" >&2 exit 1 fi echo "[deploy-by-script-to] Step 1/5: change-to-all-branches (align + deploy test)..." "$DEPLOY_IA/change-to-all-branches.sh" echo "[deploy-by-script-to] Step 2/5: checkout ${TARGET_BRANCH}..." if [[ "$(git rev-parse --abbrev-ref HEAD)" != "$TARGET_BRANCH" ]]; then git checkout "$TARGET_BRANCH" fi echo "[deploy-by-script-to] Step 3/5: fetch and sync local branch with origin/${TARGET_BRANCH}..." git fetch origin if [[ "$TARGET_BRANCH" == "test" ]]; then git pull --rebase origin test || { echo "[deploy-by-script-to][ERROR] Pull from origin/test failed. Resolve conflicts or run manually." >&2 exit 1 } else git reset --hard "origin/${TARGET_BRANCH}" fi echo "[deploy-by-script-to] Step 4/5: deploy ${TARGET_BRANCH} (--import-v1 --skipSetupHost)..." "$PROJECT_ROOT/deploy/scripts_v2/deploy.sh" "$TARGET_BRANCH" --import-v1 --skipSetupHost echo "[deploy-by-script-to] Step 5/5: checkout test..." git checkout test echo "[deploy-by-script-to] OK: aligned, synced, deployed to ${TARGET_BRANCH}, back on test"