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
2 changes: 1 addition & 1 deletion docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Base64 is encoding, so `APPLE_CERTIFICATE` remains a secret. GitHub supplies the

CI imports the identity and Apple intermediate certificate into a temporary Keychain. Notarization keys and signing handoffs use owner-only temporary files. The general build environment contains a protected file reference, and only bundling/notarization receives the relevant credentials. Cleanup restores the Keychain search list and removes temporary files and keys even after failure; runner destruction is the final boundary after forced termination.

Tauri notarizes and staples the app before producing its updater archive; the hook separately submits and staples the outer DMG. Only ticket-service network failures identified as stapler error 68 with an NSURLErrorDomain diagnostic receive bounded retries. Invalid signatures or tickets fail immediately.
Tauri notarizes and staples the app before producing its updater archive; the hook separately submits and staples the outer DMG. Only ticket-service network failures identified as stapler error 68 with an NSURLErrorDomain diagnostic receive bounded retries. Tauri does not check its own `stapler staple` result, so when the bundled app has no stapled ticket the hook rebuilds the bundle once and prints Tauri's notarization status lines. Invalid signatures or tickets, or a second unstapled app, fail immediately.

To test the full build without publishing, manually run the **Release** workflow on the reviewed source ref with `candidate_only=true`. It submits to Apple's notary service and retains the verified bundle for 30 days, but does not change release refs, deploy the gateway, create a GitHub Release or update Homebrew. The protected Environment's branch restriction still applies.

Expand Down
35 changes: 31 additions & 4 deletions scripts/release/build_desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ def clear_outputs(output_dir: Path) -> None:
(output_dir / name).unlink(missing_ok=True)


def clear_bundle(bundle_dir: Path) -> None:
# Earlier builds leave differently named DMGs and stale updater archives.
for kind in ("dmg", "macos"):
shutil.rmtree(bundle_dir / kind, ignore_errors=True)


def stapled(app: Path, *, runner: Runner, env: Mapping[str, str]) -> bool:
result = runner(["xcrun", "stapler", "validate", str(app)], env=env, check=False, capture_output=True, text=True)
return result.returncode == 0


def report_notarization(result: Any) -> None:
"""Echo Tauri's notarization status lines, which name no credentials."""
for line in f"{getattr(result, 'stdout', '') or ''}\n{getattr(result, 'stderr', '') or ''}".splitlines():
if "otariz" in line or "Stapling" in line:
print(f"desktop: tauri: {line.strip()}", flush=True)


