ia_dev/deploy/deploy-by-script-to.sh
Nicolas Cantu 907807f4d6 Generic project config, deploy scripts, gitea-issues, no reverse dependency
**Motivations:**
- Single config file per project (projects/<id>/conf.json)
- Project must not depend on ia_dev; only ia_dev solicits the project

**Root causes:**
- N/A (evolution)

**Correctifs:**
- N/A

**Evolutions:**
- lib/project_config.sh: resolve PROJECT_SLUG from IA_PROJECT, .ia_project, ai_project_id; PROJECT_CONFIG_PATH = projects/<id>/conf.json
- projects/lecoffreio.json moved to projects/lecoffreio/conf.json; projects/ia_dev/conf.json added
- deploy: branch-align, bump-version, change-to-all-branches, pousse, deploy-by-script-to use PROJECT_ROOT/IA_DEV_ROOT and project_config.sh; SCRIPT_REAL for symlink-safe paths
- deploy/_lib: shared colors, env-map, ssh, git-flow
- gitea-issues: mail list/mark-read/get-thread/send-reply, thread log, agent-loop, wiki scripts; lib.sh loads project config
- README: principle no dependency from host project; invoke ./ia_dev/deploy/bump-version.sh etc. from repo root

**Pages affectées:**
- README.md, projects/README.md, lib/, deploy/, gitea-issues/, projects/lecoffreio/, projects/ia_dev/
2026-03-12 22:35:15 +01:00

62 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# deploy-by-script-to <target_branch>: 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 <target_branch> argument (expected: test | pprod | prod)" >&2
echo "Usage: ./ia_dev/deploy/deploy-by-script-to.sh <target_branch> (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 <target_branch>" >&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"