Add notification for MiSTer Discord on release

This commit is contained in:
Dale Whinham
2021-02-03 04:13:04 +00:00
parent f4740f42c5
commit 3882c8702c
4 changed files with 72 additions and 1 deletions

65
.github/scripts/discord_notify.py vendored Executable file
View File

@@ -0,0 +1,65 @@
#!/usr/bin/env python3
from discord_webhook import DiscordWebhook, DiscordEmbed
from sys import argv
import json
import keepachangelog
GITHUB_USER = "dwhinham"
GITHUB_REPO = "mt32-pi"
RAW_URL = "https://raw.githubusercontent.com/{}/{}/master".format(
GITHUB_USER, GITHUB_REPO
)
AVATAR_URL = "{}/images/mt32pi_logo_discord_avatar.png".format(RAW_URL)
THUMBNAIL_URL = "{}/images/mt32pi_logo_dark.png".format(RAW_URL)
MAX_FIELD_LEN = 1024
COLOR = 0xEB2188
def add_field(embed, changes, field_title, section_name):
if section_name in changes:
value = "\n".join(["{}".format(change) for change in changes[section_name]])
if len(value) > MAX_FIELD_LEN:
value = value[: MAX_FIELD_LEN - 3] + "..."
embed.add_embed_field(name=field_title, value=value, inline=False)
if len(argv) < 3:
print("Usage: {} [webhook url] [version]".format(argv[0]))
exit(1)
webhook_url = argv[1]
version = argv[2]
changelog = keepachangelog.to_dict("./CHANGELOG.md")
if version not in changelog:
print("Version {} not in changelog!".format(version))
exit(1)
changes = changelog[version]
title = "🎹🎶 **{} v{} - {}**".format(
GITHUB_REPO, changes["version"], changes["release_date"]
)
release_url ="https://github.com/{}/{}/releases/tag/v{}".format(GITHUB_USER, GITHUB_REPO, version)
webhook = DiscordWebhook(url=webhook_url, username=GITHUB_REPO, avatar_url=AVATAR_URL)
embed = DiscordEmbed(title=title, url=release_url, color=COLOR)
embed.set_author(
name=GITHUB_USER,
url="https://github.com/{}".format(GITHUB_USER),
icon_url="https://github.com/{}.png".format(GITHUB_USER),
)
embed.set_thumbnail(url=THUMBNAIL_URL)
add_field(embed, changes, "✨ Added:", "added")
add_field(embed, changes, "✏ Changed:", "changed")
add_field(embed, changes, "🐛 Fixed:", "fixed")
webhook.add_embed(embed)
response = webhook.execute()

View File

@@ -150,7 +150,7 @@ jobs:
- name: Get version (git tag)
if: startsWith(github.ref, 'refs/tags/')
id: get_version
run: echo ::set-output name=version::${GITHUB_REF#refs/tags/}
run: echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
- name: Create release package
if: startsWith(github.ref, 'refs/tags/')
@@ -169,3 +169,9 @@ jobs:
with:
args: |
mt32-pi-*.zip
- name: Notify Discord of release
if: startsWith(github.ref, 'refs/tags/')
run: |
sudo pip3 install keepachangelog discord-webhook
.github/scripts/discord_notify.py ${{ secrets.DISCORD_WEBHOOK }} ${{ steps.get_version.outputs.version }}

BIN
images/mt32pi_logo_dark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB