Skip to content

Commit b463930

Browse files
committed
discord announcment on release
1 parent 5ef6ab3 commit b463930

2 files changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: "Notify Discord"
2+
description: "Post a release announcement embed to a Discord channel webhook"
3+
4+
inputs:
5+
webhook-url:
6+
description: "[secret] Discord channel webhook URL. Empty disables the block."
7+
required: false
8+
default: ""
9+
service-name:
10+
description: "[string] Display name of the released service"
11+
required: true
12+
version:
13+
description: "[string] Version being released (e.g., 1.2.3)"
14+
required: true
15+
release-url:
16+
description: "[string] URL to the GitHub Release"
17+
required: true
18+
release-notes:
19+
description: "[string] Markdown release notes (truncated to 4096 chars)"
20+
required: false
21+
default: ""
22+
prerelease:
23+
description: "[boolean: 'true'/'false'] Whether this is a prerelease"
24+
required: false
25+
default: "false"
26+
dry-run:
27+
description: "[boolean: 'true'/'false'] Log payload without sending"
28+
required: false
29+
default: "false"
30+
31+
runs:
32+
using: composite
33+
steps:
34+
- name: Send Discord announcement
35+
uses: actions/github-script@v7
36+
env:
37+
WEBHOOK_URL: ${{ inputs.webhook-url }}
38+
SERVICE_NAME: ${{ inputs.service-name }}
39+
VERSION: ${{ inputs.version }}
40+
RELEASE_URL: ${{ inputs.release-url }}
41+
RELEASE_NOTES: ${{ inputs.release-notes }}
42+
PRERELEASE: ${{ inputs.prerelease }}
43+
DRY_RUN: ${{ inputs.dry-run }}
44+
with:
45+
script: |
46+
const webhookUrl = process.env.WEBHOOK_URL;
47+
if (!webhookUrl) {
48+
core.info('Discord webhook not configured, skipping.');
49+
return;
50+
}
51+
core.setSecret(webhookUrl);
52+
53+
const serviceName = process.env.SERVICE_NAME;
54+
const version = process.env.VERSION;
55+
const releaseUrl = process.env.RELEASE_URL;
56+
const rawNotes = process.env.RELEASE_NOTES || '';
57+
const isPrerelease = process.env.PRERELEASE === 'true';
58+
const isDryRun = process.env.DRY_RUN === 'true';
59+
60+
const MAX_DESCRIPTION = 4096;
61+
const description = rawNotes.length > MAX_DESCRIPTION
62+
? rawNotes.slice(0, MAX_DESCRIPTION - 1) + '\u2026'
63+
: rawNotes;
64+
65+
const titlePrefix = isPrerelease ? '[Pre-release] ' : '';
66+
const color = isPrerelease ? 0xF1C40F : 0x2ECC71;
67+
68+
const payload = {
69+
embeds: [
70+
{
71+
title: `${titlePrefix}${serviceName} v${version}`,
72+
url: releaseUrl,
73+
description,
74+
color,
75+
timestamp: new Date().toISOString(),
76+
footer: { text: context.payload.repository?.full_name || `${context.repo.owner}/${context.repo.repo}` },
77+
},
78+
],
79+
};
80+
81+
if (isDryRun) {
82+
core.info('Dry run enabled, not sending. Payload:');
83+
core.info(JSON.stringify(payload, null, 2));
84+
return;
85+
}
86+
87+
const response = await fetch(webhookUrl, {
88+
method: 'POST',
89+
headers: { 'Content-Type': 'application/json' },
90+
body: JSON.stringify(payload),
91+
});
92+
93+
if (!response.ok) {
94+
const body = await response.text();
95+
core.setFailed(`Discord webhook returned ${response.status} ${response.statusText}: ${body}`);
96+
return;
97+
}
98+
99+
core.info(`Discord announcement posted (HTTP ${response.status}).`);

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,59 @@ Posts or updates a single comment on a pull request. When a `comment-key` is pro
12731273
```
12741274

12751275

1276+
---
1277+
1278+
### notify-discord
1279+
1280+
**Path:** `.github/blocks/notify-discord/action.yaml`
1281+
1282+
Posts a release announcement embed to a Discord channel webhook. The block no-ops when `webhook-url` is empty, so it can be wired into a pipeline unconditionally and stays dormant for repos that haven't configured `DISCORD_WEBHOOK_URL`.
1283+
1284+
#### Setup (one-time, in Discord)
1285+
1286+
1. Open the Discord server, then **Server Settings → Integrations → Webhooks → New Webhook**.
1287+
2. Pick the channel where releases should be announced.
1288+
3. Copy the webhook URL (looks like `https://discord.com/api/webhooks/<id>/<token>`).
1289+
4. Add it to GitHub as a repo or org Actions secret named `DISCORD_WEBHOOK_URL`.
1290+
1291+
The webhook URL is bound to the channel selected in step 2 — that is how "specific channel" is targeted; no channel ID is needed in the workflow.
1292+
1293+
#### Inputs
1294+
1295+
| Input | Type | Required | Default | Description |
1296+
|-------|------|----------|---------|-------------|
1297+
| `webhook-url` | string (secret) | No | `""` | Discord channel webhook URL. Empty disables the block. |
1298+
| `service-name` | string | Yes | — | Display name of the released service |
1299+
| `version` | string | Yes | — | Version being released (e.g., `1.2.3`) |
1300+
| `release-url` | string | Yes | — | URL to the GitHub Release (use the `url` output of `create-github-release`) |
1301+
| `release-notes` | string | No | `""` | Markdown release notes (auto-truncated to Discord's 4096-char embed limit) |
1302+
| `prerelease` | boolean | No | `"false"` | Tags the embed as a prerelease (amber color, `[Pre-release]` title prefix) |
1303+
| `dry-run` | boolean | No | `"false"` | Logs the JSON payload without sending |
1304+
1305+
#### Usage
1306+
1307+
```yaml
1308+
- name: Create GitHub Release
1309+
id: gh-release
1310+
uses: photon-hq/buildspace/.github/blocks/create-github-release@main
1311+
with:
1312+
version: ${{ steps.release-info.outputs.version }}
1313+
title: "${{ inputs.service-name }} v${{ steps.release-info.outputs.version }}"
1314+
notes: ${{ steps.release-info.outputs.release_notes }}
1315+
prerelease: ${{ inputs.prerelease }}
1316+
1317+
- name: Announce release on Discord
1318+
uses: photon-hq/buildspace/.github/blocks/notify-discord@main
1319+
with:
1320+
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
1321+
service-name: ${{ inputs.service-name }}
1322+
version: ${{ steps.release-info.outputs.version }}
1323+
release-url: ${{ steps.gh-release.outputs.url }}
1324+
release-notes: ${{ steps.release-info.outputs.release_notes }}
1325+
prerelease: ${{ inputs.prerelease }}
1326+
```
1327+
1328+
12761329
---
12771330

12781331
### update-docs

0 commit comments

Comments
 (0)