Update tg_notify.yml

This commit is contained in:
grol 2025-05-12 12:06:46 +03:00 committed by GitHub
parent 9c26ad2c27
commit 76677067fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,38 +11,26 @@ on:
types: [submitted] types: [submitted]
jobs: jobs:
notify: build:
name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Create message file and detect length - name: Prepare Telegram message
id: prepare id: prepare_message
run: | run: |
TITLE="${{ github.event.issue.title || github.event.pull_request.title || 'Комментарий' }}" FULL_MESSAGE="Repository: ${{ github.repository }}\nType: ${{ github.event_name }}\nAction: ${{ github.event.action }}\nTitle: ${{ github.event.issue.title || github.event.pull_request.title || 'Комментарий' }}\n${{ github.event.comment.body || '' }}\nSee ${{ github.event.issue.html_url || github.event.pull_request.html_url || github.event.comment.html_url || github.event.review.html_url }}"
COMMENT="${{ github.event.comment.body || '' }}" SHORT_MESSAGE="Repository: ${{ github.repository }}\nUpdate in ${{ github.event_name }} (${{ github.event.action }})\nTitle: ${{ github.event.issue.title || github.event.pull_request.title || 'Комментарий' }}\nSee ${{ github.event.issue.html_url || github.event.pull_request.html_url || github.event.comment.html_url || github.event.review.html_url }}"
MSG="Repository: ${{ github.repository }}
Type: ${{ github.event_name }} # Проверяем длину сообщения (лимит Telegram — 4096 символов)
Action: ${{ github.event.action }} if [ ${#FULL_MESSAGE} -gt 4096 ]; then
Title: ${TITLE} echo "message=$SHORT_MESSAGE" >> $GITHUB_OUTPUT
${COMMENT} else
echo "message=$FULL_MESSAGE" >> $GITHUB_OUTPUT
fi
See: ${{ github.event.issue.html_url || github.event.pull_request.html_url || github.event.comment.html_url || github.event.review.html_url }}" - name: Send Telegram message
echo "$MSG" > message.txt
LENGTH=$(wc -c < message.txt | tr -d ' ')
echo "length=$LENGTH" >> $GITHUB_OUTPUT
- name: Send full message if short
if: steps.prepare.outputs.length < 4096
uses: appleboy/telegram-action@master uses: appleboy/telegram-action@master
with: with:
to: ${{ secrets.TELEGRAM_CHAT_ID }} to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }} token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message_file: message.txt message: ${{ steps.prepare_message.outputs.message }}
- name: Send only link if message too long
if: steps.prepare.outputs.length >= 4096
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: |
See: ${{ github.event.issue.html_url || github.event.pull_request.html_url || github.event.comment.html_url || github.event.review.html_url }}