mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
* Finish the Nightly session in the app's exit hook On macOS every quit (Cmd+Q, the close button, File > Quit, app.quit) leaves through craft::quit, which sends -[NSApplication terminate:]. winit's applicationWillTerminate: delivers LoopExiting, eframe runs the app's on_exit, and AppKit then ends the process, so eframe::run_native never returns there and the controlled-return code after it (the Nightly session finish) never ran: every Mac Nightly start reported the previous session as unclean. Services gets an at_exit hook that on_exit runs once, last. The desktop app finishes the shared Nightly session there, and again after run_native for the paths that create no window (renderer failure), where the second call is a no-op. * Add the Apple-silicon Nightly build, signing and verification scripts packaging/macos/nightly.sh compiles the GUI-only PhotoCraft Nightly.app for aarch64 with no signing material (it refuses any) and writes the unsigned photocraft-<version>-macos-aarch64-nightly.zip: the nightly-common source and identity checks, nightly_plist.py's Info.plist, the Nightly icon and notices, no CLI, DMG or document types, zipped without xattrs. It no longer runs the bundle before signing. packaging/macos/nightly-sign.sh is the trusted step the shared signer calls (--arch aarch64 --input <unsigned zip> --output <final zip>). It requires all six release secrets, imports the Developer ID with import-cert.sh into a private keychain it deletes on exit, signs inside-out with the hardened runtime, timestamp and entitlements, notarizes with notarytool, staples the ticket into the bundle, and checks the final archive as the Launcher unpacks it (signature, team, ticket, Gatekeeper) before writing it without replacing anything. It never compiles or runs the payload. packaging/macos/nightly-verify.sh runs in a job without secrets (it refuses any): the same archive checks, then the bundle's --version with an empty environment, for the signed feed artifact or the unsigned compile output. nightly-common.sh splits the compile from the version query; Linux keeps both. The new suite runs the scripts against stand-in Apple tools. * Build the unsigned macOS Nightly in pull-request CI A hosted macos-15 job, with no secrets or environment, builds the aarch64 Nightly bundle with packaging/macos/nightly.sh when a pull request changes the Mac Nightly packaging or flavor, and checks it with nightly-verify.sh --expect unsigned, including the bundle's version. * Cap the failure-only notarization log in nightly-sign.sh The shared signer bounds a step's output at 256 KiB; notarytool's log on a rejected submission is the one large output, now cut at 128 KiB. * Address review: macOS-only exit hook, clean-tree recheck, wider refusals - The Nightly exit hook is installed only on macOS; Linux and Windows keep finishing the session after run_native returns. - nightly_build_gui checks the tree is still clean after --version (Linux). - nightly_refuse_signing_env also refuses the Windows, Azure and Linux signing names release.yml passes. - nightly-sign.sh drops the single spctl run before the retried final check. - nightly-macos.yml also runs for Cargo.toml, Cargo.lock and the text and ui-egui build scripts. * List the macOS Nightly signing tests as tests for Sonar packaging/macos/nightly_sign_tests.py is a fixture runner like the other nightly suites; without this Sonar counts it as production code. * Run the macOS Nightly PR build only with the full-ci label macOS runners are shared with release builds: no path filters, and a pull request runs the job only when it carries full-ci (a labeled event only when the added label is full-ci). ci.yml's concurrency pattern keeps other labels from running or cancelling a run. workflow_dispatch stays. * Keep the unsigned macOS Nightly archive as a short-lived artifact Seven-day retention, unsigned zip only, no secrets. It lets keyless signer tests and hand testing use the exact verified build. * Keep unlabelled events out of the macOS build's concurrency group A push to a full-ci PR and the label event arrive together; the event that would be skipped was sharing the group and cancelling the real build. * Stop the macOS Nightly scripts' --help at their header comment * Answer the Launcher's profile-form version query before startup (#16559) `PhotoCraft --launch-profile nightly-v1 --profile-root <dir> --version`, the shared producer's smoke, was refused by the strict launch-profile parser (no `--`), and the refusal opens a native dialog on macOS, which never returns on a headless runner: the hosted run did not exit in 180 s. A Nightly build now treats exactly the selector/root pair followed by `--version` or `-V` as a version query: the same line as plain `--version`, exit 0, before root validation, process identity, IPC or any window. Only parse()'s lexical checks apply; every other refusal is unchanged and `-- --version` stays a file name. nightly-verify.sh checks both forms, each within 15 seconds and with nothing on standard error, so the PR's Mac build covers the smoke. * Harden the Mac Nightly signing helpers (review of #16559) - nightly_publish_archive runs python3 -I: nightly-sign.sh calls it with the signing secrets loaded, so no module from the working directory or user site may be imported. - nightly-sign.sh and nightly-verify.sh list the archive's entries before unpacking (python3 -I, zipfile) and refuse absolute paths, `..`, empty or backslash components, entries outside PhotoCraft Nightly.app, links and special files. The check after unpacking stays. - The signature check matches the Identifier line literally (grep -F).
111 lines
6.0 KiB
Bash
111 lines
6.0 KiB
Bash
# shellcheck shell=bash
|
|
# Shared checks for the Apple-silicon Nightly scripts (nightly.sh, nightly-sign.sh, nightly-verify.sh).
|
|
# Stable packaging (package.sh, verify.sh) does not source this file. The text checks take tool output
|
|
# as arguments, so packaging/macos/nightly_sign_tests.py runs them without macOS.
|
|
|
|
MAC_NIGHTLY_APP='PhotoCraft Nightly.app'
|
|
MAC_NIGHTLY_ID='ai.storyteller.photocraft.nightly'
|
|
# The release environment's names, as stable release.yml passes them (packaging/macos/import-cert.sh).
|
|
MAC_NIGHTLY_SECRETS=(APPLE_CERTIFICATE APPLE_CERTIFICATE_PASSWORD KEYCHAIN_PASSWORD APPLE_ID APPLE_PASSWORD APPLE_TEAM_ID)
|
|
|
|
mac_nightly_die() { printf 'error: %s\n' "$*" >&2; exit 2; }
|
|
|
|
# The exact prepared version from the feed asset name, or failure.
|
|
mac_nightly_version_from_asset() {
|
|
local name="$1" version
|
|
[[ "$name" =~ ^photocraft-(.+)-macos-aarch64-nightly\.zip$ ]] || return 1
|
|
version="${BASH_REMATCH[1]}"
|
|
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-nightly\.[0-9]{8}\.[0-9]+\.[0-9]+\.g[0-9a-f]{12}$ ]] || return 1
|
|
printf '%s\n' "$version"
|
|
}
|
|
|
|
# Every signing and notarization value is set, and the team is one Apple team ID. No ad-hoc fallback.
|
|
mac_nightly_require_secrets() {
|
|
local name
|
|
for name in "${MAC_NIGHTLY_SECRETS[@]}"; do
|
|
[[ -n "${!name:-}" ]] || mac_nightly_die "$name is not set: Nightly signing and notarization are required, with no ad-hoc fallback"
|
|
done
|
|
[[ "$APPLE_TEAM_ID" =~ ^[A-Z0-9]{10}$ ]] || mac_nightly_die 'APPLE_TEAM_ID is not an Apple team ID'
|
|
if [[ -n "${NIGHTLY_APPLE_TEAM_ID:-}" && "$NIGHTLY_APPLE_TEAM_ID" != "$APPLE_TEAM_ID" ]]; then
|
|
mac_nightly_die 'the signing team differs from the reviewed Nightly team (NIGHTLY_APPLE_TEAM_ID)'
|
|
fi
|
|
}
|
|
|
|
# One line of `security find-identity -v -p codesigning`: the identity is a Developer ID Application of the team.
|
|
mac_nightly_identity_is_team() {
|
|
local line="$1" identity="$2" team="$3"
|
|
[[ "$line" == *" $identity "* && "$line" == *'"Developer ID Application: '*" ($team)\""* ]]
|
|
}
|
|
|
|
# `codesign -d --verbose=2` of the signed bundle: the Nightly identifier, a Developer ID Application of the
|
|
# team, a secure timestamp and the hardened runtime (the checks of verify.sh, made strict).
|
|
mac_nightly_check_signature() {
|
|
local details="$1" team="$2" ok=0
|
|
grep -Fqx "Identifier=$MAC_NIGHTLY_ID" <<<"$details" || { echo "error: the bundle is not signed as $MAC_NIGHTLY_ID" >&2; ok=1; }
|
|
grep -q '^Authority=Developer ID Application:' <<<"$details" || { echo 'error: not signed with a Developer ID Application identity' >&2; ok=1; }
|
|
grep -qx "TeamIdentifier=$team" <<<"$details" || { echo 'error: signed by a different team' >&2; ok=1; }
|
|
grep -q '^Timestamp=' <<<"$details" || { echo 'error: the signature has no secure timestamp' >&2; ok=1; }
|
|
grep -Eq '^CodeDirectory .*flags=0x[0-9a-f]+\([^)]*runtime' <<<"$details" || { echo 'error: not signed with the hardened runtime' >&2; ok=1; }
|
|
return "$ok"
|
|
}
|
|
|
|
# `spctl --assess --type execute -vv`: Gatekeeper accepts the bundle as notarized.
|
|
mac_nightly_check_assessment() {
|
|
grep -q 'accepted' <<<"$1" && grep -qx 'source=Notarized Developer ID' <<<"$1"
|
|
}
|
|
|
|
# Before anything is unpacked: every ZIP entry is a regular file or directory inside the one Nightly
|
|
# bundle, with no absolute path, `..`, backslash or empty component, and no link or special file.
|
|
mac_nightly_check_zip_entries() {
|
|
python3 -I - "$1" "$MAC_NIGHTLY_APP" <<'PY' || mac_nightly_die 'the archive has an entry outside the bundle, a link or a special file'
|
|
import stat, sys, zipfile
|
|
archive, app = sys.argv[1:]
|
|
with zipfile.ZipFile(archive) as z:
|
|
for info in z.infolist():
|
|
name = info.filename
|
|
parts = name.rstrip("/").split("/")
|
|
mode = info.external_attr >> 16
|
|
if (name.startswith("/") or "\\" in name or "\0" in name or parts[0] != app
|
|
or any(part in ("", ".", "..") for part in parts)
|
|
or stat.S_IFMT(mode) not in (0, stat.S_IFREG, stat.S_IFDIR)):
|
|
sys.exit(f"refused entry: {name!r}")
|
|
PY
|
|
}
|
|
|
|
# An unpacked payload directory holds exactly the GUI-only Nightly bundle: one thin arm64 PhotoCraft
|
|
# executable, the Nightly identity and the exact version (no numeric fallback), no CLI, no links or special
|
|
# files, no document or URL types.
|
|
mac_nightly_check_bundle() {
|
|
local payload="$1" version="$2" app entries plist key value
|
|
app="$payload/$MAC_NIGHTLY_APP"
|
|
entries="$(ls -A "$payload")"
|
|
[[ "$entries" == "$MAC_NIGHTLY_APP" && -d "$app" && ! -L "$app" ]] || mac_nightly_die "the archive must hold exactly $MAC_NIGHTLY_APP"
|
|
[[ -z "$(find "$payload" ! -type f ! -type d -print -quit)" ]] || mac_nightly_die 'the bundle contains links or special files'
|
|
[[ "$(ls -A "$app/Contents/MacOS")" == PhotoCraft ]] || mac_nightly_die 'Contents/MacOS must hold only the PhotoCraft GUI (no CLI)'
|
|
[[ -f "$app/Contents/MacOS/PhotoCraft" && -x "$app/Contents/MacOS/PhotoCraft" ]] || mac_nightly_die 'missing executable GUI'
|
|
[[ "$(lipo -archs "$app/Contents/MacOS/PhotoCraft")" == arm64 ]] || mac_nightly_die 'the GUI must be thin arm64'
|
|
plist="$app/Contents/Info.plist"
|
|
for key in CFBundleIdentifier CFBundleExecutable PhotoCraftVersion; do
|
|
value="$(plutil -extract "$key" raw -o - "$plist")" || mac_nightly_die "Info.plist has no $key"
|
|
case "$key" in
|
|
CFBundleIdentifier) [[ "$value" == "$MAC_NIGHTLY_ID" ]] ;;
|
|
CFBundleExecutable) [[ "$value" == PhotoCraft ]] ;;
|
|
PhotoCraftVersion) [[ "$value" == "$version" ]] ;;
|
|
esac || mac_nightly_die "Info.plist $key is not the prepared Nightly identity"
|
|
done
|
|
for key in CFBundleDocumentTypes CFBundleURLTypes UTExportedTypeDeclarations UTImportedTypeDeclarations; do
|
|
if plutil -extract "$key" xml1 -o - "$plist" >/dev/null 2>&1; then mac_nightly_die "Nightly declares $key"; fi
|
|
done
|
|
}
|
|
|
|
# `stapler validate` asks Apple's CloudKit service, which sometimes drops the connection (error 68)
|
|
# though the ticket is there (verify.sh).
|
|
mac_nightly_validate_staple() {
|
|
local target="$1" attempt
|
|
for attempt in 1 2 3 4 5; do
|
|
xcrun stapler validate "$target" && return 0
|
|
[[ "$attempt" = 5 ]] || sleep $((attempt * 20))
|
|
done
|
|
return 1
|
|
}
|