This file contains 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: Update Generated File and Post to Telegram | |
on: | |
push: | |
branch: main | |
release: | |
types: [published] # Trigger only when a release is published | |
jobs: | |
post-and-pin: | |
runs-on: ubuntu-latest | |
env: | |
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }} | |
CHAT_ID: ${{ secrets.CHAT_ID }} | |
LAST_PINNED_MESSAGE: ${{ vars.LAST_PINNED_MESSAGE }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Send Telegram message with new files and get message ID | |
id: send_telegram_message # ID to reference this step's output | |
run: | | |
RESPONSE=$(curl -s -X POST "https://api.telegram.org/bot$TG_BOT_TOKEN/sendMediaGroup" \ | |
-F "chat_id=$CHAT_ID" \ | |
-F 'media=[{ "type": "document", "media": "attach://ios"}, {"type":"document", "media": "attach://android"}, {"type":"document", "media": "attach://macos"}, {"type":"document", "media": "attach://windows", "caption":"Обновлённые инструкции!"}]' \ | |
-F "[email protected]" \ | |
-F "[email protected]" \ | |
-F "[email protected]" \ | |
-F "[email protected]") | |
MESSAGE_ID=$(echo "$RESPONSE" | jq -r '.result[0].message_id') | |
echo "MESSAGE_ID=$MESSAGE_ID" >> $GITHUB_ENV | |
- name: Unpin previous bot message | |
env: | |
LAST_PINNED_MESSAGE: ${{ vars.LAST_PINNED_MESSAGE }} | |
if: steps.send_telegram_message.outcome == 'success' && ${{ vars.LAST_PINNED_MESSAGE }} != 0 | |
run: | | |
curl -s -X POST "https://api.telegram.org/bot$TG_BOT_TOKEN/unpinChatMessage" \ | |
-d "chat_id=$CHAT_ID" \ | |
-d "message_id=$LAST_PINNED_MESSAGE" | |
- name: Pin the sent message | |
if: steps.send_telegram_message.outcome == 'success' | |
env: | |
MESSAGE_ID: ${{ env.MESSAGE_ID }} | |
GH_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
curl -s -X POST "https://api.telegram.org/bot$TG_BOT_TOKEN/pinChatMessage" \ | |
-d "chat_id=$CHAT_ID" \ | |
-d "message_id=$MESSAGE_ID" \ | |
-d "disable_notification=true" | |
gh variable set LAST_PINNED_MESSAGE --body "$MESSAGE_ID" |