feat: fixed #87
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Telegram – Last 10 Commits (Clean Text) | |
| on: | |
| push: | |
| branches: ["**"] | |
| permissions: | |
| contents: read | |
| jobs: | |
| send: | |
| if: github.repository == 'Someshdiwan/JavaEvolution-Learning-Growing-Mastering' | |
| runs-on: ubuntu-latest | |
| environment: SANDBOX | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 50 # enough for recent history | |
| - name: Build message (plain text, IST timestamps) | |
| id: msg | |
| shell: bash | |
| env: | |
| REPO: ${{ github.repository }} | |
| ACTOR: ${{ github.actor }} | |
| REF_NAME: ${{ github.ref_name }} | |
| REPO_URL: ${{ github.server_url }}/${{ github.repository }} | |
| SITE_URL: https://someshdiwan.github.io/JavaEvolution-Learning-Growing-Mastering/ | |
| run: | | |
| set -euo pipefail | |
| # Pull last 10 commits with subject | short hash | IST datetime | |
| # Use Git's format-local and force runner TZ to Asia/Kolkata | |
| mapfile -t LINES < <( | |
| TZ=Asia/Kolkata \ | |
| git log -n 10 \ | |
| --date=format-local:'%d %b %Y, %H:%M IST' \ | |
| --pretty=format:'%s%x1f%h%x1f%ad' || true | |
| ) | |
| if [[ ${#LINES[@]} -eq 0 ]]; then | |
| COMMITS="- (no commit messages found)" | |
| else | |
| COMMITS="" | |
| for row in "${LINES[@]}"; do | |
| IFS=$'\x1f' read -r subj short when <<<"$row" | |
| # bullet + blank line after each item | |
| COMMITS+="- ${subj} (${short}) — ${when}"$'\n\n' | |
| done | |
| # trim final blank line | |
| COMMITS="${COMMITS%$'\n\n'}" | |
| fi | |
| { | |
| printf 'text<<MSGEOF\n' | |
| printf '📣 Last 10 commits\n' | |
| printf 'Site: %s\n' "$SITE_URL" | |
| printf 'Repo: %s\n' "$REPO" | |
| printf 'Branch: %s\n' "$REF_NAME" | |
| printf 'By: %s\n' "$ACTOR" | |
| printf '\n' | |
| printf '%s\n' "$COMMITS" | |
| printf '\n' | |
| printf '🔗 Repo: %s\n' "$REPO_URL" | |
| printf 'MSGEOF\n' | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Send to Telegram (plain text) | |
| shell: bash | |
| env: | |
| TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} | |
| TG_CHAT_ID: ${{ secrets.TG_CHAT_ID }} | |
| TEXT: ${{ steps.msg.outputs.text }} | |
| run: | | |
| set -euo pipefail | |
| [[ -n "${TG_BOT_TOKEN:-}" && -n "${TG_CHAT_ID:-}" ]] || { echo "Missing TG secrets"; exit 1; } | |
| # Plain text: keeps your newlines and spacing as-is | |
| curl -sS -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage" \ | |
| -H 'Content-Type: application/json' \ | |
| -d "$(jq -n \ | |
| --arg chat_id "$TG_CHAT_ID" \ | |
| --arg text "$TEXT" \ | |
| '{chat_id:$chat_id, text:$text, disable_web_page_preview:true}')" \ | |
| | jq -e '.ok == true' >/dev/null | |
| echo "✅ Posted last 10 commits to Telegram." |