The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 05:00 UTC
Add structured Discord webhook logging for release notifications (#2431)
Co-authored-by: Julius Marminge <julius@macmini.local>
Julius Marminge committed
Apr 30, 2026 at 20:53 UTC
17b43960e86335534c63fb2b93ea68300b3bcc62
3 files changed
+90
-25
.github/workflows/release.yml
+4
-4
@@ -622,11 +622,11 @@ jobs:
622
if: needs.preflight.outputs.is_prerelease == 'true'
623
continue-on-error: true
624
env:
625
- DISCORD_RELEASE_NIGHTLY_ROLE_ID: ${{ vars.DISCORD_RELEASE_NIGHTLY_ROLE_ID }}
625
+ DISCORD_MENTION_ROLE_ID: ${{ secrets.DISCORD_RELEASE_NIGHTLY_ROLE_ID }}
626
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
627
run: |
628
node scripts/notify-discord-release.ts prerelease \
629
- --role-id "$DISCORD_RELEASE_NIGHTLY_ROLE_ID" \
629
+ --role-id "$DISCORD_MENTION_ROLE_ID" \
630
--release-name "${{ needs.preflight.outputs.release_name }}" \
631
--version "${{ needs.preflight.outputs.version }}" \
632
--tag "${{ needs.preflight.outputs.tag }}" \
@@ -636,11 +636,11 @@ jobs:
636
if: needs.preflight.outputs.make_latest == 'true'
637
continue-on-error: true
638
env:
639
- DISCORD_RELEASE_LATEST_ROLE_ID: ${{ vars.DISCORD_RELEASE_LATEST_ROLE_ID }}
639
+ DISCORD_MENTION_ROLE_ID: ${{ secrets.DISCORD_RELEASE_LATEST_ROLE_ID }}
640
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
641
run: |
642
node scripts/notify-discord-release.ts latest \
643
- --role-id "$DISCORD_RELEASE_LATEST_ROLE_ID" \
643
+ --role-id "$DISCORD_MENTION_ROLE_ID" \
644
--release-name "${{ needs.preflight.outputs.release_name }}" \
645
--version "${{ needs.preflight.outputs.version }}" \
646
--tag "${{ needs.preflight.outputs.tag }}" \
scripts/notify-discord-release.test.ts
+4
-2
@@ -10,7 +10,9 @@ it("builds a prerelease Discord announcement for nightly subscribers", () => {
10
releaseName: "T3 Code Nightly 1.2.4-nightly.20260501.17 (abcdef123456)",
11
version: "1.2.4-nightly.20260501.17",
12
tag: "v1.2.4-nightly.20260501.17",
13
- releaseUrl: "https://github.com/t3dotgg/t3-code/releases/tag/v1.2.4-nightly.20260501.17",
13
+ releaseUrl: new URL(
14
+ "https://github.com/t3dotgg/t3-code/releases/tag/v1.2.4-nightly.20260501.17",
15
+ ),
16
timestamp: "2026-05-01T01:41:00.000Z",
17
}),
18
{
@@ -52,7 +54,7 @@ it("builds a latest Discord announcement for stable subscribers", () => {
54
releaseName: "T3 Code v1.2.3",
55
version: "1.2.3",
56
tag: "v1.2.3",
55
- releaseUrl: "https://github.com/t3dotgg/t3-code/releases/tag/v1.2.3",
57
+ releaseUrl: new URL("https://github.com/t3dotgg/t3-code/releases/tag/v1.2.3"),
58
timestamp: "2026-05-01T01:41:00.000Z",
59
}),
60
{
scripts/notify-discord-release.ts
+82
-19
@@ -2,9 +2,14 @@
2
3
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
4
import * as NodeServices from "@effect/platform-node/NodeServices";
5
-import { Config, Data, Effect, Layer, Schema } from "effect";
5
+import { Config, Data, Effect, Layer, Logger, Schema } from "effect";
6
import { Argument, Command, Flag } from "effect/unstable/cli";
7
-import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
7
+import {
8
+ FetchHttpClient,
9
+ HttpClient,
10
+ HttpClientRequest,
11
+ HttpClientResponse,
12
+} from "effect/unstable/http";
13
14
export type DiscordReleaseTarget = "prerelease" | "latest";
15
@@ -14,7 +19,7 @@ interface DiscordReleaseAnnouncementOptions {
19
readonly releaseName: string;
20
readonly version: string;
21
readonly tag: string;
17
- readonly releaseUrl: string;
22
+ readonly releaseUrl: URL;
23
readonly timestamp: string;
24
}
25
@@ -39,8 +44,7 @@ interface DiscordWebhookPayload {
44
45
const DISCORD_RELEASE_TARGETS = ["prerelease", "latest"] as const;
46
const DiscordRoleIdSchema = Schema.String.check(Schema.isPattern(/^\d+$/));
42
-const WebUrlSchema = Schema.String.check(Schema.isPattern(/^https?:\/\/\S+$/));
43
-const DiscordWebhookUrl = Config.nonEmptyString("DISCORD_WEBHOOK_URL");
47
+const DiscordWebhookUrl = Config.url("DISCORD_WEBHOOK_URL");
48
49
class DiscordReleaseAnnouncementError extends Data.TaggedError("DiscordReleaseAnnouncementError")<{
50
readonly message: string;
@@ -57,6 +61,23 @@ const targetColors = {
61
latest: 0x2ecc71,
62
} as const satisfies Record<DiscordReleaseTarget, number>;
63
64
+function describeWebhookUrl(webhookUrl: URL) {
65
+ return {
66
+ configured: true,
67
+ origin: webhookUrl.origin,
68
+ pathnameSegmentCount: webhookUrl.pathname.split("/").filter(Boolean).length,
69
+ } as const;
70
+}
71
+
72
+function summarizePayload(payload: DiscordWebhookPayload) {
73
+ return {
74
+ contentLength: payload.content.length,
75
+ embedCount: payload.embeds.length,
76
+ allowedRoleMentionCount: payload.allowed_mentions.roles.length,
77
+ hasRoleMentionSyntax: payload.content.includes("<@&"),
78
+ } as const;
79
+}
80
+
81
export const buildDiscordReleaseAnnouncement = (
82
options: DiscordReleaseAnnouncementOptions,
83
): DiscordWebhookPayload => ({
@@ -67,7 +88,7 @@ export const buildDiscordReleaseAnnouncement = (
88
embeds: [
89
{
90
title: options.releaseName,
70
- url: options.releaseUrl,
91
+ url: options.releaseUrl.href,
92
description:
93
options.target === "prerelease"
94
? "A new T3 Code prerelease is available for nightly testers."
@@ -91,7 +112,7 @@ export const buildDiscordReleaseAnnouncement = (
112
});
113
114
const postDiscordWebhook = Effect.fn("postDiscordWebhook")(function* (
94
- webhookUrl: string,
115
+ webhookUrl: URL,
116
payload: DiscordWebhookPayload,
117
) {
118
const httpClient = (yield* HttpClient.HttpClient).pipe(
@@ -99,10 +120,16 @@ const postDiscordWebhook = Effect.fn("postDiscordWebhook")(function* (
120
retryOn: "errors-and-responses",
121
times: 3,
122
}),
102
- HttpClient.filterStatusOk,
123
);
124
105
- yield* HttpClientRequest.post(webhookUrl).pipe(
125
+ yield* Effect.logInfo("discord webhook request dispatching").pipe(
126
+ Effect.annotateLogs({
127
+ ...describeWebhookUrl(webhookUrl),
128
+ ...summarizePayload(payload),
129
+ }),
130
+ );
131
+
132
+ const response = yield* HttpClientRequest.post(webhookUrl).pipe(
133
HttpClientRequest.bodyJson(payload),
134
Effect.flatMap(httpClient.execute),
135
Effect.mapError(
@@ -113,9 +140,24 @@ const postDiscordWebhook = Effect.fn("postDiscordWebhook")(function* (
140
}),
141
),
142
);
116
-});
143
118
-const runtimeLayer = Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer);
144
+ yield* Effect.logInfo("discord webhook response received").pipe(
145
+ Effect.annotateLogs({
146
+ status: response.status,
147
+ ok: response.status >= 200 && response.status < 300,
148
+ }),
149
+ );
150
+
151
+ yield* HttpClientResponse.filterStatusOk(response).pipe(
152
+ Effect.mapError(
153
+ (cause) =>
154
+ new DiscordReleaseAnnouncementError({
155
+ message: `Discord webhook returned status ${response.status}.`,
156
+ cause,
157
+ }),
158
+ ),
159
+ );
160
+});
161
162
export const notifyDiscordReleaseCommand = Command.make(
163
"notify-discord-release",
@@ -140,31 +182,52 @@ export const notifyDiscordReleaseCommand = Command.make(
182
Flag.withDescription("Git tag for the release."),
183
),
184
releaseUrl: Flag.string("release-url").pipe(
143
- Flag.withSchema(WebUrlSchema),
185
+ Flag.withSchema(Schema.URLFromString),
186
Flag.withDescription("Public GitHub release URL."),
187
),
188
},
189
({ target, roleId, releaseName, version, tag, releaseUrl }) =>
190
Effect.gen(function* () {
149
- const webhookUrl = yield* DiscordWebhookUrl;
150
- yield* postDiscordWebhook(
151
- webhookUrl,
152
- buildDiscordReleaseAnnouncement({
191
+ yield* Effect.logInfo("discord release announcement starting").pipe(
192
+ Effect.annotateLogs({
193
target,
154
- roleId,
194
+ roleIdProvided: roleId.length > 0,
195
+ roleIdLength: roleId.length,
196
releaseName,
197
version,
198
tag,
199
releaseUrl,
159
- timestamp: new Date().toISOString(),
200
}),
201
);
202
+
203
+ const webhookUrl = yield* DiscordWebhookUrl;
204
+ const payload = buildDiscordReleaseAnnouncement({
205
+ target,
206
+ roleId,
207
+ releaseName,
208
+ version,
209
+ tag,
210
+ releaseUrl,
211
+ timestamp: new Date().toISOString(),
212
+ });
213
+
214
+ yield* Effect.logInfo("discord release announcement payload built").pipe(
215
+ Effect.annotateLogs(summarizePayload(payload)),
216
+ );
217
+ yield* postDiscordWebhook(webhookUrl, payload);
218
+ yield* Effect.logInfo("discord release announcement completed");
219
}),
220
).pipe(Command.withDescription("Post a T3 Code release announcement to Discord."));
221
222
if (import.meta.main) {
223
Command.run(notifyDiscordReleaseCommand, { version: "0.0.0" }).pipe(
167
- Effect.provide(runtimeLayer),
224
+ Effect.provide(
225
+ Layer.mergeAll(
226
+ Logger.layer([Logger.consolePretty()]),
227
+ NodeServices.layer,
228
+ FetchHttpClient.layer,
229
+ ),
230
+ ),
231
NodeRuntime.runMain,
232
);
233
}