Skip to content

feat: testing workflows for telegram commits #15

feat: testing workflows for telegram commits

feat: testing workflows for telegram commits #15

name: Telegram – Last 10 Commits (Clean Text)
on:
push:
branches: ["**"]
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 # enough for recent history
- name: Build message (clean text)
id: msg
shell: bash
env:
REPO: ${{ github.repository }}
ACTOR: ${{ github.actor }}
REF_NAME: ${{ github.ref_name }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
run: |
set -euo pipefail
ACTOR_URL="https://github.com/${ACTOR}"
# Get last 10 commits: subject, short hash, author name
mapfile -t LINES < <(git log -n 10 --pretty=format:'%s%x1f%h%x1f%an' || true)
if [[ ${#LINES[@]} -eq 0 ]]; then
COMMITS="- (no commit messages found)"
else
COMMITS=""
for row in "${LINES[@]}"; do
IFS=$'\x1f' read -r subj short author <<<"$row"
COMMITS+="- ${subj} (${short}) by ${author}"$'\n'
done
COMMITS="${COMMITS%$'\n'}"
fi
MSG=$'📣 *Repository Update*\n'
MSG+="Repo: ${REPO}\n"
MSG+="Branch: ${REF_NAME}\n"
MSG+="Pushed by: ${ACTOR_URL}\n"
MSG+=$'\n'
MSG+="Last 10 commits:\n"
MSG+="${COMMITS}\n"
MSG+=$'\n'
MSG+="🔗 Repo link: ${REPO_URL}"
{
printf 'text<<MSGEOF\n%s\nMSGEOF\n' "$MSG"
} >> "$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; }
RESP="$(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}')")"
echo "Telegram response: $RESP"
echo "$RESP" | jq -e '.ok == true' >/dev/null
echo "✅ Posted last 10 commits to Telegram."