**Motivations:** - Execute deploy.hooks.phases from conf.json with fallback to deploy_script_path; align algo/enso with repository_root and empty phases. **Root causes:** - Deploy entry was hardcoded to deploy.sh; hooks array unused. **Correctifs:** - None. **Evolutions:** - deploy/run-project-hooks.sh; change-to-all-branches.sh and deploy-by-script-to.sh call it when IA_PROJECT_ID is set; lecoffreio phases list deploy/scripts_v2/deploy.sh; algo/enso repository_root + hooks.phases []; deploy/lib/README.md placeholder for future generic extract. **Pages affectées:** - deploy/run-project-hooks.sh, deploy/change-to-all-branches.sh, deploy/deploy-by-script-to.sh, deploy/lib/README.md, projects/lecoffreio/conf.json, projects/algo/conf.json, projects/enso/conf.json
66 lines
2.4 KiB
Bash
Executable File
66 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run deploy.hooks.phases from projects/<id>/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 <env> [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
|