|
10 | 10 | tests: |
11 | 11 | runs-on: ubuntu-latest |
12 | 12 |
|
| 13 | + env: |
| 14 | + GH_START_ISO: ${{ github.event.head_commit.timestamp }} |
| 15 | + APP_ENV: testing |
| 16 | + |
13 | 17 | strategy: |
14 | 18 | matrix: |
15 | 19 | php: [ "8.4" ] # ✅ Only 8.4 supported officially |
|
48 | 52 |
|
49 | 53 | - name: 🐳 Docker Build Check |
50 | 54 | run: docker build -t maatify/bootstrap:test -f docker/Dockerfile . |
| 55 | + |
| 56 | + - name: 📲 Notify Telegram |
| 57 | + if: always() |
| 58 | + env: |
| 59 | + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_CI_BOT_TOKEN }} |
| 60 | + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CI_CHAT_ID }} |
| 61 | + run: | |
| 62 | + |
| 63 | + START_TS=$(date -u -d "$GH_START_ISO" +%s) |
| 64 | + END_TS=$(date +%s) |
| 65 | + |
| 66 | + START_TIME=$(date -u -d "@$START_TS" +"%H:%M:%S UTC") |
| 67 | + END_TIME=$(date -u +"%H:%M:%S UTC") |
| 68 | + DURATION=$((END_TS - START_TS)) |
| 69 | + |
| 70 | + if [ "$DURATION" -lt 60 ]; then |
| 71 | + DURATION_STR="${DURATION}s" |
| 72 | + else |
| 73 | + DURATION_STR="$(($DURATION / 60))m $(($DURATION % 60))s" |
| 74 | + fi |
| 75 | + |
| 76 | + STATUS="✅ Tests passed successfully!" |
| 77 | + COLOR="🟢" |
| 78 | + HEADER="Maatify CI Report" |
| 79 | + |
| 80 | + if grep -q "FAILURES!" phpunit.log || [ "${{ job.status }}" != "success" ]; then |
| 81 | + STATUS="❌ Some tests failed. Please review the log." |
| 82 | + COLOR="🔴" |
| 83 | + HEADER="Maatify CI Alert" |
| 84 | + fi |
| 85 | + |
| 86 | + PROJECT="maatify/bootstrap" |
| 87 | + BRANCH="$GITHUB_REF_NAME" |
| 88 | + ACTOR="$GITHUB_ACTOR" |
| 89 | + URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" |
| 90 | + |
| 91 | + MESSAGE="📢 <b>${HEADER}</b> |
| 92 | + |
| 93 | + ${COLOR} ${STATUS} |
| 94 | + |
| 95 | + 📦 <b>Project:</b> ${PROJECT} |
| 96 | + 🧱 <b>Branch:</b> ${BRANCH} |
| 97 | + 👷♂️ <b>Committer:</b> ${ACTOR} |
| 98 | + |
| 99 | + ⏱ <b>Start:</b> ${START_TIME} |
| 100 | + 🕒 <b>End:</b> ${END_TIME} |
| 101 | + 📈 <b>Duration:</b> ${DURATION_STR} |
| 102 | + |
| 103 | + 🔗 <a href='${URL}'>View Run Log</a>" |
| 104 | + |
| 105 | + PAYLOAD=$(jq -n \ |
| 106 | + --arg chat_id "$TELEGRAM_CHAT_ID" \ |
| 107 | + --arg text "$MESSAGE" \ |
| 108 | + --arg parse_mode "HTML" \ |
| 109 | + '{chat_id: $chat_id, text: $text, parse_mode: $parse_mode}') |
| 110 | + |
| 111 | + RESPONSE=$(curl -s -o /tmp/tg_resp.json -w "%{http_code}" \ |
| 112 | + -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ |
| 113 | + -H "Content-Type: application/json" \ |
| 114 | + -d "$PAYLOAD") |
| 115 | + |
| 116 | + echo "Raw Telegram Response (HTTP $RESPONSE):" |
| 117 | + cat /tmp/tg_resp.json |
| 118 | + |
| 119 | + if [ "$RESPONSE" -ne 200 ]; then |
| 120 | + echo "⚠️ Telegram notification failed (HTTP $RESPONSE)" >> $GITHUB_STEP_SUMMARY |
| 121 | + cat /tmp/tg_resp.json >> $GITHUB_STEP_SUMMARY |
| 122 | + else |
| 123 | + echo "✅ Telegram notification sent successfully." >> $GITHUB_STEP_SUMMARY |
| 124 | + fi |
| 125 | +
|
0 commit comments