Skip to content

Commit 07457ce

Browse files
t3dotggclaude
andcommitted
fix(release): let concurrent npm publishes finish when one fails
Effect.forEach interrupted the other in-flight platform publishes on the first failure. An interrupted upload may already be live, and npm never accepts the same version twice, so the log could hide which platforms shipped. Collect every platform result first, then fail before the launcher if any platform failed. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 6fb13f2 commit 07457ce

3 files changed

Lines changed: 87 additions & 4 deletions

File tree

‎apps/server/scripts/cli.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ServerCliDevelopmentIconTargetMissingError,
2020
ServerCliExecutableImportError,
2121
} from "./cliErrors.ts";
22+
import { publishPlatformsThenLauncher } from "./publishOrder.ts";
2223

2324
const RepoRoot = Effect.service(Path.Path).pipe(
2425
Effect.flatMap((path) => path.fromFileUrl(new URL("../../..", import.meta.url))),
@@ -225,10 +226,8 @@ const publishCmd = Command.make(
225226
);
226227
});
227228

228-
// The platform packages do not depend on each other, so they publish at
229-
// once; each takes about 17s. The launcher still goes last.
230-
yield* Effect.forEach(platformTarballs, publish, { concurrency: "unbounded", discard: true });
231-
yield* publish(launcherTarball);
229+
// Each publish takes about 17s, so the platform packages go at once.
230+
yield* publishPlatformsThenLauncher({ platformTarballs, launcherTarball, publish });
232231
}),
233232
).pipe(
234233
Command.withDescription(
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { assert, it } from "@effect/vitest";
2+
import * as Effect from "effect/Effect";
3+
import * as Exit from "effect/Exit";
4+
import * as Latch from "effect/Latch";
5+
6+
import { publishPlatformsThenLauncher } from "./publishOrder.ts";
7+
8+
const platformTarballs = ["a.tgz", "b.tgz", "c.tgz"];
9+
const launcherTarball = "t3.tgz";
10+
11+
// A fake publish that records when each upload starts and ends. Platform
12+
// uploads only end once every platform upload has started, so they have to
13+
// run at the same time. `failing` fails as soon as it starts.
14+
const fakePublish = Effect.fn("fakePublish")(function* (failing?: string) {
15+
const events: Array<string> = [];
16+
const allStarted = yield* Latch.make();
17+
let started = 0;
18+
const publish = (tarball: string) =>
19+
Effect.gen(function* () {
20+
events.push(`start ${tarball}`);
21+
if (tarball === launcherTarball) return;
22+
started += 1;
23+
if (started === platformTarballs.length) yield* allStarted.open;
24+
if (tarball === failing) return yield* Effect.fail(`${tarball} failed`);
25+
yield* allStarted.await;
26+
events.push(`end ${tarball}`);
27+
});
28+
return { events, publish };
29+
});
30+
31+
it.effect("publishes the platform packages at once and the launcher last", () =>
32+
Effect.gen(function* () {
33+
const { events, publish } = yield* fakePublish();
34+
35+
yield* publishPlatformsThenLauncher({ platformTarballs, launcherTarball, publish });
36+
37+
assert.deepStrictEqual(events.slice(0, 3).toSorted(), [
38+
"start a.tgz",
39+
"start b.tgz",
40+
"start c.tgz",
41+
]);
42+
assert.strictEqual(events.at(-1), `start ${launcherTarball}`);
43+
}),
44+
);
45+
46+
it.effect("finishes the other uploads and skips the launcher when one fails", () =>
47+
Effect.gen(function* () {
48+
const { events, publish } = yield* fakePublish("b.tgz");
49+
50+
const exit = yield* Effect.exit(
51+
publishPlatformsThenLauncher({ platformTarballs, launcherTarball, publish }),
52+
);
53+
54+
assert.deepStrictEqual(exit, Exit.fail("b.tgz failed"));
55+
assert.includeMembers(events, ["end a.tgz", "end c.tgz"]);
56+
assert.notInclude(events, `start ${launcherTarball}`);
57+
}),
58+
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as Effect from "effect/Effect";
2+
import * as Result from "effect/Result";
3+
4+
/**
5+
* Publishes every platform package at once, then the launcher, which must
6+
* never be installable before the executables it points to. When one platform
7+
* fails, the other uploads still finish rather than being interrupted: npm
8+
* never accepts the same version twice, and an interrupted upload may already
9+
* be live. The launcher is then skipped and the first failure is returned.
10+
*/
11+
export const publishPlatformsThenLauncher = <E, R>(input: {
12+
readonly platformTarballs: ReadonlyArray<string>;
13+
readonly launcherTarball: string;
14+
readonly publish: (tarball: string) => Effect.Effect<void, E, R>;
15+
}) =>
16+
Effect.gen(function* () {
17+
const results = yield* Effect.all(input.platformTarballs.map(input.publish), {
18+
concurrency: "unbounded",
19+
mode: "result",
20+
});
21+
const failed = results.find(Result.isFailure);
22+
if (failed) {
23+
return yield* Effect.fail(failed.failure);
24+
}
25+
yield* input.publish(input.launcherTarball);
26+
});

0 commit comments

Comments
 (0)