Skip to content

Discord Release Notification #13

Discord Release Notification

Discord Release Notification #13

name: Discord Release Notification
on:
release:
types: [published, created, edited]
workflow_dispatch:
jobs:
notify_discord:
runs-on: ubuntu-latest
steps:
- name: Fetch latest release
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest_release=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/latest")
echo "RELEASE_TAG=$(echo $latest_release | jq -r .tag_name)" >> $GITHUB_ENV
echo "RELEASE_NAME=$(echo $latest_release | jq -r .name)" >> $GITHUB_ENV
echo $latest_release | jq -r .body > release_body.txt
echo "RELEASE_URL=$(echo $latest_release | jq -r .html_url)" >> $GITHUB_ENV
- name: Send Discord notification
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_ANN }}
RELEASE_TAG: ${{ env.RELEASE_TAG }}
RELEASE_URL: ${{ env.RELEASE_URL }}
run: |
sudo apt-get update && sudo apt-get install -y pandoc
RELEASE_BODY=$(pandoc -f markdown -t plain release_body.txt |
sed 's/^#* //g' |
sed 's/`//g' |
sed -E 's/^[0-9]+\.[0-9]+\.[0-9]+ \([0-9]{4}-[0-9]{2}-[0-9]{2}\)//g' |
sed '/^$/N;/^\n$/D' |
sed -E 's/^(Bug Fixes|Features|BREAKING CHANGES)/\n**\1**/g' |
sed -E 's/^([A-Z][a-z]+ [A-Z][a-z]+)/\n**\1**/g')
echo "Sending notification for release: $RELEASE_TAG"
curl -H "Content-Type: application/json" -X POST -d @- $DISCORD_WEBHOOK <<EOF
{
"embeds": [{
"title": "New Release: $RELEASE_TAG",
"description": "$RELEASE_BODY",
"url": "$RELEASE_URL",
"color": 11530902
}]
}
EOF