update(MicMute): update hash for main (#282) #87
This file contains hidden or 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
| name: Notify Discord about plugin update | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'Plugins.json' | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Extract Hash Diff | |
| id: diff | |
| shell: python | |
| run: | | |
| import json | |
| import os | |
| import subprocess | |
| # Get historical versions of Plugins.json | |
| try: | |
| old_content = subprocess.check_output( | |
| ["git", "show", "HEAD~1:Plugins.json"], | |
| stderr=subprocess.DEVNULL | |
| ).decode("utf-8") | |
| old_data = json.loads(old_content) | |
| except (subprocess.CalledProcessError, json.JSONDecodeError) as e: | |
| print(f"Could not read or parse HEAD~1:Plugins.json ({e}) — skipping update notification.") | |
| old_data = None | |
| if old_data is not None: | |
| try: | |
| new_content = subprocess.check_output( | |
| ["git", "show", "HEAD:Plugins.json"], | |
| stderr=subprocess.DEVNULL | |
| ).decode("utf-8") | |
| new_data = json.loads(new_content) | |
| except (subprocess.CalledProcessError, json.JSONDecodeError) as e: | |
| print(f"Could not read or parse HEAD:Plugins.json ({e}) — skipping update notification.") | |
| new_data = None | |
| if new_data is not None: | |
| old_dict = {item['url']: item['hash'] for item in old_data if isinstance(item, dict) and 'url' in item and 'hash' in item} | |
| new_dict = {item['url']: item['hash'] for item in new_data if isinstance(item, dict) and 'url' in item and 'hash' in item} | |
| for url, new_sha in new_dict.items(): | |
| old_sha = old_dict.get(url) | |
| if not old_sha or not new_sha: | |
| continue | |
| # Trigger if the commit hash changed | |
| if old_sha != new_sha: | |
| plugin_name = url.split('/')[-1] | |
| changelog_url = f"{url}/compare/{old_sha}...{new_sha}" | |
| # Creates a clean display string like: "a459c67...bd2cfc3" | |
| display_text = f"{old_sha[:7]}...{new_sha[:7]}" | |
| with open(os.environ['GITHUB_OUTPUT'], 'a') as f: | |
| f.write(f"plugin_name={plugin_name}\n") | |
| f.write(f"changelog_url={changelog_url}\n") | |
| f.write(f"display_text={display_text}\n") | |
| break | |
| - name: Send Message via Discord Bot | |
| if: steps.diff.outputs.plugin_name != '' | |
| env: | |
| BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }} | |
| CHANNEL_ID: ${{ secrets.DISCORD_CHANNEL_ID }} | |
| PLUGIN_NAME: ${{ steps.diff.outputs.plugin_name }} | |
| CHANGELOG_URL: ${{ steps.diff.outputs.changelog_url }} | |
| DISPLAY_TEXT: ${{ steps.diff.outputs.display_text }} | |
| run: | | |
| # Formats neatly in Discord markdown with embed-suppressing brackets < > | |
| PAYLOAD=$(jq -n \ | |
| --arg msg "# 🎉 $PLUGIN_NAME updated"$'\n\n'"Changelog: [$DISPLAY_TEXT](<$CHANGELOG_URL>)" \ | |
| '{content: $msg}') | |
| curl -X POST \ | |
| -H "Authorization: Bot $BOT_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$PAYLOAD" \ | |
| "https://discord.com/api/v10/channels/$CHANNEL_ID/messages" |