Merge pull request #204 from StreamController/update-plugin-OBSPlugin… #11
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 | |
| old_content = subprocess.check_output(["git", "show", "HEAD~1:Plugins.json"]).decode("utf-8") | |
| new_content = subprocess.check_output(["git", "show", "HEAD:Plugins.json"]).decode("utf-8") | |
| old_data = json.loads(old_content) | |
| new_data = json.loads(new_content) | |
| old_dict = {item['url']: item['commits'] for item in old_data} | |
| new_dict = {item['url']: item['commits'] for item in new_data} | |
| found = False | |
| for url, new_commits in new_dict.items(): | |
| if url in old_dict: | |
| old_commits = old_dict[url] | |
| # Get the single version key and its new SHA | |
| for version, new_sha in new_commits.items(): | |
| # Fallback to absolute positional value if the app version key itself was updated | |
| old_sha = old_commits.get(version) or list(old_commits.values())[0] | |
| # 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") | |
| found = True | |
| break | |
| if found: | |
| 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" |