**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/
109 lines
3.4 KiB
Bash
Executable File
109 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Aligns only origin/test, origin/pprod, origin/prod to current branch SHA. main is not aligned.
|
|
set -euo pipefail
|
|
|
|
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
echo "[branch-align][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_DIR="$(cd "$(dirname "$SCRIPT_REAL")" && pwd)"
|
|
if [[ "$(pwd)" != "$PROJECT_ROOT" ]]; then
|
|
cd "$PROJECT_ROOT" && exec "${DEPLOY_DIR}/$(basename "${BASH_SOURCE[0]:-$0}")" "$@"
|
|
fi
|
|
|
|
env_branch="${1:-}"
|
|
if [[ -z "$env_branch" ]]; then
|
|
echo "[branch-align][ERROR] Missing <env> argument (expected: main|test|pprod|prod)" >&2
|
|
echo "Usage: ./deploy/branch-align.sh <env>" >&2
|
|
exit 1
|
|
fi
|
|
if [[ ! "$env_branch" =~ ^(main|test|pprod|prod)$ ]]; then
|
|
echo "[branch-align][ERROR] Invalid <env>: must be main, test, pprod or prod (got: '${env_branch}')" >&2
|
|
echo "Usage: ./deploy/branch-align.sh <env>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
current_branch="$(git rev-parse --abbrev-ref HEAD)"
|
|
if [[ "$current_branch" != "$env_branch" ]]; then
|
|
echo "[branch-align][ERROR] Must be on branch '${env_branch}' (current: '${current_branch}')" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Fetch latest refs
|
|
|
|
git fetch origin
|
|
|
|
target_sha="$(git rev-parse "$env_branch")"
|
|
origin_env_sha="$(git rev-parse "origin/${env_branch}")"
|
|
|
|
if [[ "$target_sha" != "$origin_env_sha" ]]; then
|
|
echo "[branch-align] origin/${env_branch} differs from local ${env_branch}. Updating remote to local (env priority)."
|
|
git push --force-with-lease origin "${target_sha}:${env_branch}"
|
|
git fetch origin
|
|
fi
|
|
|
|
# Align all three branches to env SHA
|
|
for br in test pprod prod; do
|
|
if [[ "$br" == "$env_branch" ]]; then
|
|
# Ensure tracking exists
|
|
git branch --set-upstream-to="origin/${br}" "$br" >/dev/null 2>&1 || true
|
|
continue
|
|
fi
|
|
|
|
git branch -f "$br" "$target_sha"
|
|
git push --force-with-lease origin "${target_sha}:${br}"
|
|
git branch --set-upstream-to="origin/${br}" "$br" >/dev/null 2>&1 || true
|
|
|
|
done
|
|
|
|
# Also ensure env branch tracks its remote
|
|
|
|
git branch --set-upstream-to="origin/${env_branch}" "$env_branch" >/dev/null 2>&1 || true
|
|
|
|
# Verify last 30 commits are identical
|
|
|
|
tmp1="$(mktemp -t branch-align-test.XXXXXX)"
|
|
tmp2="$(mktemp -t branch-align-pprod.XXXXXX)"
|
|
tmp3="$(mktemp -t branch-align-prod.XXXXXX)"
|
|
cleanup() {
|
|
rm -f "$tmp1" "$tmp2" "$tmp3"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
git log -30 --format=%H origin/test > "$tmp1"
|
|
git log -30 --format=%H origin/pprod > "$tmp2"
|
|
git log -30 --format=%H origin/prod > "$tmp3"
|
|
|
|
if ! diff -u "$tmp1" "$tmp2" >/dev/null; then
|
|
echo "[branch-align][ERROR] Last 30 commits differ: origin/test vs origin/pprod" >&2
|
|
exit 1
|
|
fi
|
|
if ! diff -u "$tmp1" "$tmp3" >/dev/null; then
|
|
echo "[branch-align][ERROR] Last 30 commits differ: origin/test vs origin/prod" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Final assertions
|
|
|
|
if [[ "$(git rev-parse --abbrev-ref HEAD)" != "$env_branch" ]]; then
|
|
echo "[branch-align][ERROR] Branch changed unexpectedly" >&2
|
|
exit 1
|
|
fi
|
|
|
|
sha_test="$(git rev-parse origin/test)"
|
|
sha_pprod="$(git rev-parse origin/pprod)"
|
|
sha_prod="$(git rev-parse origin/prod)"
|
|
|
|
if [[ "$sha_test" != "$sha_pprod" ]] || [[ "$sha_test" != "$sha_prod" ]]; then
|
|
echo "[branch-align][ERROR] Remote branches are not aligned" >&2
|
|
echo "origin/test=$sha_test" >&2
|
|
echo "origin/pprod=$sha_pprod" >&2
|
|
echo "origin/prod=$sha_prod" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "[branch-align] OK: origin/test, origin/pprod, origin/prod aligned to ${sha_test}"
|