def build_environment(environ: Mapping[str, str], rzm: Path, home: Path) -> dict[str, str]:
"""The Tauri build gets the signing key, not the publishing tokens."""
env = {
Expand Down Expand Up @@ -185,16 +203,25 @@ def build(
if prebuilt_frontend and not (desktop / "dist/index.html").is_file():
raise DesktopBuildError("prepared desktop frontend is missing; restore the verified CI frontend artifact")
bundle_dir = root / BUNDLE_DIR
# Earlier builds leave differently named DMGs and stale updater archives.
for kind in ("dmg", "macos"):
shutil.rmtree(bundle_dir / kind, ignore_errors=True)
clear_bundle(bundle_dir)
runner(tauri_command(version, updater=updater, notarize=notarize, prebuilt_frontend=prebuilt_frontend), cwd=desktop, env=clean_env, check=True)
command = tauri_command(version, updater=updater, notarize=notarize, bundle=True, prebuilt_frontend=prebuilt_frontend)
if notarize:
with credentials(env) as signing_env:
# A signer failure must not expose credentials through captured output.
try:
runner(command, cwd=desktop, env=signing_env, check=True, capture_output=True, text=True, timeout=3600)
for attempt in range(2):
result = runner(command, cwd=desktop, env=signing_env, check=True, capture_output=True, text=True, timeout=3600)
report_notarization(result)
if stapled(bundle_dir / "macos/Rhizome.app", runner=runner, env=clean_env):
break
if attempt:
raise DesktopBuildError("Rhizome.app has no stapled ticket after rebuilding; no desktop assets staged")
# Tauri ignores `xcrun stapler staple` failures (tauri-macos-sign
# 2.12), so a ticket Apple has not yet propagated leaves the app,
# DMG and updater archive unstapled. A rebuild resubmits the same app.
print("desktop: Tauri left Rhizome.app without a stapled ticket; rebuilding the bundle once", flush=True)
clear_bundle(bundle_dir)
outputs = bundle_outputs(bundle_dir, updater=updater)
notarize_dmg(outputs[DMG], runner=runner, env=signing_env)
except subprocess.SubprocessError as error:
Expand Down
33 changes: 31 additions & 2 deletions scripts/release/build_desktop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ class FakeTauri:
def __init__(self, root: Path) -> None:
self.root = root
self.calls: list[tuple[list[str], dict]] = []
self.unstapled_checks = 0

def __call__(self, command, **kwargs):
self.calls.append((list(command), kwargs))
if command[:3] == ["xcrun", "stapler", "validate"]:
code = 65 if self.unstapled_checks else 0
self.unstapled_checks = max(0, self.unstapled_checks - 1)
return subprocess.CompletedProcess(command, code, "", "")
if command[:3] == ["xcrun", "notarytool", "submit"]:
return subprocess.CompletedProcess(command, 0, '{"status":"Accepted"}', "")
if command[:3] == ["npm", "run", "tauri"]:
Expand Down Expand Up @@ -177,14 +182,38 @@ def test_signed_build_stages_stable_names_and_update_feed(self) -> None:
self.assertEqual("synthetic-password", env["TAURI_SIGNING_PRIVATE_KEY_PASSWORD"])
self.assertNotIn("GITHUB_TOKEN", env)
self.assertTrue(env["PATH"].startswith(str(self.home / ".cargo/bin")))
codesign = self.runner.commands()[2]
self.assertEqual(["xcrun", "stapler", "validate"], self.runner.commands()[2][:3])
codesign = self.runner.commands()[3]
self.assertEqual(["codesign", "--verify", "--deep", "--strict"], codesign[:4])
self.assertTrue(codesign[4].endswith("bundle/macos/Rhizome.app"))
content_check = self.runner.commands()[3]
content_check = self.runner.commands()[4]
self.assertEqual("--check-artifact", content_check[2])
self.assertTrue(content_check[1].endswith("scripts/teamkeys/release.py"))
self.assertTrue(content_check[3].endswith("Rhizome.app/Contents/MacOS/rhizome-desktop"))

def test_unstapled_app_rebuilds_the_bundle_once(self) -> None:
# Tauri ignores stapler failures, so the build checks the ticket itself.
self.runner.unstapled_checks = 1
with patch.object(build_desktop, "verify_distribution") as verify, patch.object(build_desktop, "notarize_dmg"):
self.build({**APPLE, "RZM_RELEASE_DESKTOP": "1",
"TAURI_SIGNING_PRIVATE_KEY": "synthetic-key",
"TAURI_SIGNING_PRIVATE_KEY_PASSWORD": "synthetic-password"})
commands = self.runner.commands()
self.assertEqual(2, sum(c[:3] == ["npm", "run", "tauri"] and "bundle" in c for c in commands))
self.assertEqual(2, sum(c[:3] == ["xcrun", "stapler", "validate"] for c in commands))
verify.assert_called_once()
self.assertTrue((self.output / "Rhizome-macos-arm64.dmg").is_file())

def test_app_still_unstapled_after_rebuild_stages_nothing(self) -> None:
self.runner.unstapled_checks = 2
with patch.object(build_desktop, "verify_distribution") as verify, patch.object(build_desktop, "notarize_dmg"):
with self.assertRaisesRegex(DesktopBuildError, "no stapled ticket after rebuilding"):
self.build({**APPLE, "RZM_RELEASE_DESKTOP": "1",
"TAURI_SIGNING_PRIVATE_KEY": "synthetic-key",
"TAURI_SIGNING_PRIVATE_KEY_PASSWORD": "synthetic-password"})
verify.assert_not_called()
self.assertFalse(self.output.exists() and any(self.output.iterdir()))

def test_missing_dependencies_are_installed_first(self) -> None:
(self.root / "desktop/node_modules").rmdir()
self.build({})
Expand Down
17 changes: 10 additions & 7 deletions scripts/release/evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import json
import re
import subprocess
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from pathlib import Path
from typing import Callable, Mapping, Protocol, Sequence
Expand Down Expand Up @@ -352,13 +353,15 @@ def _api(self, endpoint: str) -> object:
def associated_prs(
self, commit_shas: Sequence[str]
) -> Mapping[str, Sequence[PullRequestRecord]]:
result = {}
for sha in commit_shas:
payload = self._api(
f"repos/{self.repo_slug}/commits/{sha}/pulls"
)
result[sha] = tuple(_pr_from_rest(item) for item in payload)
return result
# Each lookup is one gh process; sequential calls took ~10 minutes for
# a release spanning 1,300 PR commits.
def lookup(sha: str) -> tuple[PullRequestRecord, ...]:
payload = self._api(f"repos/{self.repo_slug}/commits/{sha}/pulls")
return tuple(_pr_from_rest(item) for item in payload)

shas = list(commit_shas)
with ThreadPoolExecutor(max_workers=8) as pool:
return dict(zip(shas, pool.map(lookup, shas)))

def pr_commits(self, number: int) -> Sequence[str]:
payload = self._api(f"repos/{self.repo_slug}/pulls/{number}/commits")
Expand Down
Loading