feat(ci): add Discord notifications for releases

- stable releases: fetch GH release, post green embed with changelog

- dev releases: post orange embed with version info

- graceful skip if webhook not configured
This commit is contained in:
kaitranntt
2025-12-19 00:26:22 -05:00
parent 2db8f3bf1a
commit ee76d663ae
2 changed files with 53 additions and 0 deletions
+14
View File
@@ -153,3 +153,17 @@ jobs:
git add VERSION package.json
git commit -m "chore(release): ${{ steps.bump.outputs.new }} [skip ci]"
git push origin dev
- name: Notify Discord
if: success()
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
VERSION: ${{ steps.bump.outputs.new }}
run: |
if [ -z "$DISCORD_WEBHOOK_URL" ]; then
echo "DISCORD_WEBHOOK_URL not set, skipping notification"
exit 0
fi
curl -s -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "{\"username\":\"CCS Dev Release\",\"embeds\":[{\"title\":\"Dev Release $VERSION\",\"url\":\"https://www.npmjs.com/package/@kaitranntt/ccs/v/$VERSION\",\"color\":15638323,\"description\":\"Pre-release version available for testing.\",\"footer\":{\"text\":\"npm i @kaitranntt/ccs@dev\"}}]}"
+39
View File
@@ -52,3 +52,42 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: bunx semantic-release
- name: Notify Discord
if: success()
uses: actions/github-script@v7
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (!process.env.DISCORD_WEBHOOK_URL) {
core.warning('DISCORD_WEBHOOK_URL not set, skipping notification')
return
}
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 1
})
if (!releases.length) {
core.warning('No releases found, skipping notification')
return
}
const r = releases[0]
const desc = (r.body || 'No changelog available').slice(0, 2000)
await fetch(process.env.DISCORD_WEBHOOK_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username: 'CCS Release',
embeds: [{
title: `Release ${r.name || r.tag_name}`,
url: r.html_url,
color: 0x10B981,
description: desc,
timestamp: r.created_at,
footer: { text: 'npm i @kaitranntt/ccs@latest' }
}]
})
})