diff --git a/deploy/change-to-all-branches.sh b/deploy/change-to-all-branches.sh index 05cb842..15a728e 100755 --- a/deploy/change-to-all-branches.sh +++ b/deploy/change-to-all-branches.sh @@ -47,6 +47,10 @@ echo "[change-to-all-branches] Aligning branches..." # scripts_v2 lives in the host project's deploy/ (not necessarily under ia_dev) DEPLOY_SCRIPTS_V2="${PROJECT_ROOT}/deploy/scripts_v2" echo "[change-to-all-branches] Deploying test (--import-v1 --skipSetupHost, --no-sync-origin because we just pushed)..." -"${DEPLOY_SCRIPTS_V2}/deploy.sh" test --import-v1 --skipSetupHost --no-sync-origin +if [[ -n "${IA_PROJECT_ID:-}" && -x "${DEPLOY_DIR}/run-project-hooks.sh" ]]; then + "${DEPLOY_DIR}/run-project-hooks.sh" test --import-v1 --skipSetupHost --no-sync-origin +else + "${DEPLOY_SCRIPTS_V2}/deploy.sh" test --import-v1 --skipSetupHost --no-sync-origin +fi echo "[change-to-all-branches] OK" diff --git a/deploy/deploy-by-script-to.sh b/deploy/deploy-by-script-to.sh index b65abb6..e12512d 100755 --- a/deploy/deploy-by-script-to.sh +++ b/deploy/deploy-by-script-to.sh @@ -66,12 +66,16 @@ git fetch origin git reset --hard "origin/${TARGET_BRANCH}" echo "[deploy-by-script-to] Step 4/5: deploy ${TARGET_BRANCH} (--import-v1 --skipSetupHost)..." -deploy_script="$PROJECT_ROOT/deploy/scripts_v2/deploy.sh" -if [[ -n "${PROJECT_CONFIG_PATH:-}" && -f "${PROJECT_CONFIG_PATH:-}" ]] && command -v jq >/dev/null 2>&1; then - _cfg_script="$(jq -r '.deploy.deploy_script_path // ""' "$PROJECT_CONFIG_PATH" 2>/dev/null)" - [[ -n "$_cfg_script" && -x "$_cfg_script" ]] && deploy_script="$_cfg_script" +if [[ -n "${IA_PROJECT_ID:-}" && -x "${DEPLOY_IA}/run-project-hooks.sh" ]]; then + "${DEPLOY_IA}/run-project-hooks.sh" "$TARGET_BRANCH" --import-v1 --skipSetupHost +else + deploy_script="$PROJECT_ROOT/deploy/scripts_v2/deploy.sh" + if [[ -n "${PROJECT_CONFIG_PATH:-}" && -f "${PROJECT_CONFIG_PATH:-}" ]] && command -v jq >/dev/null 2>&1; then + _cfg_script="$(jq -r '.deploy.deploy_script_path // ""' "$PROJECT_CONFIG_PATH" 2>/dev/null)" + [[ -n "$_cfg_script" && -x "$_cfg_script" ]] && deploy_script="$_cfg_script" + fi + "$deploy_script" "$TARGET_BRANCH" --import-v1 --skipSetupHost fi -"$deploy_script" "$TARGET_BRANCH" --import-v1 --skipSetupHost echo "[deploy-by-script-to] Step 5/5: checkout test..." git checkout test diff --git a/deploy/lib/README.md b/deploy/lib/README.md new file mode 100644 index 0000000..9542a2b --- /dev/null +++ b/deploy/lib/README.md @@ -0,0 +1,7 @@ +# Shared deploy helpers (ia_dev) + +LeCoffre conserve la logique métier et SSH ciblée dans `lecoffre_ng_test/deploy/scripts_v2/` (dont `_lib/` : `ssh.sh`, `colors.sh`, modules `deploy-*.sh`). + +Ce répertoire est réservé aux **extraits réellement génériques** (plusieurs projets, sans Prisma ni règles LeCoffre), extraits **après** stabilisation de la segmentation côté projet. Aujourd’hui les helpers SSH/proxy dupliqués ne sont pas déplacés ici pour éviter une double source de vérité avant revue transverse. + +Référence cadrage : dépôt LeCoffre, `deploy/DEPLOY_ORCHESTRATION_IA_DEV.md`. diff --git a/deploy/run-project-hooks.sh b/deploy/run-project-hooks.sh new file mode 100755 index 0000000..8b5bfaa --- /dev/null +++ b/deploy/run-project-hooks.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +# Run deploy.hooks.phases from projects//conf.json (paths relative to repository_root). +# If phases is empty or missing, exec deploy.deploy_script_path with the same arguments. +# Usage: run-project-hooks.sh [options passed to each phase / fallback script] +# Requires: IA_PROJECT_ID, IA_DEV_ROOT (or re-exec from project root like change-to-all-branches). +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)" + +if [[ -z "${IA_PROJECT_ID:-}" ]]; then + echo "[run-project-hooks][ERROR] IA_PROJECT_ID is not set" >&2 + exit 1 +fi + +# shellcheck source=../lib/project_config.sh +source "${IA_DEV_ROOT}/lib/project_config.sh" +# 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 +REPO_ROOT="${IA_PROJECT_GIT_ROOT:-}" +if [[ -z "$REPO_ROOT" || ! -d "$REPO_ROOT" ]]; then + echo "[run-project-hooks][ERROR] Could not resolve repository root for project ${IA_PROJECT_ID}" >&2 + exit 1 +fi + +CONF="${PROJECT_CONFIG_PATH:-}" +if [[ -z "$CONF" || ! -f "$CONF" ]]; then + echo "[run-project-hooks][ERROR] Missing conf: ${CONF:-}" >&2 + exit 1 +fi + +if ! command -v jq >/dev/null 2>&1; then + echo "[run-project-hooks][ERROR] jq is required to read deploy.hooks.phases" >&2 + exit 1 +fi + +DEPLOY_SCRIPT_PATH="$(jq -r '.deploy.deploy_script_path // empty' "$CONF")" +if [[ -z "$DEPLOY_SCRIPT_PATH" || ! -f "$DEPLOY_SCRIPT_PATH" ]]; then + echo "[run-project-hooks][ERROR] deploy.deploy_script_path missing or not a file: ${DEPLOY_SCRIPT_PATH:-}" >&2 + exit 1 +fi + +PHASE_COUNT="$(jq '.deploy.hooks.phases // [] | length' "$CONF")" +if [[ "$PHASE_COUNT" == "0" ]]; then + exec bash "$DEPLOY_SCRIPT_PATH" "$@" +fi + +mapfile -t PHASE_SCRIPTS < <(jq -r '.deploy.hooks.phases[]? | if type == "string" then . elif type == "object" and (.run | type == "string") then .run else empty end' "$CONF") + +if [[ ${#PHASE_SCRIPTS[@]} -eq 0 ]]; then + exec bash "$DEPLOY_SCRIPT_PATH" "$@" +fi + +for rel in "${PHASE_SCRIPTS[@]}"; do + [[ -z "$rel" ]] && continue + phase_path="${REPO_ROOT}/${rel}" + if [[ ! -f "$phase_path" ]]; then + echo "[run-project-hooks][ERROR] Phase script not found: ${phase_path}" >&2 + exit 1 + fi + echo "[run-project-hooks] Running: ${rel} $*" + bash "$phase_path" "$@" +done diff --git a/projects/algo/conf.json b/projects/algo/conf.json index 0f102f7..d600c0a 100644 --- a/projects/algo/conf.json +++ b/projects/algo/conf.json @@ -8,9 +8,13 @@ "/home/desk/code/algo/deploy/lecoffre-front-main" ], "deploy": { + "repository_root": "/home/desk/code/algo", "scripts_path": "/home/desk/code/algo/deploy/scripts_v2", "deploy_script_path": "/home/desk/code/algo/deploy/scripts_v2/deploy.sh", - "secrets_path": "/home/desk/code/algo/.secrets" + "secrets_path": "/home/desk/code/algo/.secrets", + "hooks": { + "phases": [] + } }, "version": { "package_json_paths": [ diff --git a/projects/enso/conf.json b/projects/enso/conf.json index 718a4d1..684e6fa 100644 --- a/projects/enso/conf.json +++ b/projects/enso/conf.json @@ -8,9 +8,13 @@ "/home/desk/code/enso/deploy/lecoffre-front-main" ], "deploy": { + "repository_root": "/home/desk/code/enso", "scripts_path": "/home/desk/code/enso/deploy/scripts_v2", "deploy_script_path": "/home/desk/code/enso/deploy/scripts_v2/deploy.sh", - "secrets_path": "/home/desk/code/enso/.secrets" + "secrets_path": "/home/desk/code/enso/.secrets", + "hooks": { + "phases": [] + } }, "version": { "package_json_paths": [ diff --git a/projects/lecoffreio/conf.json b/projects/lecoffreio/conf.json index ef7dd38..c942602 100644 --- a/projects/lecoffreio/conf.json +++ b/projects/lecoffreio/conf.json @@ -13,7 +13,9 @@ "deploy_script_path": "/home/desk/code/lecoffre_ng_test/deploy/scripts_v2/deploy.sh", "secrets_path": "/home/desk/code/lecoffre_ng_test/.secrets", "hooks": { - "phases": [] + "phases": [ + "deploy/scripts_v2/deploy.sh" + ] } }, "version": {