|
14 | 14 | name: 🔧 Build & Test (PHP 8.4) |
15 | 15 | runs-on: ubuntu-latest |
16 | 16 |
|
| 17 | + env: |
| 18 | + GH_START_ISO: ${{ github.event.head_commit.timestamp }} |
| 19 | + |
17 | 20 | strategy: |
18 | 21 | fail-fast: false |
19 | 22 | matrix: |
|
71 | 74 | name: phpunit-coverage-report |
72 | 75 | path: .phpunit.cache/ |
73 | 76 |
|
| 77 | + - name: 📲 Notify Telegram |
| 78 | + if: always() |
| 79 | + env: |
| 80 | + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_CI_BOT_TOKEN }} |
| 81 | + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CI_CHAT_ID }} |
| 82 | + run: | |
| 83 | + |
| 84 | + START_TS=$(date -u -d "$GH_START_ISO" +%s) |
| 85 | + END_TS=$(date +%s) |
| 86 | + |
| 87 | + START_TIME=$(date -u -d "@$START_TS" +"%H:%M:%S UTC") |
| 88 | + END_TIME=$(date -u +"%H:%M:%S UTC") |
| 89 | + DURATION=$((END_TS - START_TS)) |
| 90 | + |
| 91 | + if [ "$DURATION" -lt 60 ]; then |
| 92 | + DURATION_STR="${DURATION}s" |
| 93 | + else |
| 94 | + DURATION_STR="$(($DURATION / 60))m $(($DURATION % 60))s" |
| 95 | + fi |
| 96 | + |
| 97 | + STATUS="✅ Tests passed successfully!" |
| 98 | + COLOR="🟢" |
| 99 | + HEADER="Maatify CI Report" |
| 100 | + |
| 101 | + if grep -q "FAILURES!" phpunit.log || [ "${{ job.status }}" != "success" ]; then |
| 102 | + STATUS="❌ Some tests failed. Please review the log." |
| 103 | + COLOR="🔴" |
| 104 | + HEADER="Maatify CI Alert" |
| 105 | + fi |
| 106 | + |
| 107 | + PROJECT="maatify/common" |
| 108 | + BRANCH="$GITHUB_REF_NAME" |
| 109 | + ACTOR="$GITHUB_ACTOR" |
| 110 | + URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" |
| 111 | + |
| 112 | + MESSAGE="📢 <b>${HEADER}</b> |
| 113 | + |
| 114 | + ${COLOR} ${STATUS} |
| 115 | + |
| 116 | + 📦 <b>Project:</b> ${PROJECT} |
| 117 | + 🧱 <b>Branch:</b> ${BRANCH} |
| 118 | + 👷♂️ <b>Committer:</b> ${ACTOR} |
| 119 | + |
| 120 | + ⏱ <b>Start:</b> ${START_TIME} |
| 121 | + 🕒 <b>End:</b> ${END_TIME} |
| 122 | + 📈 <b>Duration:</b> ${DURATION_STR} |
| 123 | + |
| 124 | + 🔗 <a href='${URL}'>View Run Log</a>" |
| 125 | + |
| 126 | + PAYLOAD=$(jq -n \ |
| 127 | + --arg chat_id "$TELEGRAM_CHAT_ID" \ |
| 128 | + --arg text "$MESSAGE" \ |
| 129 | + --arg parse_mode "HTML" \ |
| 130 | + '{chat_id: $chat_id, text: $text, parse_mode: $parse_mode}') |
| 131 | + |
| 132 | + RESPONSE=$(curl -s -o /tmp/tg_resp.json -w "%{http_code}" \ |
| 133 | + -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ |
| 134 | + -H "Content-Type: application/json" \ |
| 135 | + -d "$PAYLOAD") |
| 136 | + |
| 137 | + echo "Raw Telegram Response (HTTP $RESPONSE):" |
| 138 | + cat /tmp/tg_resp.json |
| 139 | + |
| 140 | + if [ "$RESPONSE" -ne 200 ]; then |
| 141 | + echo "⚠️ Telegram notification failed (HTTP $RESPONSE)" >> $GITHUB_STEP_SUMMARY |
| 142 | + cat /tmp/tg_resp.json >> $GITHUB_STEP_SUMMARY |
| 143 | + else |
| 144 | + echo "✅ Telegram notification sent successfully." >> $GITHUB_STEP_SUMMARY |
| 145 | + fi |
| 146 | + |
74 | 147 | - name: 📊 Summary |
75 | 148 | if: always() |
76 | 149 | run: | |
|
0 commit comments