GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(release): macOS CLI notarization no longer blocks the desktop bu… · AndryHTC/t3code@423254e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • release-desktop.yml
  • scripts
    • build-cli-archive.test.ts
    • build-cli-archive.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: .github/workflows/release-desktop.yml
+53-6Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ jobs:
408408
run: command -v patchelf || { sudo apt-get update && sudo apt-get install -y patchelf; }
409409

410410
- name: Build CLI archive
411+
id: build_cli
411412
if: inputs.cli_archive
412413
shell: bash
413414
env:
@@ -425,25 +426,38 @@ jobs:
425426
AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
426427
run: |
427428
set -euo pipefail
428-
if [[ "${{ inputs.platform }}" == "mac" && -n "${APPLE_API_KEY:-}" ]]; then
429-
key_path="$RUNNER_TEMP/AuthKey_cli_${APPLE_API_KEY_ID}.p8"
430-
printf '%s' "$APPLE_API_KEY" > "$key_path"
431-
export APPLE_API_KEY="$key_path"
429+
extra_args=()
430+
if [[ "${{ inputs.platform }}" == "mac" ]]; then
431+
if [[ -n "${APPLE_API_KEY:-}" ]]; then
432+
key_dir="$(mktemp -d "$RUNNER_TEMP/t3-cli-notary.XXXXXXXX")"
433+
trap 'rm -rf "$key_dir"' EXIT
434+
key_path="$key_dir/AuthKey.p8"
435+
(umask 077 && printf '%s' "$APPLE_API_KEY" > "$key_path")
436+
export APPLE_API_KEY="$key_path"
437+
fi
438+
# Older release refs lack deferred notarization and still wait here.
439+
cli_help="$(node scripts/build-cli-archive.ts --help)"
440+
if [[ "$cli_help" == *--notary-submission-file* ]]; then
441+
extra_args=(--notary-submission-file "$RUNNER_TEMP/t3-cli-notary-submission")
442+
echo "deferred_notarization=true" >> "$GITHUB_OUTPUT"
443+
fi
432444
fi
433445
node scripts/build-cli-archive.ts \
434446
--platform "${{ inputs.platform }}" \
435447
--arch "${{ inputs.arch }}" \
436448
--version "${{ inputs.version }}" \
437449
--resource-monitor-dir "$RUNNER_TEMP/cli-resource-monitor" \
438-
--output-dir release-cli
450+
--output-dir release-cli \
451+
${extra_args[@]+"${extra_args[@]}"}
439452
440453
- name: Smoke-test CLI archive
441454
if: inputs.cli_archive && inputs.verify_runner == ''
442455
shell: bash
443456
run: node scripts/smoke-cli-archive.ts --archive release-cli/* --expect-version "${{ inputs.version }}"
444457

458+
# macOS uploads its archive after "Await CLI notarization" instead.
445459
- name: Upload CLI archive
446-
if: inputs.cli_archive
460+
if: inputs.cli_archive && inputs.platform != 'mac'
447461
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
448462
with:
449463
name: cli-${{ inputs.platform }}-${{ inputs.arch }}
@@ -620,6 +634,39 @@ jobs:
620634
621635
vp run dist:desktop:artifact "${args[@]}"
622636
637+
# The CLI was submitted without waiting so Apple reviews it while the
638+
# desktop builds. Notarization does not change the archive bytes, but
639+
# nothing uploads them, so nothing publishes them, until Apple accepts.
640+
# With signing configured, a missing submission id fails this step.
641+
- name: Await CLI notarization
642+
if: inputs.cli_archive && inputs.platform == 'mac' && steps.build_cli.outputs.deferred_notarization == 'true'
643+
shell: bash
644+
env:
645+
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
646+
APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
647+
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
648+
run: |
649+
set -euo pipefail
650+
if [[ -n "${APPLE_API_KEY:-}" ]]; then
651+
key_dir="$(mktemp -d "$RUNNER_TEMP/t3-cli-notary.XXXXXXXX")"
652+
trap 'rm -rf "$key_dir"' EXIT
653+
key_path="$key_dir/AuthKey.p8"
654+
(umask 077 && printf '%s' "$APPLE_API_KEY" > "$key_path")
655+
export APPLE_API_KEY="$key_path"
656+
fi
657+
node scripts/build-cli-archive.ts await-notarization \
658+
--submission-file "$RUNNER_TEMP/t3-cli-notary-submission"
659+
660+
- name: Upload notarized CLI archive
661+
if: inputs.cli_archive && inputs.platform == 'mac'
662+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
663+
with:
664+
name: cli-${{ inputs.platform }}-${{ inputs.arch }}
665+
path: release-cli/*
666+
if-no-files-found: error
667+
# The archive is already gzip or zip; deflating it again saves under 2%.
668+
compression-level: 0
669+
623670
# Warm installs only touch the store index, so new content means a fetch.
624671
- name: Check staged install cache for new content
625672
id: stage_pnpm_changed
Collapse file

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

Copy file name to clipboard
+216Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
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+
// Apple documents id and path for an unwaited submit; a pending status must not fail it.
80+
for (const submitted of [
81+
'{"id":"new-id","message":"Successfully uploaded file","path":"t3.zip"}',
82+
'{"id":"new-id","status":"In Progress"}',
83+
]) {
84+
const content = yield* makeContent();
85+
yield* fs.writeFileString(content.submissionFile, "stale-id");
86+
const stub = stubSpawner((subcommand) =>
87+
subcommand === "submit"
88+
? { exitCode: 0, stdout: submitted }
89+
: { exitCode: 0, stdout: '{"id":"new-id","status":"Accepted"}' },
90+
);
91+
92+
yield* withStubs(
93+
signMacArchiveContents({
94+
repoRoot: content.root,
95+
contentDir: content.contentDir,
96+
executablePath: content.executablePath,
97+
notarySubmissionFile: Option.some(content.submissionFile),
98+
}),
99+
stub,
100+
);
101+
assert.equal(yield* fs.readFileString(content.submissionFile), "new-id");
102+
const [submit] = notarySubcommands(stub.calls);
103+
assert.equal(submit?.[0], "submit");
104+
assert.isFalse(submit?.includes("--wait"));
105+
106+
yield* withStubs(awaitCliNotarization(content.submissionFile), stub);
107+
assert.deepEqual(notarySubcommands(stub.calls)[1]?.slice(0, 2), ["wait", "new-id"]);
108+
}
109+
}).pipe(Effect.scoped),
110+
);
111+
112+
it.effect("fails the gate unless Apple accepted the submission", () =>
113+
Effect.gen(function* () {
114+
const fs = yield* FileSystem.FileSystem;
115+
const cases: ReadonlyArray<{
116+
readonly name: string;
117+
readonly wait: NotaryReply;
118+
readonly submitted?: boolean;
119+
readonly env?: Record<string, string>;
120+
readonly error: string | undefined;
121+
readonly fetchesLog?: boolean;
122+
}> = [
123+
{
124+
name: "invalid",
125+
wait: { exitCode: 0, stdout: '{"id":"sub","status":"Invalid"}' },
126+
error: "CliArchiveNotarizationRejectedError",
127+
fetchesLog: true,
128+
},
129+
{
130+
name: "rejected with a non-zero exit",
131+
wait: { exitCode: 1, stdout: '{"id":"sub","status":"Rejected"}' },
132+
error: "CliArchiveNotarizationRejectedError",
133+
fetchesLog: true,
134+
},
135+
{
136+
name: "still in progress",
137+
wait: { exitCode: 0, stdout: '{"id":"sub","status":"In Progress"}' },
138+
error: "CliArchiveNotarizationRejectedError",
139+
},
140+
{
141+
name: "still in progress with a non-zero exit",
142+
wait: { exitCode: 1, stdout: '{"id":"sub","status":"In Progress"}' },
143+
error: "CliArchiveCommandFailedError",
144+
},
145+
{
146+
name: "notarytool failed",
147+
wait: { exitCode: 69 },
148+
error: "CliArchiveCommandFailedError",
149+
},
150+
{
151+
name: "no status",
152+
wait: { exitCode: 0, stdout: '{"id":"sub"}' },
153+
error: "CliArchiveNotarizationRejectedError",
154+
},
155+
{
156+
name: "accepted with a non-zero exit",
157+
wait: { exitCode: 1, stdout: '{"id":"sub","status":"Accepted"}' },
158+
error: "CliArchiveCommandFailedError",
159+
},
160+
{
161+
name: "submission missing",
162+
wait: { exitCode: 0, stdout: '{"id":"sub","status":"Accepted"}' },
163+
submitted: false,
164+
error: "CliArchiveInputMissingError",
165+
},
166+
{
167+
name: "submission without credentials",
168+
wait: { exitCode: 0, stdout: '{"id":"sub","status":"Accepted"}' },
169+
env: { T3CODE_CLI_MAC_SIGN_IDENTITY: signedEnv.T3CODE_CLI_MAC_SIGN_IDENTITY },
170+
error: "CliArchiveInputMissingError",
171+
},
172+
{
173+
name: "notarization not configured",
174+
wait: { exitCode: 0 },
175+
submitted: false,
176+
env: {},
177+
error: undefined,
178+
},
179+
];
180+
for (const testCase of cases) {
181+
const content = yield* makeContent();
182+
if (testCase.submitted !== false) yield* fs.writeFileString(content.submissionFile, "sub");
183+
const stub = stubSpawner(() => testCase.wait);
184+
const exit = yield* withStubs(
185+
awaitCliNotarization(content.submissionFile),
186+
stub,
187+
testCase.env,
188+
).pipe(Effect.flip, Effect.option);
189+
assert.equal(Option.getOrUndefined(exit)?._tag, testCase.error, testCase.name);
190+
assert.equal(
191+
notarySubcommands(stub.calls).some((argv) => argv[0] === "log"),
192+
testCase.fetchesLog ?? false,
193+
testCase.name,
194+
);
195+
}
196+
}).pipe(Effect.scoped),
197+
);
198+
199+
it.effect("fails a standalone build whose waited submission is not Accepted", () =>
200+
Effect.gen(function* () {
201+
const content = yield* makeContent();
202+
const stub = stubSpawner(() => ({ exitCode: 0, stdout: '{"id":"sub","status":"Invalid"}' }));
203+
const error = yield* withStubs(
204+
signMacArchiveContents({
205+
repoRoot: content.root,
206+
contentDir: content.contentDir,
207+
executablePath: content.executablePath,
208+
notarySubmissionFile: Option.none(),
209+
}),
210+
stub,
211+
).pipe(Effect.flip);
212+
assert.equal(error._tag, "CliArchiveNotarizationRejectedError");
213+
assert.isTrue(notarySubcommands(stub.calls)[0]?.includes("--wait"));
214+
}).pipe(Effect.scoped),
215+
);
216+
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.