feat: testing workflows for telegram commits #10
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: ["**"] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| send: | |
| runs-on: ubuntu-latest | |
| environment: SANDBOX # must have TG_BOT_TOKEN and TG_CHAT_ID | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 50 | |
| - name: Build message (MarkdownV2, plain look) | |
| id: msg | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| REPO="${{ github.repository }}" | |
| ACTOR="${{ github.actor }}" | |
| REF_NAME="${{ github.ref_name }}" | |
| RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| REPO_URL="${{ github.server_url }}/${{ github.repository }}" | |
| COMMIT_BASE="${REPO_URL}/commit" | |
| ACTOR_URL="https://github.com/${ACTOR}" | |
| # MarkdownV2 escap er (Telegram): _ * [ ] ( ) ~ ` > # + - = | { } . ! | |
| mde() { | |
| sed -e 's/\\/\\\\/g' \ | |
| -e 's/_/\\_/g' -e 's/*/\\*/g' -e 's/$begin:math:display$/\\\\[/g' -e 's/]/\\$end:math:display$/g' \ | |
| -e 's/(/\$begin:math:text$/g' -e 's/)/\\$end:math:text$/g' -e 's/~/\\~/g' -e 's/`/\\`/g' \ | |
| -e 's/>/\\>/g' -e 's/#/\\#/g' -e 's/\\+/\\\\+/g' \ | |
| -e 's/-/\\-/g' -e 's/=/\\=/g' -e 's/|/\\|/g' -e 's/{/\\{/g' -e 's/}/\\}/g' \ | |
| -e 's/\./\\./g' -e 's/!/\\!/g' | |
| } | |
| # Grab last 10 commits: subject, short, full | |
| mapfile -t LINES < <(git log -n 10 --pretty=format:'%s%x1f%h%x1f%H' || true) | |
| if [[ ${#LINES[@]} -eq 0 ]]; then | |
| COMMITS_TXT="- (no commit messages found)" | |
| else | |
| COMMITS_TXT="" | |
| for row in "${LINES[@]}"; do | |
| IFS=$'\x1f' read -r subj short full <<<"$row" | |
| subj_esc="$(printf '%s' "$subj" | mde)" | |
| # Keep raw URLs (no MDV2 link) to match your “plain” style | |
| COMMITS_TXT+="- ${subj_esc} (${short}) by ${ACTOR_URL}\n" | |
| done | |
| fi | |
| HEADER="📣 Last 10 commits\n" | |
| META="Repo: ${REPO}\nBy: ${ACTOR}\nRef: ${REF_NAME}\nRun: ${RUN_URL}\n\n" | |
| FOOTER="\nRepo: ${REPO_URL}" | |
| MESSAGE="${HEADER}${META}${COMMITS_TXT}${FOOTER}" | |
| MESSAGE="$(printf '%s' "$MESSAGE" | tr -d '\r')" # normalize newlines | |
| { | |
| printf 'text<<MSGEOF\n' | |
| printf '%s\n' "$MESSAGE" | |
| printf 'MSGEOF\n' | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Send to Telegram (MarkdownV2) | |
| 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; } | |
| 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, parse_mode:"MarkdownV2", disable_web_page_preview:true}')" | |
| echo "✅ Posted last 10 commits to Telegram." |