diff --git a/.github/workflows/discord_notify.yml b/.github/workflows/discord_notify.yml index 79180c3..d225bc8 100644 --- a/.github/workflows/discord_notify.yml +++ b/.github/workflows/discord_notify.yml @@ -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 diff --git a/discord_webhook.py b/discord_webhook.py new file mode 100644 index 0000000..8f26bcb --- /dev/null +++ b/discord_webhook.py @@ -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()