admin/scripts/notify-deploy.sh
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

89 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Notify the ops Telegram group after a frontend production deploy attempt.
#
# Usage:
# ./scripts/notify-deploy.sh
# DEPLOY_STATUS=failed ./scripts/notify-deploy.sh
#
# Optional env:
# DEPLOY_SHA git sha (default: GITHUB_SHA or HEAD)
# DEPLOY_STATUS success | failed
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NOTIFY="$SCRIPT_DIR/notify-ops-telegram.sh"
if [[ ! -x "$NOTIFY" ]]; then
echo "[ghabilee-frontend-deploy-notify] skipped: missing $NOTIFY" >&2
exit 0
fi
STATUS="${DEPLOY_STATUS:-success}"
RAW_SHA="${DEPLOY_SHA:-${GITHUB_SHA:-}}"
if [[ -z "$RAW_SHA" ]] && command -v git >/dev/null 2>&1; then
RAW_SHA="$(git rev-parse HEAD 2>/dev/null || true)"
fi
SHORT_SHA="${RAW_SHA:0:7}"
if [[ -z "$SHORT_SHA" ]]; then
SHORT_SHA="unknown"
fi
VERSION="${DEPLOY_VERSION:-}"
if [[ -z "$VERSION" || "$VERSION" == "?" ]]; then
if [[ -f package.json ]]; then
VERSION="$(
python3 -c 'import json,sys; print(json.load(open("package.json")).get("version") or "?")' \
2>/dev/null || echo "?"
)"
else
VERSION="?"
fi
fi
SUBJECT="${DEPLOY_COMMIT_SUBJECT:-}"
if [[ -z "$SUBJECT" ]] && command -v git >/dev/null 2>&1; then
SUBJECT="$(git log -1 --format=%s 2>/dev/null || true)"
fi
# فقط عنوان commit — body چندخطی نباید در پیام بیاید
if [[ -n "$SUBJECT" ]]; then
SUBJECT="${SUBJECT%%$'\n'*}"
SUBJECT="${SUBJECT%%$'\r'*}"
fi
if [[ ${#SUBJECT} -gt 100 ]]; then
SUBJECT="${SUBJECT:0:97}..."
fi
MESSAGE="$(
STATUS="$STATUS" VERSION="$VERSION" SHORT_SHA="$SHORT_SHA" SUBJECT="$SUBJECT" python3 - <<'PY'
import os
from datetime import datetime
from zoneinfo import ZoneInfo
def fa(s: str) -> str:
return s.translate(str.maketrans("0123456789", "۰۱۲۳۴۵۶۷۸۹"))
status = os.environ.get("STATUS", "success")
version = os.environ.get("VERSION", "?")
sha = os.environ.get("SHORT_SHA", "?")
subject = os.environ.get("SUBJECT", "").strip()
now = datetime.now(ZoneInfo("Asia/Tehran"))
time_line = fa(now.strftime("%H:%M"))
lines: list[str] = []
if status == "failed":
lines.append("😵 فرانت قبیله گیر کرد — CI یه بار دیگه؟")
else:
lines.append("✨ ظاهر قبیله تازه شد — برو ببین!")
lines.append("")
lines.append(f"🕐 {time_line} · نسخه {fa(version)} · {sha}")
if subject:
lines.append(f"📝 {subject}")
if status != "failed":
lines.append("🏠 https://ghabilee.ir")
print("\n".join(lines))
PY
)"
printf '%s' "$MESSAGE" | "$NOTIFY"