ci: fix Discord release notification step
This commit is contained in:
@@ -447,10 +447,58 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Send release to Discord
|
||||
uses: SethCohen/github-releases-to-discord@v1
|
||||
with:
|
||||
webhook_url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
color: "2105893"
|
||||
username: "OpenChamber Releases"
|
||||
footer_title: "OpenChamber Changelog"
|
||||
reduce_headings: true
|
||||
if: ${{ secrets.DISCORD_WEBHOOK_URL != '' }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
VERSION: ${{ needs.create-release.outputs.version }}
|
||||
REPOSITORY: ${{ github.repository }}
|
||||
run: |
|
||||
node - <<'NODE'
|
||||
(async () => {
|
||||
const tag = `v${process.env.VERSION}`;
|
||||
const repo = process.env.REPOSITORY;
|
||||
|
||||
const releaseRes = await fetch(`https://api.github.com/repos/${repo}/releases/tags/${tag}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
|
||||
Accept: 'application/vnd.github+json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!releaseRes.ok) {
|
||||
const body = await releaseRes.text();
|
||||
throw new Error(`Failed to fetch release ${tag}: ${releaseRes.status} ${body}`);
|
||||
}
|
||||
|
||||
const release = await releaseRes.json();
|
||||
const description = (release.body || `OpenChamber ${tag} released.`).slice(0, 4096);
|
||||
|
||||
const payload = {
|
||||
username: 'OpenChamber Releases',
|
||||
embeds: [
|
||||
{
|
||||
title: release.name || `OpenChamber ${tag}`,
|
||||
url: release.html_url,
|
||||
description,
|
||||
color: 2105893,
|
||||
footer: { text: 'OpenChamber Changelog' },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const discordRes = await fetch(process.env.DISCORD_WEBHOOK_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!discordRes.ok) {
|
||||
const body = await discordRes.text();
|
||||
throw new Error(`Failed to send Discord release: ${discordRes.status} ${body}`);
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
|
||||
Reference in New Issue
Block a user