Skip to content

Commit 7b19cb7

Browse files
committed
fix(release): preserve announcements when changelog lookup fails
1 parent 31f3796 commit 7b19cb7

3 files changed

Lines changed: 67 additions & 12 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,6 @@ jobs:
13481348
- --filter=@t3tools/scripts...
13491349
13501350
- name: Read published release notes
1351-
id: discord_release_notes
13521351
if: needs.preflight.outputs.is_prerelease == 'true'
13531352
continue-on-error: true
13541353
env:
@@ -1358,13 +1357,16 @@ jobs:
13581357
RELEASE_CHANNEL: ${{ needs.preflight.outputs.release_channel }}
13591358
run: |
13601359
if [ "$RELEASE_CHANNEL" = 'nightly' ]; then
1361-
gh release view "$RELEASE_TAG" --json body --jq '.body // ""' > "$RUNNER_TEMP/discord-release-notes.md"
1360+
if ! gh release view "$RELEASE_TAG" --json body --jq '.body // ""' > "$RUNNER_TEMP/discord-release-notes.md"; then
1361+
: > "$RUNNER_TEMP/discord-release-notes.md"
1362+
echo '::warning::Could not read published release notes; announcing without a changelog.'
1363+
fi
13621364
else
13631365
: > "$RUNNER_TEMP/discord-release-notes.md"
13641366
fi
13651367
13661368
- name: Announce prerelease on Discord
1367-
if: needs.preflight.outputs.is_prerelease == 'true' && steps.discord_release_notes.outcome == 'success'
1369+
if: needs.preflight.outputs.is_prerelease == 'true'
13681370
continue-on-error: true
13691371
env:
13701372
DISCORD_MENTION_ROLE_ID: ${{ secrets.DISCORD_RELEASE_NIGHTLY_ROLE_ID }}

‎scripts/notify-discord-release.test.ts‎

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,46 @@ it.effect("waits for Retry-After before retrying a rate-limited message", () =>
403403
}),
404404
);
405405

406+
it.effect("bounds total retry time while preserving delays within the deadline", () =>
407+
Effect.gen(function* () {
408+
const limited = yield* Deferred.make<void>();
409+
let attempts = 0;
410+
const client = Layer.succeed(
411+
HttpClient.HttpClient,
412+
HttpClient.make((request) =>
413+
Effect.gen(function* () {
414+
attempts += 1;
415+
yield* Deferred.succeed(limited, undefined);
416+
return HttpClientResponse.fromWeb(
417+
request,
418+
new Response(null, { status: 429, headers: { "retry-after": "40" } }),
419+
);
420+
}),
421+
),
422+
);
423+
const fiber = yield* postDiscordWebhook(
424+
webhookUrl,
425+
buildDiscordReleaseAnnouncement(latestAnnouncement)[0]!,
426+
latestAnnouncement,
427+
).pipe(Effect.provide(client), Effect.result, Effect.forkChild);
428+
yield* Deferred.await(limited);
429+
yield* TestClock.adjust("39 seconds");
430+
assert.equal(attempts, 1);
431+
yield* TestClock.adjust("1 second");
432+
assert.equal(attempts, 2);
433+
yield* TestClock.adjust("20 seconds");
434+
const result = yield* Fiber.join(fiber);
435+
assert.equal(attempts, 2);
436+
assert.equal(result._tag, "Failure");
437+
if (result._tag !== "Failure") assert.fail("Expected the retry deadline to expire");
438+
assert.equal(result.failure._tag, "DiscordReleaseWebhookRequestError");
439+
if (result.failure._tag !== "DiscordReleaseWebhookRequestError")
440+
assert.fail(`Unexpected error: ${result.failure._tag}`);
441+
assert.equal(result.failure.reason, "TimeoutError");
442+
assert.ok(!Cause.pretty(Cause.fail(result.failure)).includes("test-secret-token"));
443+
}),
444+
);
445+
406446
// Run the checked-in shell commands with gh/node stubs, then send their captured
407447
// arguments through the real CLI parser and an injected HTTP client.
408448
function workflowRun(workflow: string, stepName: string) {
@@ -494,20 +534,31 @@ it.layer(NodeServices.layer)("Discord release CLI and workflow", (it) => {
494534
0,
495535
);
496536
assert.equal(yield* fs.readFileString(`${temp}/discord-release-notes.md`), "");
497-
// A failed fetch must skip the announcement, rather than send the empty
498-
// file created by shell redirection before gh failed.
499537
assert.equal(
500538
yield* spawner.exitCode(
501-
ChildProcess.make("bash", ["-e", "-c", `gh() { return 42; }\n${read}`], {
502-
env: shellEnv,
503-
}),
539+
ChildProcess.make(
540+
"bash",
541+
["-e", "-c", `gh() { printf '%s' 'partial changelog'; return 42; }\n${read}`],
542+
{ env: shellEnv },
543+
),
504544
),
505-
42,
545+
0,
506546
);
547+
assert.equal(yield* fs.readFileString(`${temp}/discord-release-notes.md`), "");
548+
const fallbackRequests: string[] = [];
549+
yield* runCli(args).pipe(Effect.provide([configLayer, captureClient(fallbackRequests)]));
550+
assert.equal(fallbackRequests.length, 1);
551+
const fallback = decodePayload(fallbackRequests[0]!);
552+
assert.equal(fallback.embeds[0]?.description, intro);
553+
assert.equal(fallback.content, `-# <@&${latestAnnouncement.roleId}>`);
554+
assert.deepStrictEqual(fallback.allowed_mentions, {
555+
parse: [],
556+
roles: [latestAnnouncement.roleId],
557+
});
507558
assert.ok(
508-
workflow.includes(
509-
"if: needs.preflight.outputs.is_prerelease == 'true' && steps.discord_release_notes.outcome == 'success'",
510-
),
559+
workflow
560+
.split(" - name: Announce prerelease on Discord\n")[1]
561+
?.startsWith(" if: needs.preflight.outputs.is_prerelease == 'true'\n"),
511562
);
512563
assert.ok(workflow.includes("GH_REPO: ${{ github.repository }}"));
513564
assert.ok(workflow.includes("RELEASE_TAG: ${{ needs.preflight.outputs.tag }}"));

‎scripts/notify-discord-release.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ export const postDiscordWebhook = Effect.fn("postDiscordWebhook")(function* (
285285
const response = yield* HttpClientRequest.post(requestUrl).pipe(
286286
HttpClientRequest.bodyJson(payload),
287287
Effect.flatMap(httpClient.execute),
288+
// Bound requests and retry waits together without shortening Retry-After.
289+
Effect.timeout("1 minute"),
288290
Effect.mapError(
289291
(error) =>
290292
new DiscordReleaseWebhookRequestError({

0 commit comments

Comments
 (0)