Workflow file for this run
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: Publish Blog Post to Telegram/Discord | |
on: | |
pull_request: | |
branches: [announcements] | |
types: [closed] | |
paths: | |
- "announcements/*.md" | |
jobs: | |
publish: | |
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 pandoc | |
- 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/Discord | |
env: | |
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} | |
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }} | |
run: | | |
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" | |
# Convert markdown to plain text using pandoc | |
pandoc -f markdown -t plain "$file" -o "$file.txt" | |
content=$(cat "$file.txt") | |
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage" \ | |
-d chat_id="${TELEGRAM_TO}" -d text="$content" -d parse_mode="Markdown" | |
curl -X POST -H "Content-Type: application/json" \ | |
-d "{\"content\": \"${content}\"}" https://discord.com/api/webhooks/1155501986532307056/POOHKkxip-2n4NA3Fe7ye1iPhrKeEwZOHiU2CSWCRt7TYv1uxvriNhZ0mat1JvLKpEsI | |
done |