mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 19:41:09 +02:00
feat(ci): add Telegram notifications and Grafana CI/CD dashboard
- Add notify-start job with Telegram notification for build start - Add notify-complete job with build status and duration notification - Push CI metrics to Prometheus Pushgateway for Grafana visualization - Create CI/CD Grafana dashboard with build status, duration, and history - Add Pushgateway scrape config to Prometheus Requires TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, and PUSHGATEWAY_URL secrets. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
ebd0e53c9a
commit
618c58c519
3 changed files with 1100 additions and 0 deletions
318
.github/workflows/ci.yml
vendored
318
.github/workflows/ci.yml
vendored
|
|
@ -328,6 +328,150 @@ jobs:
|
|||
echo "| storage-web | ${{ steps.changes.outputs.storage-web }} |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| telegram-stats-bot | ${{ steps.changes.outputs.telegram-stats-bot }} |" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
# ===========================================
|
||||
# Notify Build Start
|
||||
# ===========================================
|
||||
notify-start:
|
||||
name: Notify Build Start
|
||||
runs-on: ubuntu-latest
|
||||
needs: detect-changes
|
||||
if: needs.detect-changes.outputs.any-changes == 'true'
|
||||
steps:
|
||||
- name: Count services to build
|
||||
id: count
|
||||
run: |
|
||||
COUNT=0
|
||||
SERVICES=""
|
||||
|
||||
if [ "${{ needs.detect-changes.outputs.mana-core-auth }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• mana-core-auth\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.manacore-web }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• manacore-web\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.chat-backend }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• chat-backend\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.chat-web }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• chat-web\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.todo-backend }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• todo-backend\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.todo-web }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• todo-web\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.calendar-backend }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• calendar-backend\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.calendar-web }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• calendar-web\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.clock-backend }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• clock-backend\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.clock-web }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• clock-web\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.contacts-backend }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• contacts-backend\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.contacts-web }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• contacts-web\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.presi-backend }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• presi-backend\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.presi-web }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• presi-web\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.storage-backend }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• storage-backend\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.storage-web }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• storage-web\n"
|
||||
fi
|
||||
if [ "${{ needs.detect-changes.outputs.telegram-stats-bot }}" == "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
SERVICES="${SERVICES}• telegram-stats-bot\n"
|
||||
fi
|
||||
|
||||
# Estimate build time (roughly 3-5 min per service, parallel execution)
|
||||
if [ $COUNT -le 3 ]; then
|
||||
ESTIMATE="~3-5 min"
|
||||
elif [ $COUNT -le 8 ]; then
|
||||
ESTIMATE="~5-8 min"
|
||||
else
|
||||
ESTIMATE="~8-12 min"
|
||||
fi
|
||||
|
||||
echo "count=$COUNT" >> $GITHUB_OUTPUT
|
||||
echo "services<<EOF" >> $GITHUB_OUTPUT
|
||||
echo -e "$SERVICES" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
echo "estimate=$ESTIMATE" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Send Telegram notification
|
||||
env:
|
||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||
run: |
|
||||
MESSAGE="🔨 *CI Build Started*
|
||||
|
||||
📦 *${{ steps.count.outputs.count }} services* building:
|
||||
${{ steps.count.outputs.services }}
|
||||
⏱️ Estimated: ${{ steps.count.outputs.estimate }}
|
||||
🔗 [View Build](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
|
||||
|
||||
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||
-d chat_id="${TELEGRAM_CHAT_ID}" \
|
||||
-d text="${MESSAGE}" \
|
||||
-d parse_mode="Markdown" \
|
||||
-d disable_web_page_preview="true" || true
|
||||
|
||||
- name: Push build-started metrics to Prometheus
|
||||
env:
|
||||
PUSHGATEWAY_URL: ${{ secrets.PUSHGATEWAY_URL }}
|
||||
run: |
|
||||
# Skip if no Pushgateway URL configured
|
||||
if [ -z "$PUSHGATEWAY_URL" ]; then
|
||||
echo "PUSHGATEWAY_URL not configured, skipping metrics push"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
START_EPOCH=$(date +%s)
|
||||
|
||||
# Push build-in-progress metric
|
||||
cat <<EOF | curl --data-binary @- "${PUSHGATEWAY_URL}/metrics/job/ci/run_id/${{ github.run_id }}/branch/${{ github.ref_name }}"
|
||||
# HELP ci_build_in_progress Whether a CI build is currently in progress
|
||||
# TYPE ci_build_in_progress gauge
|
||||
ci_build_in_progress 1
|
||||
# HELP ci_build_start_timestamp_seconds Unix timestamp when build started
|
||||
# TYPE ci_build_start_timestamp_seconds gauge
|
||||
ci_build_start_timestamp_seconds ${START_EPOCH}
|
||||
# HELP ci_build_services_count Number of services being built
|
||||
# TYPE ci_build_services_count gauge
|
||||
ci_build_services_count ${{ steps.count.outputs.count }}
|
||||
EOF
|
||||
|
||||
echo "Build-started metrics pushed to Pushgateway"
|
||||
|
||||
# ===========================================
|
||||
# Validation job - runs on PRs
|
||||
# ===========================================
|
||||
|
|
@ -858,3 +1002,177 @@ jobs:
|
|||
tags: ${{ steps.meta.outputs.tags }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
# ===========================================
|
||||
# Notify Build Complete
|
||||
# ===========================================
|
||||
notify-complete:
|
||||
name: Notify Build Complete
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- detect-changes
|
||||
- notify-start
|
||||
- build-mana-core-auth
|
||||
- build-manacore-web
|
||||
- build-chat-backend
|
||||
- build-chat-web
|
||||
- build-todo-backend
|
||||
- build-todo-web
|
||||
- build-calendar-backend
|
||||
- build-calendar-web
|
||||
- build-clock-backend
|
||||
- build-clock-web
|
||||
- build-contacts-backend
|
||||
- build-contacts-web
|
||||
- build-presi-backend
|
||||
- build-presi-web
|
||||
- build-storage-backend
|
||||
- build-storage-web
|
||||
- build-telegram-stats-bot
|
||||
if: always() && needs.detect-changes.outputs.any-changes == 'true'
|
||||
steps:
|
||||
- name: Calculate duration and status
|
||||
id: result
|
||||
run: |
|
||||
# Get workflow start time from GitHub API
|
||||
START_TIME="${{ github.event.repository.pushed_at }}"
|
||||
|
||||
# Calculate duration in minutes
|
||||
START_EPOCH=$(date -d "${{ github.event.head_commit.timestamp }}" +%s 2>/dev/null || date +%s)
|
||||
END_EPOCH=$(date +%s)
|
||||
DURATION_SECONDS=$((END_EPOCH - START_EPOCH))
|
||||
DURATION_MINUTES=$((DURATION_SECONDS / 60))
|
||||
DURATION_REMAINDER=$((DURATION_SECONDS % 60))
|
||||
|
||||
echo "duration=${DURATION_MINUTES}m ${DURATION_REMAINDER}s" >> $GITHUB_OUTPUT
|
||||
|
||||
# Count successful and failed builds
|
||||
SUCCESS=0
|
||||
FAILED=0
|
||||
SKIPPED=0
|
||||
FAILED_SERVICES=""
|
||||
SUCCESS_SERVICES=""
|
||||
|
||||
check_job() {
|
||||
local job_name=$1
|
||||
local result=$2
|
||||
if [ "$result" == "success" ]; then
|
||||
SUCCESS=$((SUCCESS + 1))
|
||||
SUCCESS_SERVICES="${SUCCESS_SERVICES}✅ ${job_name}\n"
|
||||
elif [ "$result" == "failure" ]; then
|
||||
FAILED=$((FAILED + 1))
|
||||
FAILED_SERVICES="${FAILED_SERVICES}❌ ${job_name}\n"
|
||||
elif [ "$result" == "skipped" ]; then
|
||||
SKIPPED=$((SKIPPED + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
check_job "mana-core-auth" "${{ needs.build-mana-core-auth.result }}"
|
||||
check_job "manacore-web" "${{ needs.build-manacore-web.result }}"
|
||||
check_job "chat-backend" "${{ needs.build-chat-backend.result }}"
|
||||
check_job "chat-web" "${{ needs.build-chat-web.result }}"
|
||||
check_job "todo-backend" "${{ needs.build-todo-backend.result }}"
|
||||
check_job "todo-web" "${{ needs.build-todo-web.result }}"
|
||||
check_job "calendar-backend" "${{ needs.build-calendar-backend.result }}"
|
||||
check_job "calendar-web" "${{ needs.build-calendar-web.result }}"
|
||||
check_job "clock-backend" "${{ needs.build-clock-backend.result }}"
|
||||
check_job "clock-web" "${{ needs.build-clock-web.result }}"
|
||||
check_job "contacts-backend" "${{ needs.build-contacts-backend.result }}"
|
||||
check_job "contacts-web" "${{ needs.build-contacts-web.result }}"
|
||||
check_job "presi-backend" "${{ needs.build-presi-backend.result }}"
|
||||
check_job "presi-web" "${{ needs.build-presi-web.result }}"
|
||||
check_job "storage-backend" "${{ needs.build-storage-backend.result }}"
|
||||
check_job "storage-web" "${{ needs.build-storage-web.result }}"
|
||||
check_job "telegram-stats-bot" "${{ needs.build-telegram-stats-bot.result }}"
|
||||
|
||||
echo "success=$SUCCESS" >> $GITHUB_OUTPUT
|
||||
echo "failed=$FAILED" >> $GITHUB_OUTPUT
|
||||
|
||||
if [ $FAILED -gt 0 ]; then
|
||||
echo "status=❌ FAILED" >> $GITHUB_OUTPUT
|
||||
echo "emoji=🔴" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "status=✅ SUCCESS" >> $GITHUB_OUTPUT
|
||||
echo "emoji=🟢" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
echo "failed_services<<EOF" >> $GITHUB_OUTPUT
|
||||
echo -e "$FAILED_SERVICES" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Send Telegram notification
|
||||
env:
|
||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||
run: |
|
||||
FAILED_INFO=""
|
||||
if [ "${{ steps.result.outputs.failed }}" != "0" ]; then
|
||||
FAILED_INFO="
|
||||
❌ *Failed:*
|
||||
${{ steps.result.outputs.failed_services }}"
|
||||
fi
|
||||
|
||||
MESSAGE="${{ steps.result.outputs.emoji }} *CI Build Complete*
|
||||
|
||||
${{ steps.result.outputs.status }}
|
||||
|
||||
📊 *Results:*
|
||||
✅ Success: ${{ steps.result.outputs.success }}
|
||||
❌ Failed: ${{ steps.result.outputs.failed }}
|
||||
|
||||
⏱️ Duration: ${{ steps.result.outputs.duration }}
|
||||
${FAILED_INFO}
|
||||
🔗 [View Build](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
|
||||
|
||||
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||
-d chat_id="${TELEGRAM_CHAT_ID}" \
|
||||
-d text="${MESSAGE}" \
|
||||
-d parse_mode="Markdown" \
|
||||
-d disable_web_page_preview="true" || true
|
||||
|
||||
- name: Push metrics to Prometheus
|
||||
if: always()
|
||||
env:
|
||||
PUSHGATEWAY_URL: ${{ secrets.PUSHGATEWAY_URL }}
|
||||
run: |
|
||||
# Skip if no Pushgateway URL configured
|
||||
if [ -z "$PUSHGATEWAY_URL" ]; then
|
||||
echo "PUSHGATEWAY_URL not configured, skipping metrics push"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Calculate duration in seconds for metrics
|
||||
START_EPOCH=$(date -d "${{ github.event.head_commit.timestamp }}" +%s 2>/dev/null || date +%s)
|
||||
END_EPOCH=$(date +%s)
|
||||
DURATION_SECONDS=$((END_EPOCH - START_EPOCH))
|
||||
|
||||
# Determine build status (1 = success, 0 = failed)
|
||||
if [ "${{ steps.result.outputs.failed }}" == "0" ]; then
|
||||
BUILD_STATUS=1
|
||||
else
|
||||
BUILD_STATUS=0
|
||||
fi
|
||||
|
||||
# Push metrics to Pushgateway
|
||||
cat <<EOF | curl --data-binary @- "${PUSHGATEWAY_URL}/metrics/job/ci/run_id/${{ github.run_id }}/branch/${{ github.ref_name }}"
|
||||
# HELP ci_build_duration_seconds Duration of CI build in seconds
|
||||
# TYPE ci_build_duration_seconds gauge
|
||||
ci_build_duration_seconds ${DURATION_SECONDS}
|
||||
# HELP ci_build_status Build status (1=success, 0=failed)
|
||||
# TYPE ci_build_status gauge
|
||||
ci_build_status ${BUILD_STATUS}
|
||||
# HELP ci_builds_success_total Number of successful service builds
|
||||
# TYPE ci_builds_success_total gauge
|
||||
ci_builds_success_total ${{ steps.result.outputs.success }}
|
||||
# HELP ci_builds_failed_total Number of failed service builds
|
||||
# TYPE ci_builds_failed_total gauge
|
||||
ci_builds_failed_total ${{ steps.result.outputs.failed }}
|
||||
# HELP ci_build_timestamp_seconds Unix timestamp of build completion
|
||||
# TYPE ci_build_timestamp_seconds gauge
|
||||
ci_build_timestamp_seconds ${END_EPOCH}
|
||||
# HELP ci_build_in_progress Whether a CI build is currently in progress
|
||||
# TYPE ci_build_in_progress gauge
|
||||
ci_build_in_progress 0
|
||||
EOF
|
||||
|
||||
echo "Metrics pushed to Pushgateway successfully"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue