diff --git a/.cursor/agents/deploy-pprod-or-prod.md b/.cursor/agents/deploy-pprod-or-prod.md new file mode 100644 index 0000000..33c97c3 --- /dev/null +++ b/.cursor/agents/deploy-pprod-or-prod.md @@ -0,0 +1,41 @@ +--- +name: deploy-pprod-or-prod +description: Déploie vers pprod ou prod en suivant le workflow change-to-all-branches, deploy-by-script-to, puis push-by-script. Paramètre obligatoire pprod ou prod. +model: inherit +is_background: false +--- + +# Agent deploy-pprod-or-prod + +**Contexte projet :** La configuration et la documentation du projet sont dans `projects//` (chemin absolu : `/home/desk/code/lecoffre_ng_test/ia_dev/projects/`). L'identifiant `` vient du slug (contenu du fichier `../ai_project_id`). Rappeler ce chemin en début et en fin d'exécution. + +**Rôle de l'agent :** Exécuter le déploiement vers **pprod** ou **prod** en suivant strictement le workflow ci-dessous. Paramètre obligatoire : `pprod` ou `prod`. En cas d'échec d'une étape, corriger (analyse des logs, corrections code/config/doc), relancer jusqu'à succès ou blocage nécessitant instruction utilisateur. + +**Répertoire d'exécution :** Racine du dépôt projet = `/home/desk/code/lecoffre_ng_test`. Tous les scripts sont invoqués après `cd` vers cette racine. + +## Workflow obligatoire + +1. **Vérifier la branche** : La machine doit être sur la branche **test** au démarrage. Si ce n'est pas le cas, indiquer à l'utilisateur de passer sur test (ou exécuter `git checkout test` depuis la racine projet) avant de continuer. + +2. **Lancer /change-to-all-branches** (sur test) : + - Exécuter intégralement l'agent change-to-all-branches (commande /change-to-all-branches) : push-by-script puis `./ia_dev/deploy/change-to-all-branches.sh`. + - **Si KO :** Analyser la sortie et les logs (logs/deploy_*.log), identifier la cause, appliquer les corrections, relancer /change-to-all-branches jusqu'à succès. + - **Si OK :** Passer à l'étape 3. + +3. **Lancer le script deploy-by-script-to** avec la branche en paramètre (`pprod` ou `prod`) : + - Commande : `cd /home/desk/code/lecoffre_ng_test && ./ia_dev/deploy/deploy-by-script-to.sh ` + - Le script fait : checkout sur la branche en paramètre, vérification que `.secrets/` existe, mise à jour forcée de la branche locale sur la branche distante, déploiement (deploy.sh avec --import-v1 --skipSetupHost), checkout test. + - **Si KO :** Analyser la sortie et les logs, identifier la cause, appliquer les corrections, relancer le script jusqu'à succès. + - **Si OK :** Passer à l'étape 4. + +4. **Checkout test** : Le script remet déjà sur test. Vérifier que la branche courante est test après le script. + +5. **Lancer /push-by-script** : Exécuter intégralement l'agent push-by-script (commande /push-by-script). Message de commit fourni par l'agent selon les règles du projet. + +## Horodatage et contexte + +Appliquer intégralement le bloc défini dans `.cursor/rules/cloture-evolution.mdc` (début et fin d'exécution, lancement et retour des sub-agents). Au début et à la fin : date/heure, projet (contenu de `../ai_project_id`), branche du dépôt dans `../`, répertoire de travail du dépôt dans `../`. + +## Clôture complète + +Appliquer **intégralement** `.cursor/rules/cloture-evolution.mdc`. Aucune dérogation. diff --git a/deploy/deploy-by-script-to.sh b/deploy/deploy-by-script-to.sh index 8b18d46..fd4c08c 100755 --- a/deploy/deploy-by-script-to.sh +++ b/deploy/deploy-by-script-to.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# deploy-by-script-to : 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. +# deploy-by-script-to : checkout target, verify .secrets/, force sync with origin, deploy target, checkout test. +# Centralized in ia_dev. Call after /change-to-all-branches (agent). Requires: start on branch test. Target: pprod | prod only. set -euo pipefail if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then @@ -17,40 +17,37 @@ fi TARGET_BRANCH="${1:-}" if [[ -z "$TARGET_BRANCH" ]]; then - echo "[deploy-by-script-to][ERROR] Missing argument (expected: test | pprod | prod)" >&2 - echo "Usage: ./ia_dev/deploy/deploy-by-script-to.sh (or ./deploy/deploy-by-script-to.sh if deploy wraps ia_dev)" >&2 + echo "[deploy-by-script-to][ERROR] Missing argument (expected: pprod | prod)" >&2 + echo "Usage: ./ia_dev/deploy/deploy-by-script-to.sh (pprod or prod only)" >&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 " >&2 +if [[ ! "$TARGET_BRANCH" =~ ^(pprod|prod)$ ]]; then + echo "[deploy-by-script-to][ERROR] Invalid target branch: must be pprod or prod (got: '${TARGET_BRANCH}')" >&2 + echo "Usage: ./ia_dev/deploy/deploy-by-script-to.sh " >&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 + echo "[deploy-by-script-to][ERROR] Must be on branch 'test' (current: '${current}'). Run /change-to-all-branches first." >&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}..." +echo "[deploy-by-script-to] Step 1/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}" +SECRETS_DIR="${PROJECT_ROOT}/.secrets/${TARGET_BRANCH}" +if [[ ! -d "$SECRETS_DIR" ]]; then + echo "[deploy-by-script-to][ERROR] .secrets/${TARGET_BRANCH} does not exist at ${SECRETS_DIR}" >&2 + exit 1 fi +echo "[deploy-by-script-to] Step 2/5: .secrets/${TARGET_BRANCH} OK" + +echo "[deploy-by-script-to] Step 3/5: force sync local branch with origin/${TARGET_BRANCH}..." +git fetch origin +git reset --hard "origin/${TARGET_BRANCH}" 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