TSHARPS-CI/ci-notify.sh
Claude BM 9b7abec506 feat: TSHARPS-CI external runner — branch-independent CI pipeline
Complete CI system that lives outside TSHARPS branches:
- ci-webhook.py: HTTP server on port 9500, receives Gitea push webhooks
- ci-runner.sh: runs feature manifests, pytest, package checks (read-only)
- ci-notify.sh: sends results to Telegram CICD Pipeline topic (4706)
- ci-config.json: branch→worktree mapping, tokens, timeouts
- README.md: branch model, promotion workflow, switch-back plan

Same tests for ALL branches. No drift. Runner self-monitors for crashes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 03:25:31 +00:00

58 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# TSHARPS CI — Telegram Notification Sender
# Sends CI results to the CICD Pipeline Telegram topic.
# Called by ci-runner.sh with results.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CONFIG="$SCRIPT_DIR/ci-config.json"
BOT_TOKEN=$(python3 -c "import json; print(json.load(open('$CONFIG'))['telegram_bot_token'])")
CHAT_ID=$(python3 -c "import json; print(json.load(open('$CONFIG'))['telegram_chat_id'])")
TOPIC_ID=$(python3 -c "import json; print(json.load(open('$CONFIG'))['telegram_topic_id'])")
TAG_USERS=$(python3 -c "import json; users=json.load(open('$CONFIG')).get('tag_users_on_fail',[]); print(' '.join('@'+u for u in users))")
BRANCH="$1"
COMMIT="$2"
STATUS="$3" # "pass" or "fail" or "error"
SUMMARY="$4" # e.g., "940 passed, 0 failed, 393 skipped"
FEATURES="$5" # e.g., "31/31 features verified"
DURATION="$6" # e.g., "12.3s"
ACTOR="$7" # who pushed
if [ "$STATUS" = "pass" ]; then
ICON="✅"
MSG="${ICON} CI PASSED on ${BRANCH} (${COMMIT})
Tests: ${SUMMARY}
Features: ${FEATURES}
Duration: ${DURATION}
Pushed by: ${ACTOR}"
elif [ "$STATUS" = "fail" ]; then
ICON="❌"
MSG="${ICON} CI FAILED on ${BRANCH} (${COMMIT})
Tests: ${SUMMARY}
Features: ${FEATURES}
Duration: ${DURATION}
Pushed by: ${ACTOR}
${TAG_USERS} — this build needs attention."
elif [ "$STATUS" = "error" ]; then
ICON="🚨"
MSG="${ICON} CI RUNNER ERROR on ${BRANCH} (${COMMIT})
The CI runner itself failed — not a test failure.
Check logs: journalctl -u tsharps-ci --since '5 minutes ago'
${TAG_USERS} — runner needs attention."
fi
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d "chat_id=${CHAT_ID}" \
-d "message_thread_id=${TOPIC_ID}" \
-d "text=${MSG}" > /dev/null 2>&1
exit 0