diff --git a/docs/RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME.md b/docs/RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME.md index 187093c..da5865d 100644 --- a/docs/RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME.md +++ b/docs/RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME.md @@ -103,6 +103,8 @@ Num checkout local, confirmar que ambos os SHAs de §6.1 são ancestros da ponta **Sem VPN**, muitos runners Paperclip **não têm rota** para o LXC interno — ver nota em [CRM `crm.pmx.bet` — PHP deploy](https://git.bitreport.pt/BitReport.pt/paperclip/src/branch/main/docs/runbooks/CRM_PMX_BET_PHP_MIGRATE_DEPLOY.md). Com acesso a **`10.10.20.22`**: +**Script (Gitea + runtime):** a partir da raiz deste repositório, `scripts/crm/verify_pmx_bet_due_time_deploy.sh gitea` confirma que `main` no Gitea contém os SHAs de §6.1 (clone raso + `merge-base --is-ancestor`; ajustar `CRM_GIT_FETCH_DEPTH` se a história entre a ponta e os fixes exceder o valor por omissão). Com VPN/SSH, `CRM_PMX_SSH=USER@10.10.20.22 ./scripts/crm/verify_pmx_bet_due_time_deploy.sh runtime` replica o bloco manual abaixo no docroot de autodeploy. + 1. **Árvore `git` usada pelo autodeploy** (`/data/wwwroot/crm-repo`): ```bash diff --git a/scripts/crm/verify_pmx_bet_due_time_deploy.sh b/scripts/crm/verify_pmx_bet_due_time_deploy.sh new file mode 100755 index 0000000..e4d00c9 --- /dev/null +++ b/scripts/crm/verify_pmx_bet_due_time_deploy.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# Gitea + runtime checks for CRM `due_time` normalization on crm.pmx.bet. +# See docs/RUNBOOK_REPORTER_CRM_TASKS_DUE_TIME.md §6 (BIT-1048 / BIT-1049 / BIT-887). +# +# Usage: +# ./scripts/crm/verify_pmx_bet_due_time_deploy.sh gitea +# CRM_PMX_SSH=deploy@10.10.20.22 ./scripts/crm/verify_pmx_bet_due_time_deploy.sh runtime +set -euo pipefail + +readonly CRM_REPO_URL="${CRM_REPO_URL:-https://git.bitreport.pt/BitReport.pt/CRM_Project.git}" +readonly SHA_E0="${DUE_TIME_FIX_SHA_E0:-e0f2b62bcc59a509a8b0543e7282d58bca023b54}" +readonly SHA_30="${DUE_TIME_FIX_SHA_30:-30b74b19d3e27a53e5fcaf9a89e0989651f1222e}" +readonly RUNTIME_GIT_DIR="${CRM_PMX_RUNTIME_GIT_DIR:-/data/wwwroot/crm-repo}" +readonly FETCH_DEPTH="${CRM_GIT_FETCH_DEPTH:-500}" + +cmd_gitea() { + local tip tmp_repo + tip="$(git ls-remote "$CRM_REPO_URL" refs/heads/main | awk '{print $1}')" + echo "verify_pmx_bet_due_time_deploy: gitea refs/heads/main -> ${tip}" + + tmp_repo="$(mktemp -d)" + # Capture path at trap install time (RETURN runs before the function frame is discarded). + trap "rm -rf \"${tmp_repo}\"" RETURN + + git clone --quiet --depth 1 --branch main "$CRM_REPO_URL" "$tmp_repo/repo" + git -C "$tmp_repo/repo" fetch --quiet --depth="$FETCH_DEPTH" origin main + + git -C "$tmp_repo/repo" merge-base --is-ancestor "$SHA_E0" HEAD + git -C "$tmp_repo/repo" merge-base --is-ancestor "$SHA_30" HEAD + + local head_local + head_local="$(git -C "$tmp_repo/repo" rev-parse HEAD)" + echo "verify_pmx_bet_due_time_deploy: gitea ancestor OK (${SHA_E0}, ${SHA_30} ⊆ HEAD ${head_local})" + if [[ "$head_local" != "$tip" ]]; then + echo "verify_pmx_bet_due_time_deploy: note: shallow HEAD ${head_local} may differ from ls-remote tip ${tip}; widen CRM_GIT_FETCH_DEPTH if ancestor check fails after a large fast-forward." >&2 + fi +} + +cmd_runtime() { + : "${CRM_PMX_SSH:?set CRM_PMX_SSH, e.g. deploy@10.10.20.22 (VPN required from most lab runners)}" + + ssh -o BatchMode=yes "$CRM_PMX_SSH" \ + "set -euo pipefail; cd '${RUNTIME_GIT_DIR}' && git fetch -q origin && git rev-parse HEAD && git merge-base --is-ancestor ${SHA_E0} HEAD && git merge-base --is-ancestor ${SHA_30} HEAD && echo ancestors_ok" +} + +case "${1:-}" in + gitea) cmd_gitea ;; + runtime) cmd_runtime ;; + *) + echo "usage: $0 gitea|runtime" >&2 + exit 1 + ;; +esac