Skip to content

Commit

Permalink
discord notification (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
afreakyelf authored Apr 3, 2024
1 parent 343542b commit 927199c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
29 changes: 19 additions & 10 deletions .github/workflows/discord_notify.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
name: Discord Release Notification
name: Notify Discord on Release

on:
release:
types: [created]
types: [created, edited]

jobs:
discord_notification:
runs-on: ubuntu-latest
steps:
- name: Checkout code
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Send message to Discord
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
- name: Install dependencies
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{"content": "Hey everyone! 🎉\n\n**New Release 🚀 Version: ${{ github.event.release.tag_name }}**\n\n**What\'s Changed:**\n* ${{github.event.release.body}}\n\n**Full Changelog:** [View Changes](${{ github.event.release.html_url }})"}' \
$DISCORD_WEBHOOK
python -m pip install --upgrade pip
pip install requests
- name: Send notification to Discord
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_BODY: ${{ github.event.release.body }}
RELEASE_URL: ${{ github.event.release.html_url }}
run: python discord_webhook.py
26 changes: 26 additions & 0 deletions discord_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# discord_webhook.py

import json
import os
import requests

def main():
webhook_url = os.getenv('DISCORD_WEBHOOK_URL')
release_tag = os.getenv('RELEASE_TAG')
release_body = os.getenv('RELEASE_BODY')
release_url = os.getenv('RELEASE_URL')

# Construct the message content with Markdown
content = f"Hello @everyone, new release **{release_tag}** is out 🚀 \n{release_body} \n[View Release]({release_url})"

# Prepare the webhook payload
payload = {
"content": content
}

# Send the webhook
response = requests.post(webhook_url, json=payload)
response.raise_for_status() # This will raise an error if the request fails

if __name__ == "__main__":
main()

0 comments on commit 927199c

Please sign in to comment.