github: add Discord webhook notification for main branch commits
Creates a GitHub Actions workflow that sends Discord notifications when
commits are pushed to the main branch. The implementation prioritizes
clean separation between workflow orchestration and notification logic.
Architecture:
- .github/workflows/discord-notify.yml: Minimal workflow with single
Python script execution
- .github/scripts/discord_notify.py: Self-contained script handling all
commit extraction, JSON generation, and webhook delivery
Features:
- Triggers only on pushes to main branch
- Extracts commit information using git subprocess calls
- Generates Discord embed with commit message, author, SHA, and link
- Safe JSON serialization handles quotes, newlines, and special characters
- Robust environment validation (requires CI=1 and GITHUB_SHA)
- Proper HTTP error handling with status code checking
The webhook sends rich embeds to Discord with commit details including
clickable commit links and properly formatted timestamps. All shell
scripting is avoided in the YAML file - the workflow simply executes
the Python script which handles everything else.
Webhook URL points to the provided Discord channel endpoint.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s82b63953ab6ceccbk
diff --git a/.github/workflows/discord-notify.yml b/.github/workflows/discord-notify.yml
new file mode 100644
index 0000000..b0258be
--- /dev/null
+++ b/.github/workflows/discord-notify.yml
@@ -0,0 +1,20 @@
+name: Discord Notification
+on:
+ push:
+ branches:
+ - main
+
+permissions: read-all
+
+jobs:
+ notify-discord:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 2
+
+ - name: Send Discord notification
+ env:
+ DISCORD_WEBHOOK_FOR_COMMITS: ${{ secrets.DISCORD_WEBHOOK_FOR_COMMITS }}
+ run: python3 .github/scripts/discord_notify.py