Skip to content

Discord Notification Workflow โ€‹

Status: โœ… Production
Workflow File: .github/workflows/discord-notify.yml
Type: Push notification automation
Triggers: Commits to main, dev, and all branches (for testing)


Overview โ€‹

The Discord Notification workflow automatically sends commit notifications to a Discord channel whenever code is pushed to the repository. This keeps the team informed of code changes in real-time without requiring manual updates.

Key Features:

  • Multi-commit support: Shows all commits when multiple are pushed at once
  • Commit count in title (e.g., "3 commits")
  • Shows commit message, author, and shortened SHA for each commit
  • Direct links to each commit on GitHub
  • Color-coded by branch:
    • Blue (#5865F2) for main branch
    • Green (#57F287) for dev branch
  • Timestamp of push
  • Commits separated by horizontal rules for clarity
  • Notification history tracking to avoid duplicate messages

Quick Setup โ€‹

1. Create Discord Webhook โ€‹

  1. Open Discord Server Settings โ†’ Integrations โ†’ Webhooks
  2. Click "New Webhook"
  3. Name: GitHub Notifications
  4. Select channel where notifications should appear (e.g., #dev-updates)
  5. Copy the webhook URL

2. Add GitHub Secrets โ€‹

  1. Go to GitHub repository secrets
  2. Click "New repository secret"
  3. Name: DISCORD_WEBHOOK_COMMITS
  4. Value: Paste the production commit-notification webhook URL (used on dev/main)
  5. (Optional) Add DISCORD_WEBHOOK_TEST for feature branches if you want non-prod pushes in a separate channel
  6. Click "Add secret"

3. Test โ€‹

Push a commit to dev or main branch:

bash
git commit -m "Test Discord notification"
git push origin dev

Then check:


Notification Behavior โ€‹

When Notifications Fire โ€‹

  • Any push to main branch
  • Any push to dev branch
  • Any push to any other branch (useful for testing or feature branch tracking)

What Gets Notified โ€‹

Per Commit:

  • Commit message
  • Author name
  • Shortened commit SHA (7 characters)
  • Link to commit on GitHub

Per Push:

  • Total commit count
  • Branch name
  • Timestamp

Avoiding Duplicates โ€‹

The workflow maintains a notification history in git to prevent sending the same commit notification twice. This is stored in .github-workflow-state/notified-commits.txt and persists across workflow runs.


Troubleshooting โ€‹

Notifications Not Appearing โ€‹

Check:

  1. Secret exists: Verify DISCORD_WEBHOOK_COMMITS (and DISCORD_WEBHOOK_TEST if used) are set in GitHub secrets
  2. Webhook URL valid: Test by sending a test message via Discord webhook
  3. Permissions: Ensure bot/webhook has permission to post in the target channel
  4. Branches: Ensure you're pushing to main or dev (or another branch if configured)

Duplicate Notifications โ€‹

  1. The workflow includes deduplication logicโ€”duplicates should not occur
  2. If duplicates happen, check .github-workflow-state/notified-commits.txt in git history
  3. May need to reset notification history by removing that file from git

Wrong Channel โ€‹

  1. Verify the webhook URL points to the correct Discord channel
  2. Update the webhook URL in GitHub secrets if the channel changed

Configuration โ€‹

Environment Variables (in Workflow) โ€‹

No environment variablesโ€”all configuration is via:

  • DISCORD_WEBHOOK_COMMITS secret (required for dev/main)
  • DISCORD_WEBHOOK_TEST secret (optional for non-prod branches)
  • Workflow trigger branches (currently main, dev, **)

Customization โ€‹

To change notification content or formatting:

To add more branches:

  • Edit the on.push.branches section in .github/workflows/discord-notify.yml


Testing Locally โ€‹

There is no local testing needed for this workflowโ€”it only runs on GitHub Actions when code is pushed.

To test the webhook URL:

bash
curl -X POST "YOUR_WEBHOOK_URL" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Test message",
    "embeds": [{
      "title": "Test Commit",
      "description": "This is a test notification"
    }]
  }'

Maintenance โ€‹

Regular Checks โ€‹

  • Monthly: Verify webhook URL is still valid and bot still has permissions
  • On channel changes: Update webhook URL in GitHub secrets

Updating the Workflow โ€‹

If modifying the workflow, test on a non-production branch first:

bash
git checkout -b test/discord-workflow
# Make changes to .github/workflows/discord-notify.yml
git push origin test/discord-workflow
# Verify notifications work
# Then merge to dev and main

.github/workflows/
  โ”œโ”€โ”€ discord-notify.yml           # Workflow definition
.github/workflow-state/
  โ””โ”€โ”€ notified-commits.txt         # Notification history (auto-managed)
docs/engineering/github/workflows/
  โ”œโ”€โ”€ DISCORD_NOTIFICATION.md      # This file
  โ”œโ”€โ”€ discord/
  โ”‚   โ””โ”€โ”€ IMPLEMENTATION_SUMMARY.md # Quick reference
  โ””โ”€โ”€ testing/
      โ””โ”€โ”€ (See testing docs for workflow validation)

Built with VitePress