1+ name : Notify Discord about plugin update
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths :
8+ - ' Plugins.json'
9+
10+ jobs :
11+ notify :
12+ runs-on : ubuntu-latest
13+ steps :
14+ - name : Checkout Code
15+ uses : actions/checkout@v4
16+ with :
17+ fetch-depth : 2
18+
19+ - name : Extract Hash Diff
20+ id : diff
21+ shell : python
22+ run : |
23+ import json
24+ import os
25+ import subprocess
26+
27+ # Get historical versions of Plugins.json
28+ old_content = subprocess.check_output(["git", "show", "HEAD~1:Plugins.json"]).decode("utf-8")
29+ new_content = subprocess.check_output(["git", "show", "HEAD:Plugins.json"]).decode("utf-8")
30+
31+ old_data = json.loads(old_content)
32+ new_data = json.loads(new_content)
33+
34+ # Turn lists into dicts keyed by repository URL
35+ old_dict = {item['url']: item['commits'] for item in old_data}
36+ new_dict = {item['url']: item['commits'] for item in new_data}
37+
38+ found = False
39+ for url, new_commits in new_dict.items():
40+ old_commits = old_dict.get(url, {})
41+
42+ for version, new_sha in new_commits.items():
43+ old_sha = old_commits.get(version)
44+
45+ # Check if the commit hash for this version changed
46+ if old_sha != new_sha:
47+ plugin_name = url.split('/')[-1]
48+
49+ # Build comparison link (or a fallback direct commit link if it's a new version)
50+ if old_sha:
51+ changelog_url = f"{url}/compare/{old_sha}...{new_sha}"
52+ else:
53+ changelog_url = f"{url}/commit/{new_sha}"
54+
55+ with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
56+ f.write(f"plugin_name={plugin_name}\n")
57+ f.write(f"changelog_url={changelog_url}\n")
58+ found = True
59+ break
60+ if found:
61+ break
62+
63+ - name : Send Message via Discord Bot
64+ if : steps.diff.outputs.plugin_name != ''
65+ env :
66+ BOT_TOKEN : ${{ secrets.DISCORD_BOT_TOKEN }}
67+ CHANNEL_ID : ${{ secrets.DISCORD_CHANNEL_ID }}
68+ PLUGIN_NAME : ${{ steps.diff.outputs.plugin_name }}
69+ CHANGELOG_URL : ${{ steps.diff.outputs.changelog_url }}
70+ run : |
71+ # Build a clean Markdown payload safe from string-breaking characters
72+ PAYLOAD=$(jq -n \
73+ --arg msg "# 🎉 $PLUGIN_NAME updated"$'\n\n'"Changelog: $CHANGELOG_URL" \
74+ '{content: $msg}')
75+
76+ # Send payload directly to the Discord API using Bot authentication
77+ curl -X POST \
78+ -H "Authorization: Bot $BOT_TOKEN" \
79+ -H "Content-Type: application/json" \
80+ -d "$PAYLOAD" \
81+ "https://discord.com/api/v10/channels/$CHANNEL_ID/messages"
0 commit comments