-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
343542b
commit 927199c
Showing
2 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
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
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 |
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
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() |