mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 04:19:49 +00:00
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:
@@ -153,3 +153,17 @@ jobs:
|
|||||||
git add VERSION package.json
|
git add VERSION package.json
|
||||||
git commit -m "chore(release): ${{ steps.bump.outputs.new }} [skip ci]"
|
git commit -m "chore(release): ${{ steps.bump.outputs.new }} [skip ci]"
|
||||||
git push origin dev
|
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\"}}]}"
|
||||||
|
|||||||
@@ -52,3 +52,42 @@ jobs:
|
|||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
run: bunx semantic-release
|
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' }
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user