ia_dev/deploy/change-to-all-branches.sh
Nicolas Cantu 02f822c790 fix(deploy): remove implicit fallback deployment site list
**Motivations :**
- keep deploy-by-script-to strict when source-of-truth site slugs are unavailable
- align ia_dev deploy wrappers with lecoffreio-only deployment model
- avoid hidden default behavior in secrets layout validation

**Root causes :**
- deploy-by-script-to still had a fallback that reintroduced implicit site assumptions
- helper comments and branch-align wording still referenced removed multisite lines

**Correctifs :**
- remove fallback site injection in deploy-by-script-to and fail explicitly on empty site list
- update change-to-all-branches orchestration comment to source-of-truth semantics
- align deploy-conf-handling nested secrets guidance with lecoffreio-only tree

**Evolutions :**
- strengthen strict mode behavior for deployment prerequisites

**Page affectées :**
- deploy/deploy-by-script-to.sh
- deploy/change-to-all-branches.sh
- deploy/lib/deploy-conf-handling.sh
2026-05-14 10:32:23 +02:00

86 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# From branch test only: align origin/test, origin/pprod, origin/prod then optionally deploy to test (import V1 is systematic after deploy-app when RUN_DEPLOY=true; see deploy.conf for other RUN_*).
# Usage: ./deploy/change-to-all-branches.sh [project_id] [--align-only]
# --align-only : run branch-align.sh test only (no deploy to test). Used by deploy-pprod-or-prod step 2; full deploy test remains /change-to-all-branches without this flag.
set -euo pipefail
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_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)"
IA_DEV_ROOT="$(cd "$DEPLOY_DIR/.." && pwd)"
# shellcheck source=../lib/smart_ide_logs.sh
source "${IA_DEV_ROOT}/lib/smart_ide_logs.sh"
smart_ide_logs_begin "$IA_DEV_ROOT" "$0" "$*"
smart_ide_logs_register_exit_trap
# Optional first arg: project id (must exist as projects/<id>/conf.json); then re-exec from project root
if [[ -n "${1:-}" && -f "${IA_DEV_ROOT}/projects/${1}/conf.json" ]]; then
export IA_PROJECT_ID="$1"
shift
# shellcheck source=../lib/project_config.sh
source "${IA_DEV_ROOT}/lib/project_config.sh"
[[ -n "${PROJECT_ID:-}" ]] && export IA_PROJECT_ID="$PROJECT_ID"
# shellcheck source=../lib/project_git_root_from_conf.sh
source "${IA_DEV_ROOT}/lib/project_git_root_from_conf.sh"
ia_dev_resolve_project_git_root
PROJECT_ROOT="${IA_PROJECT_GIT_ROOT:-}"
if [[ -z "$PROJECT_ROOT" || ! -d "$PROJECT_ROOT" ]]; then
echo "[change-to-all-branches][ERROR] Could not resolve project root for project_id ${IA_PROJECT_ID}" >&2
exit 1
fi
cd "$PROJECT_ROOT" && exec "${DEPLOY_DIR}/$(basename "${BASH_SOURCE[0]:-$0}")" "$@"
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "[change-to-all-branches][ERROR] Not in a git repository" >&2
exit 1
fi
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
if [[ "$(pwd)" != "$PROJECT_ROOT" ]]; then
cd "$PROJECT_ROOT" && exec "${DEPLOY_DIR}/$(basename "${BASH_SOURCE[0]:-$0}")" "$@"
fi
current="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$current" != "test" ]]; then
echo "[change-to-all-branches][ERROR] Must be on branch 'test' (current: '${current}')" >&2
exit 1
fi
ALIGN_ONLY=false
UNKNOWN_ARGS=()
for _arg in "$@"; do
if [[ "$_arg" == "--align-only" ]]; then
ALIGN_ONLY=true
else
UNKNOWN_ARGS+=("$_arg")
fi
done
if [[ ${#UNKNOWN_ARGS[@]} -gt 0 ]]; then
echo "[change-to-all-branches][ERROR] Unknown arguments: ${UNKNOWN_ARGS[*]} (optional: --align-only)" >&2
exit 1
fi
echo "[change-to-all-branches] Aligning branches..."
"$DEPLOY_DIR/branch-align.sh" test
if [[ "$ALIGN_ONLY" == "true" ]]; then
echo "[change-to-all-branches] OK (--align-only: deploy test skipped)"
exit 0
fi
# scripts_v2 lives in the host project's deploy/ (not necessarily under ia_dev)
DEPLOY_SCRIPTS_V2="${PROJECT_ROOT}/deploy/scripts_v2"
ALL_SITES="${DEPLOY_SCRIPTS_V2}/deploy-multisite-lines.sh"
echo "[change-to-all-branches] Deploying test (--no-sync-origin; business flags from deploy.conf only)..."
if [[ -n "${IA_PROJECT_ID:-}" && -x "${DEPLOY_DIR}/orchestrator.sh" ]]; then
"${DEPLOY_DIR}/orchestrator.sh" test --no-sync-origin
elif [[ -f "$ALL_SITES" ]]; then
# Monorepo LeCoffre: run deployment lines from deploy/scripts_v2 source-of-truth (currently lecoffreio only).
bash "$ALL_SITES" test --no-sync-origin
else
"${DEPLOY_SCRIPTS_V2}/deploy.sh" test --no-sync-origin
fi
echo "[change-to-all-branches] OK"