Skip to content

feat(stats): Implement MongoDB integration for stats tracking, includ… #114

feat(stats): Implement MongoDB integration for stats tracking, includ…

feat(stats): Implement MongoDB integration for stats tracking, includ… #114

Workflow file for this run

name: Discord Notification
on:
push:
branches: [main, dev]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set up jq
run: sudo apt-get install jq
- name: Get commit info
id: commit
run: |
echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "AUTHOR=$(git log -1 --pretty=format:'%an')" >> $GITHUB_OUTPUT
echo "AUTHOR_AVATAR=https://github.com/${{ github.actor }}.png" >> $GITHUB_OUTPUT
echo "MESSAGE<<EOF" >> $GITHUB_OUTPUT
git log -1 --pretty=%B >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "URL=https://github.com/${{ github.repository }}/commit/$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "TIMESTAMP=$(git log -1 --pretty=%cI)" >> $GITHUB_OUTPUT
echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
- name: Set Discord Webhook URL
id: webhook
run: |
if [[ "${GITHUB_REF##*/}" == "main" ]]; then
echo "WEBHOOK=${{ secrets.DISCORD_WEBHOOK }}" >> $GITHUB_OUTPUT
elif [[ "${GITHUB_REF##*/}" == "dev" ]]; then
if [ -n "${{ secrets.DISCORD_DEV_WEBHOOK }}" ]; then
echo "WEBHOOK=${{ secrets.DISCORD_DEV_WEBHOOK }}" >> $GITHUB_OUTPUT
else
echo "WEBHOOK=${{ secrets.DISCORD_WEBHOOK }}" >> $GITHUB_OUTPUT
fi
else
echo "WEBHOOK=" >> $GITHUB_OUTPUT
fi
- name: Send Discord Embed
if: steps.webhook.outputs.WEBHOOK != ''
env:
DISCORD_WEBHOOK: ${{ steps.webhook.outputs.WEBHOOK }}
run: |
MESSAGE=$(echo "${{ steps.commit.outputs.MESSAGE }}" | sed 's/^> /➡️ /g; s/^- /• /g')
BRANCH="${{ github.ref_name }}"
COLOR=5763719
if [[ "$BRANCH" == "dev" ]]; then
COLOR=16753920
fi
PAYLOAD=$(jq -n \
--arg author "${{ steps.commit.outputs.AUTHOR }}" \
--arg author_avatar "${{ steps.commit.outputs.AUTHOR_AVATAR }}" \
--arg message "$MESSAGE" \
--arg url "${{ steps.commit.outputs.URL }}" \
--arg timestamp "${{ steps.commit.outputs.TIMESTAMP }}" \
--arg sha "${{ steps.commit.outputs.SHA }}" \
--arg branch "$BRANCH" \
--argjson color "$COLOR" \
'{
"embeds": [{
"title": ("🚀 New Update Released! (" + $branch + ")"),
"description": ("**Commit:** [`" + $sha[0:7] + "`](" + $url + ")\n\n" + $message),
"color": $color,
"footer": {
"text": ("Pushed by " + $author),
"icon_url": $author_avatar
},
"timestamp": $timestamp
}]
}')
curl -X POST -H "Content-Type: application/json" -d "$PAYLOAD" "$DISCORD_WEBHOOK"