Skip to content

Commit d20df4a

Browse files
t3dotggclaude
andcommitted
perf(release): macOS CLI notarization no longer blocks the desktop build
The arm64 macOS job now submits the CLI without waiting, builds the desktop while Apple reviews it, and uploads the CLI archive only after await-notarization sees Accepted. Standalone builds still wait and now also fail unless the status is Accepted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c8267db commit d20df4a

3 files changed

Lines changed: 384 additions & 26 deletions

File tree

‎.github/workflows/release-desktop.yml‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,17 @@ jobs:
435435
--arch "${{ inputs.arch }}" \
436436
--version "${{ inputs.version }}" \
437437
--resource-monitor-dir "$RUNNER_TEMP/cli-resource-monitor" \
438+
--notary-submission-file "$RUNNER_TEMP/t3-cli-notary-submission" \
438439
--output-dir release-cli
439440
440441
- name: Smoke-test CLI archive
441442
if: inputs.cli_archive && inputs.verify_runner == ''
442443
shell: bash
443444
run: node scripts/smoke-cli-archive.ts --archive release-cli/* --expect-version "${{ inputs.version }}"
444445

446+
# macOS uploads its archive after "Await CLI notarization" instead.
445447
- name: Upload CLI archive
446-
if: inputs.cli_archive
448+
if: inputs.cli_archive && inputs.platform != 'mac'
447449
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
448450
with:
449451
name: cli-${{ inputs.platform }}-${{ inputs.arch }}
@@ -618,6 +620,35 @@ jobs:
618620
619621
vp run dist:desktop:artifact "${args[@]}"
620622
623+
# The CLI was submitted without waiting so Apple reviews it while the
624+
# desktop builds. Notarization does not change the archive bytes, but
625+
# nothing uploads them, so nothing publishes them, until Apple accepts.
626+
- name: Await CLI notarization
627+
if: inputs.cli_archive && inputs.platform == 'mac'
628+
shell: bash
629+
env:
630+
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
631+
APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
632+
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
633+
run: |
634+
set -euo pipefail
635+
if [[ -n "${APPLE_API_KEY:-}" ]]; then
636+
key_path="$RUNNER_TEMP/AuthKey_cli_${APPLE_API_KEY_ID}.p8"
637+
printf '%s' "$APPLE_API_KEY" > "$key_path"
638+
trap 'rm -f "$key_path"' EXIT
639+
export APPLE_API_KEY="$key_path"
640+
fi
641+
node scripts/build-cli-archive.ts await-notarization \
642+
--submission-file "$RUNNER_TEMP/t3-cli-notary-submission"
643+
644+
- name: Upload notarized CLI archive
645+
if: inputs.cli_archive && inputs.platform == 'mac'
646+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
647+
with:
648+
name: cli-${{ inputs.platform }}-${{ inputs.arch }}
649+
path: release-cli/*
650+
if-no-files-found: error
651+
621652
# Warm installs only touch the store index, so new content means a fetch.
622653
- name: Check staged install cache for new content
623654
id: stage_pnpm_changed

‎scripts/build-cli-archive.test.ts‎

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
import * as NodeServices from "@effect/platform-node/NodeServices";
2+
import { assert, it } from "@effect/vitest";
3+
import * as ConfigProvider from "effect/ConfigProvider";
4+
import * as Effect from "effect/Effect";
5+
import * as FileSystem from "effect/FileSystem";
6+
import * as Option from "effect/Option";
7+
import * as Path from "effect/Path";
8+
import * as Sink from "effect/Sink";
9+
import * as Stream from "effect/Stream";
10+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
11+
12+
import { awaitCliNotarization, signMacArchiveContents } from "./build-cli-archive.ts";
13+
14+
const signedEnv = {
15+
T3CODE_CLI_MAC_SIGN_IDENTITY: "Developer ID Application: Test (TEAM)",
16+
APPLE_API_KEY: "/tmp/AuthKey_TEST.p8",
17+
APPLE_API_KEY_ID: "TEST",
18+
APPLE_API_ISSUER: "issuer",
19+
};
20+
21+
type NotaryReply = { readonly exitCode: number; readonly stdout?: string };
22+
23+
/** Stands in for `xcrun notarytool`, codesign and ditto; records each invocation. */
24+
function stubSpawner(notary: (subcommand: string) => NotaryReply) {
25+
const calls: Array<ReadonlyArray<string>> = [];
26+
const spawner = ChildProcessSpawner.make((command) => {
27+
const argv = ChildProcess.isStandardCommand(command)
28+
? [command.command, ...command.args.map(String)]
29+
: [];
30+
calls.push(argv);
31+
const reply = argv[1] === "notarytool" ? notary(argv[2] ?? "") : { exitCode: 0 };
32+
return Effect.succeed(
33+
ChildProcessSpawner.makeHandle({
34+
pid: ChildProcessSpawner.ProcessId(1),
35+
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(reply.exitCode)),
36+
isRunning: Effect.succeed(false),
37+
kill: () => Effect.void,
38+
unref: Effect.succeed(Effect.void),
39+
stdin: Sink.drain,
40+
stdout: reply.stdout ? Stream.make(new TextEncoder().encode(reply.stdout)) : Stream.empty,
41+
stderr: Stream.empty,
42+
all: Stream.empty,
43+
getInputFd: () => Sink.drain,
44+
getOutputFd: () => Stream.empty,
45+
}),
46+
);
47+
});
48+
return { calls, spawner };
49+
}
50+
51+
const withStubs = <A, E, R>(
52+
effect: Effect.Effect<A, E, R>,
53+
stub: ReturnType<typeof stubSpawner>,
54+
env: Record<string, string> = signedEnv,
55+
) =>
56+
effect.pipe(
57+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, stub.spawner),
58+
Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env }))),
59+
);
60+
61+
const makeContent = Effect.fn("test.makeContent")(function* () {
62+
const fs = yield* FileSystem.FileSystem;
63+
const path = yield* Path.Path;
64+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-notary-" });
65+
const contentDir = path.join(root, "content");
66+
yield* fs.makeDirectory(contentDir);
67+
const executablePath = path.join(contentDir, "t3");
68+
yield* fs.writeFileString(executablePath, "t3");
69+
return { root, contentDir, executablePath, submissionFile: path.join(root, "submission") };
70+
});
71+
72+
const notarySubcommands = (calls: ReadonlyArray<ReadonlyArray<string>>) =>
73+
calls.filter((argv) => argv[1] === "notarytool").map((argv) => argv.slice(2));
74+
75+
it.layer(NodeServices.layer)("build-cli-archive notarization", (it) => {
76+
it.effect("records a deferred submission without waiting, then gates on Accepted", () =>
77+
Effect.gen(function* () {
78+
const fs = yield* FileSystem.FileSystem;
79+
const content = yield* makeContent();
80+
yield* fs.writeFileString(content.submissionFile, "stale-id");
81+
const stub = stubSpawner((subcommand) =>
82+
subcommand === "submit"
83+
? { exitCode: 0, stdout: '{"id":"new-id","message":"Successfully uploaded file"}' }
84+
: { exitCode: 0, stdout: '{"id":"new-id","status":"Accepted"}' },
85+
);
86+
87+
yield* withStubs(
88+
signMacArchiveContents({
89+
repoRoot: content.root,
90+
contentDir: content.contentDir,
91+
executablePath: content.executablePath,
92+
notarySubmissionFile: Option.some(content.submissionFile),
93+
}),
94+
stub,
95+
);
96+
assert.equal(yield* fs.readFileString(content.submissionFile), "new-id");
97+
const [submit] = notarySubcommands(stub.calls);
98+
assert.equal(submit?.[0], "submit");
99+
assert.isFalse(submit?.includes("--wait"));
100+
101+
yield* withStubs(awaitCliNotarization(content.submissionFile), stub);
102+
assert.deepEqual(notarySubcommands(stub.calls)[1]?.slice(0, 2), ["wait", "new-id"]);
103+
}).pipe(Effect.scoped),
104+
);
105+
106+
it.effect("fails the gate unless Apple accepted the submission", () =>
107+
Effect.gen(function* () {
108+
const fs = yield* FileSystem.FileSystem;
109+
const cases: ReadonlyArray<{
110+
readonly name: string;
111+
readonly wait: NotaryReply;
112+
readonly submitted?: boolean;
113+
readonly env?: Record<string, string>;
114+
readonly error: string | undefined;
115+
readonly fetchesLog?: boolean;
116+
}> = [
117+
{
118+
name: "invalid",
119+
wait: { exitCode: 0, stdout: '{"id":"sub","status":"Invalid"}' },
120+
error: "CliArchiveNotarizationRejectedError",
121+
fetchesLog: true,
122+
},
123+
{
124+
name: "rejected with a non-zero exit",
125+
wait: { exitCode: 1, stdout: '{"id":"sub","status":"Rejected"}' },
126+
error: "CliArchiveNotarizationRejectedError",
127+
fetchesLog: true,
128+
},
129+
{
130+
name: "notarytool failed",
131+
wait: { exitCode: 69 },
132+
error: "CliArchiveCommandFailedError",
133+
},
134+
{
135+
name: "no status",
136+
wait: { exitCode: 0, stdout: '{"id":"sub"}' },
137+
error: "CliArchiveNotarizationRejectedError",
138+
},
139+
{
140+
name: "accepted with a non-zero exit",
141+
wait: { exitCode: 1, stdout: '{"id":"sub","status":"Accepted"}' },
142+
error: "CliArchiveCommandFailedError",
143+
},
144+
{
145+
name: "submission missing",
146+
wait: { exitCode: 0, stdout: '{"id":"sub","status":"Accepted"}' },
147+
submitted: false,
148+
error: "CliArchiveInputMissingError",
149+
},
150+
{
151+
name: "submission without credentials",
152+
wait: { exitCode: 0, stdout: '{"id":"sub","status":"Accepted"}' },
153+
env: { T3CODE_CLI_MAC_SIGN_IDENTITY: signedEnv.T3CODE_CLI_MAC_SIGN_IDENTITY },
154+
error: "CliArchiveInputMissingError",
155+
},
156+
{
157+
name: "notarization not configured",
158+
wait: { exitCode: 0 },
159+
submitted: false,
160+
env: {},
161+
error: undefined,
162+
},
163+
];
164+
for (const testCase of cases) {
165+
const content = yield* makeContent();
166+
if (testCase.submitted !== false) yield* fs.writeFileString(content.submissionFile, "sub");
167+
const stub = stubSpawner(() => testCase.wait);
168+
const exit = yield* withStubs(
169+
awaitCliNotarization(content.submissionFile),
170+
stub,
171+
testCase.env,
172+
).pipe(Effect.flip, Effect.option);
173+
assert.equal(Option.getOrUndefined(exit)?._tag, testCase.error, testCase.name);
174+
assert.equal(
175+
notarySubcommands(stub.calls).some((argv) => argv[0] === "log"),
176+
testCase.fetchesLog ?? false,
177+
testCase.name,
178+
);
179+
}
180+
}).pipe(Effect.scoped),
181+
);
182+
183+
it.effect("fails a standalone build whose waited submission is not Accepted", () =>
184+
Effect.gen(function* () {
185+
const content = yield* makeContent();
186+
const stub = stubSpawner(() => ({ exitCode: 0, stdout: '{"id":"sub","status":"Invalid"}' }));
187+
const error = yield* withStubs(
188+
signMacArchiveContents({
189+
repoRoot: content.root,
190+
contentDir: content.contentDir,
191+
executablePath: content.executablePath,
192+
notarySubmissionFile: Option.none(),
193+
}),
194+
stub,
195+
).pipe(Effect.flip);
196+
assert.equal(error._tag, "CliArchiveNotarizationRejectedError");
197+
assert.isTrue(notarySubcommands(stub.calls)[0]?.includes("--wait"));
198+
}).pipe(Effect.scoped),
199+
);
200+
});

0 commit comments

Comments
 (0)