Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(ci): use Discord webhooks for release announce (works with forum channels)

EtienneLescot268372902b1f
diff --git a/.github/scripts/discord-release-announce.mjs b/.github/scripts/discord-release-announce.mjs
index 331a301e6..2df2cbf78 100644
--- a/.github/scripts/discord-release-announce.mjs
+++ b/.github/scripts/discord-release-announce.mjs
@@ -1,72 +1,72 @@
import { info, warning } from "@actions/core";
import { context, getOctokit } from "@actions/github";
+const WEBHOOK_USERNAME = (process.env.DISCORD_WEBHOOK_USERNAME || "OpenScreen").trim();
+const WEBHOOK_AVATAR = (process.env.DISCORD_WEBHOOK_AVATAR_URL || "").trim();
+
const botToken = (process.env.DISCORD_BOT_TOKEN || "").trim();
+const channelId = (
+ process.env.DISCORD_RC_TESTING_CHANNEL_ID ||
+ process.env.DISCORD_RELEASE_CHANNEL_ID ||
+ ""
+).trim();
+const webhookUrl = (
+ process.env.DISCORD_RC_TESTING_WEBHOOK_URL ||
+ process.env.DISCORD_RELEASE_WEBHOOK_URL ||
+ process.env.DISCORD_WEBHOOK_URL ||
+ ""
+).trim();
+
const kind = (process.env.KIND || "stable").trim();
const stableTag = (process.env.STABLE_TAG || "").trim();
const rcTag = (process.env.RC_TAG || "").trim();
const extra = (process.env.EXTRA || "").trim();
-const channelId =
- kind === "rc"
- ? (process.env.DISCORD_RC_TESTING_CHANNEL_ID || "").trim()
- : (process.env.DISCORD_RELEASE_CHANNEL_ID || "").trim();
-
-if (!botToken || !channelId) {
- info(
- `Discord ${kind} announcement skipped: missing DISCORD_BOT_TOKEN or channel id. ` +
- `Set DISCORD_${kind === "rc" ? "RC_TESTING_" : ""}CHANNEL_ID as a repo variable.`,
- );
- process.exit(0);
-}
if (!stableTag) {
warning("STABLE_TAG missing; skipping.");
process.exit(0);
}
+if (!webhookUrl && (!botToken || !channelId)) {
+ info(
+ "Discord announce skipped: set either a webhook URL (preferred) or both " +
+ "DISCORD_BOT_TOKEN and a channel id.",
+ );
+ process.exit(0);
+}
const owner = context.repo.owner;
const repo = context.repo.repo;
const releaseUrl = `${context.serverUrl}/${owner}/${repo}/releases/tag/${stableTag}`;
-
-const octokit = getOctokit(process.env.GITHUB_TOKEN);
-
-let releaseBody = "";
-try {
- const r = await octokit.rest.repos.getReleaseByTag({
- owner,
- repo,
- tag: stableTag,
- });
- releaseBody = (r.data.body || "").slice(0, 1500);
-} catch (err) {
- warning(`Failed to fetch release body: ${err?.message ?? err}`);
-}
+const stableVersion = stableTag.replace(/^v/, "").replace(/-.*$/, "");
let closedIssues = [];
-try {
- const versionTitle = `v${stableTag.replace(/^v/, "").replace(/-.*$/, "")}`;
- const milestones = await octokit.paginate(octokit.rest.issues.listMilestones, {
- owner,
- repo,
- state: "closed",
- per_page: 100,
- });
- const m = milestones.find((x) => x.title === versionTitle);
- if (m) {
- const issues = await octokit.paginate(octokit.rest.issues.listForRepo, {
+if (process.env.GITHUB_TOKEN) {
+ try {
+ const octokit = getOctokit(process.env.GITHUB_TOKEN);
+ const versionTitle = `v${stableVersion}`;
+ const milestones = await octokit.paginate(octokit.rest.issues.listMilestones, {
owner,
repo,
- milestone: `${m.number}`,
state: "closed",
per_page: 100,
});
- closedIssues = issues
- .filter((i) => !i.pull_request)
- .slice(0, 20)
- .map((i) => `• [#${i.number}](${i.html_url}) ${i.title}`);
+ const m = milestones.find((x) => x.title === versionTitle);
+ if (m) {
+ const issues = await octokit.paginate(octokit.rest.issues.listForRepo, {
+ owner,
+ repo,
+ milestone: `${m.number}`,
+ state: "closed",
+ per_page: 100,
+ });
+ closedIssues = issues
+ .filter((i) => !i.pull_request)
+ .slice(0, 20)
+ .map((i) => `• [#${i.number}](${i.html_url}) ${i.title}`);
+ }
+ } catch (err) {
+ warning(`Failed to fetch closed issues: ${err?.message ?? err}`);
}
-} catch (err) {
- warning(`Failed to fetch closed issues: ${err?.message ?? err}`);
}
const isRc = kind === "rc";
@@ -80,7 +80,6 @@ const description = [
`📦 **Download:** [${stableTag}](${releaseUrl})`,
isRc && rcTag ? `_Promoted from \`${rcTag}\`_` : "",
closedIssues.length > 0 ? `\n**Closed issues in this release:**\n${closedIssues.join("\n")}` : "",
- releaseBody ? `\n---\n${releaseBody}` : "",
]
.filter(Boolean)
.join("\n");
@@ -98,7 +97,28 @@ const payload = {
allowed_mentions: { parse: [] },
};
-try {
+async function postViaWebhook() {
+ const endpoint = new URL(webhookUrl);
+ endpoint.searchParams.set("wait", "true");
+ const res = await fetch(endpoint.toString(), {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ username: WEBHOOK_USERNAME,
+ avatar_url: WEBHOOK_AVATAR || undefined,
+ ...payload,
+ }),
+ });
+ if (!res.ok) {
+ const txt = await res.text();
+ warning(`Discord webhook POST failed ${res.status}: ${txt}`);
+ return false;
+ }
+ info(`📣 ${kind} announcement posted for ${stableTag} via webhook.`);
+ return true;
+}
+
+async function postViaBot() {
const res = await fetch(`https://discord.com/api/v10/channels/${channelId}/messages`, {
method: "POST",
headers: {
@@ -109,10 +129,15 @@ try {
});
if (!res.ok) {
const txt = await res.text();
- warning(`Discord POST failed ${res.status}: ${txt}`);
- process.exit(0);
+ warning(`Discord bot POST failed ${res.status}: ${txt}`);
+ return false;
}
- info(`📣 ${kind} announcement posted for ${stableTag} in channel ${channelId}.`);
-} catch (err) {
- warning(`Discord throw: ${err?.message ?? err}`);
+ info(`📣 ${kind} announcement posted for ${stableTag} via bot.`);
+ return true;
+}
+
+if (webhookUrl) {
+ await postViaWebhook();
+} else {
+ await postViaBot();
}
diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml
index e3f355928..4f6209d11 100644
--- a/.github/workflows/prerelease.yml
+++ b/.github/workflows/prerelease.yml
@@ -143,6 +143,9 @@ jobs:
- name: Announce RC on Discord (#rc-testing)
if: success()
env:
+ # Webhook is preferred over bot+channel because #rc-testing is a forum channel,
+ # which only accepts posts via webhook (the bot can't create messages there directly).
+ DISCORD_RC_TESTING_WEBHOOK_URL: ${{ vars.DISCORD_RC_TESTING_WEBHOOK_URL }}
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
DISCORD_RC_TESTING_CHANNEL_ID: ${{ vars.DISCORD_RC_TESTING_CHANNEL_ID }}
GITHUB_TOKEN: ${{ secrets.OPENSCREEN_RELEASE_TOKEN }}
diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml
index da7625071..d15e5a51b 100644
--- a/.github/workflows/promote.yml
+++ b/.github/workflows/promote.yml
@@ -124,6 +124,8 @@ jobs:
- name: Announce stable on Discord
if: success()
env:
+ # Webhook is preferred over bot+channel for forum/announcement channels.
+ DISCORD_RELEASE_WEBHOOK_URL: ${{ vars.DISCORD_RELEASE_WEBHOOK_URL }}
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
DISCORD_RELEASE_CHANNEL_ID: ${{ vars.DISCORD_RELEASE_CHANNEL_ID }}
GITHUB_TOKEN: ${{ secrets.OPENSCREEN_RELEASE_TOKEN }}
diff --git a/docs/secrets.md b/docs/secrets.md
index b05754092..1e236575c 100644
--- a/docs/secrets.md
+++ b/docs/secrets.md
@@ -93,26 +93,30 @@ gh api /repos/getopenscreen/openscreen/rulesets/18060803 --jq '.bypass_actors'
Bot token from a Discord application added to the OpenScreen Discord server with the `bot` scope and at minimum:
-- `Send Messages` in `#rc-testing` and the release-announcement channel
+- `Send Messages` in any text channels where the bot posts
- `Manage Messages` if you want the roadmap-sync workflow to pin its message
- `Read Message History` (usually default)
Stored as a repository secret.
-### `DISCORD_RC_TESTING_CHANNEL_ID`
+### `DISCORD_RC_TESTING_WEBHOOK_URL` (preferred) or `DISCORD_RC_TESTING_CHANNEL_ID` (fallback)
-Snowflake ID of the Discord channel where release candidates are announced. Set as a **repository variable** (not a secret — it's not sensitive).
+A **Discord webhook** for the `#rc-testing` channel. Each pre-release creates a new thread in the forum. Preferred because the channel is a forum and webhooks can create threads there, while a bot cannot post messages directly to a forum channel.
+
+To create: in Discord, channel ⚙️ → Integrations → Webhooks → New Webhook → name it (e.g. "OpenScreen Releases") → Copy URL. Set as a **repository variable** (not a secret if it's a per-channel URL, but you can also set it as a secret if you want it private):
```bash
-gh variable set DISCORD_RC_TESTING_CHANNEL_ID --body "1521416826146263051" --repo getopenscreen/openscreen
+gh variable set DISCORD_RC_TESTING_WEBHOOK_URL --body "https://discord.com/api/webhooks/<id>/<token>" --repo getopenscreen/openscreen
```
-### `DISCORD_RELEASE_CHANNEL_ID`
+If a webhook is not set, the script falls back to `DISCORD_BOT_TOKEN` + `DISCORD_RC_TESTING_CHANNEL_ID` (bot message in a text channel). Forum channels will not work via this fallback — it returns Discord error `50008 Cannot send messages in a non-text channel`.
+
+### `DISCORD_RELEASE_WEBHOOK_URL` (preferred) or `DISCORD_RELEASE_CHANNEL_ID` (fallback)
-Snowflake ID of the channel where stable releases are announced. Repository variable.
+Same pattern as above, for the stable release announcement channel. Each stable release creates a new thread in the forum.
```bash
-gh variable set DISCORD_RELEASE_CHANNEL_ID --body "<id>" --repo getopenscreen/openscreen
+gh variable set DISCORD_RELEASE_WEBHOOK_URL --body "https://discord.com/api/webhooks/<id>/<token>" --repo getopenscreen/openscreen
```
### `DISCORD_ROADMAP_CHANNEL_ID` and `DISCORD_ROADMAP_MESSAGE_ID`