Skip to content

Workflow file for this run

name: Publish Blog Post to Telegram
on:
pull_request:
branches: [announcements]
types: [closed]
paths:
- "announcements/*.md"
jobs:
publish_to_telegram:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Identify Markdown Files
id: files
run: |
base_sha=${{ github.event.pull_request.base.sha }}
head_sha=${{ github.event.pull_request.head.sha }}
git fetch origin $base_sha
git fetch origin $head_sha
files=$(git diff --name-only --diff-filter=A "$base_sha" "$head_sha" -- 'announcements/*.md')
files_comma_separated=$(echo "$files" | tr '\n' ',')
echo "Changed Markdown Files: $files_comma_separated"
echo "::set-output name=markdown_files::$files_comma_separated"
- name: Publish to Telegram
env:
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
run: |
echo "Publishing to Telegram..."
IFS=',' read -ra files_arr <<< "${{ steps.files.outputs.markdown_files }}"
for file in "${files_arr[@]}"; do
# Skip empty strings which may occur if there's a trailing comma
[ -z "$file" ] && continue
echo "Processing file: $file"
content=$(cat "$file")
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage" \
-d chat_id="${TELEGRAM_TO}" -d text="$content" -d parse_mode="MarkdownV2"
curl -X POST -H "Content-Type: application/json" \
-d '{"content": "$content"}' https://discord.com/api/webhooks/1155501986532307056/POOHKkxip-2n4NA3Fe7ye1iPhrKeEwZOHiU2CSWCRt7TYv1uxvriNhZ0mat1JvLKpEsI
done