Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions scripts/build-desktop-artifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
}),
);

it.effect("retries Electron packaging when Apple's timestamp server drops a signature", () =>
Effect.gen(function* () {
let attempts = 0;
const result = yield* retryTransientElectronPackaging(
Effect.suspend(() => {
attempts += 1;
return attempts < 2
? Effect.fail(
new TestFailure({
message:
"Command failed: codesign --sign ... locale.pak\nlocale.pak: A timestamp was expected but was not found.",
}),
)
: Effect.succeed("built");
}),
);

assert.equal(result, "built");
assert.equal(attempts, 2);
}),
);

it.effect("does not retry non-network packaging failures", () =>
Effect.gen(function* () {
let attempts = 0;
Expand Down
30 changes: 27 additions & 3 deletions scripts/build-desktop-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,20 +564,44 @@ const runCommand = Effect.fn("runCommand")(function* (command: ChildProcess.Comm
}
});

/**
* What codesign prints when Apple's timestamp server (timestamp.apple.com)
* doesn't answer `--timestamp`. The server drops requests now and then; the
* same signature succeeds on the next try.
*/
const APPLE_TIMESTAMP_FAILURE_PATTERNS = [
"a timestamp was expected but was not found",
"the timestamp service is not available",
] as const;

function isAppleTimestampFailure(error: unknown): boolean {
const message = (error instanceof Error ? error.message : String(error)).toLowerCase();
return APPLE_TIMESTAMP_FAILURE_PATTERNS.some((pattern) => message.includes(pattern));
}

function isTransientPackagingFailure(error: unknown): boolean {
return isTransientNetworkFailure(error) || isAppleTimestampFailure(error);
}

/**
* Runs electron-builder again, up to twice, when it fails on a network blip or
* on Apple's timestamp server. Each run re-extracts Electron and signs from
* scratch, so a retry never sees a half-signed app.
*/
export function retryTransientElectronPackaging<A, E, R>(
packaging: Effect.Effect<A, E, R>,
): Effect.Effect<A, E, R> {
return packaging.pipe(
Effect.tapError((error) =>
isTransientNetworkFailure(error)
isTransientPackagingFailure(error)
? Effect.logWarning(
"[desktop-artifact] Electron packaging hit a transient network failure; bounded retry policy active.",
"[desktop-artifact] Electron packaging hit a transient network or code-signing timestamp failure; bounded retry policy active.",
)
: Effect.void,
),
Effect.retry({
times: 2,
while: isTransientNetworkFailure,
while: isTransientPackagingFailure,
}),
);
}
Expand Down
Loading