Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discord notification #122

Merged
merged 11 commits into from
Apr 3, 2024
Merged
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()
Loading