ci: add discord workflows (#440)

Drew Smirnoff created

Change summary

.github/workflows/discord-monitor.yml | 73 +++++++++++++++++++++++++++++
.github/workflows/discord-notify.yml  | 26 ++++++++++
2 files changed, 99 insertions(+)

Detailed changes

.github/workflows/discord-monitor.yml 🔗

@@ -0,0 +1,73 @@
+name: Flotpane Activity Monitor
+
+on:
+  push:
+  issues:
+    types: [opened, edited, deleted, closed, reopened]
+  pull_request:
+    types: [opened, edited, closed, reopened]
+  issue_comment:
+    types: [created, deleted]
+  fork:
+  watch:
+    types: [started] # This triggers when someone stars the repo
+  discussion:
+    types: [created, answered]
+
+jobs:
+  discord-audit-log:
+    name: Send Discord Audit Log
+    runs-on: ubuntu-latest
+    steps:
+      - name: Parse Event and Send Webhook
+        env:
+          DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL_AUDIT_LOG }}
+        run: |
+          EVENT_NAME="${{ github.event_name }}"
+          ACTOR="${{ github.actor }}"
+          REPO="${{ github.repository }}"
+          ACTION="${{ github.event.action }}"
+
+          # Default fallback URL
+          URL="https://github.com/$REPO"
+
+          # Customize Title and URL based on the specific event
+          if [ "$EVENT_NAME" == "issues" ]; then
+            TITLE="🐛 Issue $ACTION in $REPO"
+            URL="${{ github.event.issue.html_url }}"
+          elif [ "$EVENT_NAME" == "pull_request" ]; then
+            TITLE="🔄 Pull Request $ACTION in $REPO"
+            URL="${{ github.event.pull_request.html_url }}"
+          elif [ "$EVENT_NAME" == "push" ]; then
+            TITLE="⬆️ Code Pushed to $REPO"
+            URL="${{ github.event.compare }}" # Links to the commit comparison
+          elif [ "$EVENT_NAME" == "issue_comment" ]; then
+            TITLE="💬 Comment $ACTION on an Issue/PR"
+            URL="${{ github.event.comment.html_url }}"
+          elif [ "$EVENT_NAME" == "watch" ]; then
+            TITLE="⭐ Repo Starred!"
+          elif [ "$EVENT_NAME" == "fork" ]; then
+            TITLE="🍴 Repo Forked!"
+          elif [ "$EVENT_NAME" == "discussion" ]; then
+            TITLE="🗣️ Discussion $ACTION"
+            URL="${{ github.event.discussion.html_url }}"
+          else
+            TITLE="🔔 Activity ($EVENT_NAME) in $REPO"
+          fi
+
+          # Use jq to safely build the JSON payload (prevents special characters from breaking the script)
+          # Color is set to 0 (Pitch Black) to match the Flotpane branding
+          jq -n \
+            --arg title "$TITLE" \
+            --arg url "$URL" \
+            --arg desc "**User:** \`$ACTOR\` triggered \`$EVENT_NAME\`.\n\n[**View this activity on GitHub**]($url)" \
+            '{
+              username: "Flotpane Monitor",
+              avatar_url: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
+              embeds: [{
+                title: $title,
+                url: $url,
+                description: $desc,
+                color: 0
+              }]
+            }' | curl -H "Content-Type: application/json" -d @- $DISCORD_WEBHOOK_URL

.github/workflows/discord-notify.yml 🔗

@@ -0,0 +1,26 @@
+name: Discord Release Notification
+
+on:
+  release:
+    types: [published]
+
+jobs:
+  notify-discord:
+    name: Notify Discord Channel
+    runs-on: ubuntu-latest
+    if: github.event.release.tag_name != 'nightlyv0'
+
+    steps:
+      - name: Send Discord Message
+        env:
+          # Pulls the secure webhook URL from your repository secrets
+          DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
+        run: |
+          curl -H "Content-Type: application/json" \
+          -X POST \
+          -d '{
+            "username": "GitHub Releases",
+            "avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
+            "content": "🚀 **A new Matcha release has been published!**\n\n**Release:** ${{ github.event.release.name }}\n\nCheck it out here: ${{ github.event.release.html_url }}"
+          }' \
+          $DISCORD_WEBHOOK_URL