Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Stage macOS signing credentials only for packaging (#5696)
Nick Gomeze9fb005f3c61
diff --git a/.github/scripts/release-cascade-shape.test.mjs b/.github/scripts/release-cascade-shape.test.mjsindex 61fe28d2a..b3c785403 100644--- a/.github/scripts/release-cascade-shape.test.mjs+++ b/.github/scripts/release-cascade-shape.test.mjs@@ -1149,6 +1149,32 @@ describe('every release-pipeline post prefers the releases webhook', () => {});});+const macPackagingJobs = [+ {+ label: 'desktop-release.yml#build-macos',+ steps: parse(desktopRelease).jobs['build-macos'].steps,+ bundle: 'Build desktop main/preload/renderer',+ packager: 'Build + sign + notarize DMG/ZIP',+ },+ {+ label: 'desktop-build.yml#build-macos-dmg',+ steps: parse(read('desktop-build.yml')).jobs['build-macos-dmg'].steps,+ bundle: 'Build electron-vite bundles',+ packager: 'Package DMG (${{ steps.signmode.outputs.mode }})',+ },+];+const macStepIndex = (job, name) => {+ const at = job.steps.findIndex((step) => step.name === name);+ if (at === -1) throw new Error(`${job.label} has no step named ${name}`);+ return at;+};+const macStepsBeforeSigning = (job) => [+ 'Force-install darwin keyring prebuilds for universal merge',+ 'Stage @parcel/watcher for the bundled CLI',+ job.bundle,+ 'Validate variant provisioning profile',+];+describe('macOS signing stays on the workflow-staged keychain', () => {const desktopBuild = read('desktop-build.yml');const PREPARE = 'Prepare signing keychain (CSC_KEYCHAIN)';@@ -1189,14 +1215,18 @@ describe('macOS signing stays on the workflow-staged keychain', () => {}});- test('the staging step runs before the packager in both workflows', () => {- for (const [source, packager] of [- [desktopRelease, 'Build + sign + notarize DMG/ZIP'],- [desktopBuild, 'Package DMG ('],- ]) {- const names = stepNames(source);- expect(indexOfStep(names, PREPARE)).toBeGreaterThan(-1);- expect(indexOfStep(names, PREPARE)).toBeLessThan(indexOfStep(names, packager));+ test('the staging step runs after the unsigned build steps, just before the packager, in both workflows', () => {+ for (const job of macPackagingJobs) {+ const prepare = macStepIndex(job, PREPARE);+ for (const name of macStepsBeforeSigning(job)) {+ expect(prepare, `${job.label}: ${PREPARE} must follow ${name}`).toBeGreaterThan(+ macStepIndex(job, name),+ );+ }+ expect(+ job.steps.slice(prepare + 1, macStepIndex(job, job.packager)).map((step) => step.name),+ `${job.label}: only the key materialization may sit between ${PREPARE} and the packager`,+ ).toEqual(['Materialize App Store Connect API key']);}});@@ -1213,6 +1243,59 @@ describe('macOS signing stays on the workflow-staged keychain', () => {expect(teardown).toBeGreaterThan(indexOfStep(names, 'Build + sign + notarize DMG/ZIP'));expect(teardown).toBeLessThan(indexOfStep(names, 'Smoke the packaged DMG'));});++ test('both jobs tear the keychain down right after the key removal, even on failure', () => {+ for (const job of macPackagingJobs) {+ const teardown = macStepIndex(job, 'Remove signing keychain');+ expect(+ teardown,+ `${job.label}: the keychain teardown must directly follow the key removal`,+ ).toBe(macStepIndex(job, 'Remove App Store Connect API key') + 1);+ expect(job.steps[teardown].if).toBe('always()');+ }+ });+});++describe('the App Store Connect key exists on disk only for packaging', () => {+ const MATERIALIZE = 'Materialize App Store Connect API key';+ const REMOVE = 'Remove App Store Connect API key';+ const keyPath = (job) => {+ const match = /^\s*KEY_PATH="([^"]+)"$/m.exec(job.steps[macStepIndex(job, MATERIALIZE)].run);+ if (!match) throw new Error(`${job.label}: ${MATERIALIZE} no longer assigns KEY_PATH`);+ return match[1];+ };++ test('the key is materialized after the unsigned build steps, immediately before the packager', () => {+ for (const job of macPackagingJobs) {+ const materialize = macStepIndex(job, MATERIALIZE);+ for (const name of macStepsBeforeSigning(job)) {+ expect(materialize, `${job.label}: ${MATERIALIZE} must follow ${name}`).toBeGreaterThan(+ macStepIndex(job, name),+ );+ }+ expect(materialize, `${job.label}: ${MATERIALIZE} must directly precede the packager`).toBe(+ macStepIndex(job, job.packager) - 1,+ );+ }+ });++ test('the step right after the packager removes the key at the path it was materialized to, even on failure', () => {+ for (const job of macPackagingJobs) {+ const remove = macStepIndex(job, REMOVE);+ expect(remove, `${job.label}: ${REMOVE} must directly follow the packager`).toBe(+ macStepIndex(job, job.packager) + 1,+ );+ expect(job.steps[remove].run).toContain(`rm -f "${keyPath(job)}"`);+ expect(job.steps[remove].if).toBe('always()');+ }+ });++ test('the release job removes the key before the smoke gate launches the packaged app', () => {+ const [release] = macPackagingJobs;+ expect(macStepIndex(release, REMOVE)).toBeLessThan(+ macStepIndex(release, 'Smoke the packaged DMG (FR5b)'),+ );+ });});describe('public desktop product variants stay independently buildable', () => {diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.ymlindex 11733aa2a..1c673672f 100644--- a/.github/workflows/desktop-build.yml+++ b/.github/workflows/desktop-build.yml@@ -140,6 +140,49 @@ jobs:echo "::notice::CSC_LINK absent — building unsigned DMG. Artifact will be labeled 'unsigned'."fi+ # Step A: vite/main/preload bundles via electron-vite. Always identical+ # for signed and unsigned modes.+ - name: Build electron-vite bundles+ working-directory: packages/desktop+ run: pnpm run build:desktop++ # Force-install both darwin-arm64 and darwin-x64 prebuilt binaries for+ # @napi-rs/keyring before electron-builder's universal merge runs. pnpm+ # under workspace conditions only installs the host-arch optionalDependency+ # (cpu constraint), so the darwin-x64 binary is missing on an arm64+ # runner. @electron/universal's lipo merge then either errors or hangs+ # waiting for x64 inputs that don't exist.+ #+ # NOTE: electron-builder.yml is currently arm64-only (`target.arch:+ # [arm64]`), so this step is effectively a no-op for the smoke build.+ # Kept in place because (a) it's idempotent and adds <1s, (b) it+ # unblocks a future flip to universal target without another mirror+ # cycle. Documented for the next reader who'd otherwise wonder why.+ - name: Force-install darwin keyring prebuilds for universal merge+ working-directory: packages/desktop+ run: node scripts/prepare-universal.mjs++ # Stage @parcel/watcher onto the bundled CLI's module path. This workflow+ # invokes electron-builder directly (not the build:mac npm script, which+ # DOES run this), so the step must be explicit here or the smoke/QA DMG+ # ships without @parcel/watcher on the CLI path and the server degrades to+ # chokidar (#760).+ - name: Stage @parcel/watcher for the bundled CLI+ working-directory: packages/desktop+ run: node scripts/stage-parcel-watcher.mjs++ - name: Validate variant provisioning profile+ if: steps.signmode.outputs.mode == 'signed' && env.OK_DESKTOP_VARIANT != 'stable'+ working-directory: packages/desktop+ run: |+ set -euo pipefail+ PROFILE_PATH="build/embedded.${OK_DESKTOP_VARIANT}.provisionprofile"+ if [[ ! -f "$PROFILE_PATH" ]]; then+ echo "::error::The committed ${OK_DESKTOP_VARIANT} Developer ID provisioning profile is missing."+ exit 1+ fi+ security cms -D -i "$PROFILE_PATH" >/dev/null+# Twin of the step in desktop-release.yml; keep them in lockstep. Stage# the Developer ID cert in a keychain this job owns and hand it to# electron-builder via CSC_KEYCHAIN instead of letting it build one from@@ -262,49 +305,6 @@ jobs:echo "APPLE_API_KEY=$KEY_PATH" >> "$GITHUB_ENV"echo "::notice::APPLE_API_KEY materialized to $KEY_PATH"- # Step A: vite/main/preload bundles via electron-vite. Always identical- # for signed and unsigned modes.- - name: Build electron-vite bundles- working-directory: packages/desktop- run: pnpm run build:desktop-- # Force-install both darwin-arm64 and darwin-x64 prebuilt binaries for- # @napi-rs/keyring before electron-builder's universal merge runs. pnpm- # under workspace conditions only installs the host-arch optionalDependency- # (cpu constraint), so the darwin-x64 binary is missing on an arm64- # runner. @electron/universal's lipo merge then either errors or hangs- # waiting for x64 inputs that don't exist.- #- # NOTE: electron-builder.yml is currently arm64-only (`target.arch:- # [arm64]`), so this step is effectively a no-op for the smoke build.- # Kept in place because (a) it's idempotent and adds <1s, (b) it- # unblocks a future flip to universal target without another mirror- # cycle. Documented for the next reader who'd otherwise wonder why.- - name: Force-install darwin keyring prebuilds for universal merge- working-directory: packages/desktop- run: node scripts/prepare-universal.mjs-- # Stage @parcel/watcher onto the bundled CLI's module path. This workflow- # invokes electron-builder directly (not the build:mac npm script, which- # DOES run this), so the step must be explicit here or the smoke/QA DMG- # ships without @parcel/watcher on the CLI path and the server degrades to- # chokidar (#760).- - name: Stage @parcel/watcher for the bundled CLI- working-directory: packages/desktop- run: node scripts/stage-parcel-watcher.mjs-- - name: Validate variant provisioning profile- if: steps.signmode.outputs.mode == 'signed' && env.OK_DESKTOP_VARIANT != 'stable'- working-directory: packages/desktop- run: |- set -euo pipefail- PROFILE_PATH="build/embedded.${OK_DESKTOP_VARIANT}.provisionprofile"- if [[ ! -f "$PROFILE_PATH" ]]; then- echo "::error::The committed ${OK_DESKTOP_VARIANT} Developer ID provisioning profile is missing."- exit 1- fi- security cms -D -i "$PROFILE_PATH" >/dev/null-# Step B: package via electron-builder. Kept as a separate runner step# from step A (rather than chained via && in a single shell). The split# was originally forced by a packaging bug in the previous script runner:@@ -344,6 +344,17 @@ jobs:pnpm exec node "$GITHUB_WORKSPACE/.github/scripts/package-desktop.mjs" --mac --publish neverfi+ - name: Remove App Store Connect API key+ if: always()+ run: rm -f "$RUNNER_TEMP/AuthKey.p8"++ - name: Remove signing keychain+ if: always()+ run: |+ if [[ -n "${CSC_KEYCHAIN:-}" ]]; then+ security delete-keychain "$CSC_KEYCHAIN" || true+ fi+# Twin of desktop-release.yml's "Attest the signed macOS app": with# CSC_KEYCHAIN, a missing identity is a warning and an ad-hoc-signed app# rather than electron-builder's own hard failure, so signed mode proves@@ -398,13 +409,3 @@ jobs:packages/desktop/dist-desktop/*-mac.ymlretention-days: 14if-no-files-found: error-- # Hosted runners are ephemeral, so this is hygiene rather than a- # security boundary. Runs after the upload so a late failure still- # leaves diagnostics.- - name: Remove signing keychain- if: always()- run: |- if [[ -n "${CSC_KEYCHAIN:-}" ]]; then- security delete-keychain "$CSC_KEYCHAIN" || true- fidiff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.ymlindex 1159a74c1..dbe5a74bb 100644--- a/.github/workflows/desktop-release.yml+++ b/.github/workflows/desktop-release.yml@@ -611,6 +611,41 @@ jobs:exit 1fi+ # Force-install both darwin-arm64 and darwin-x64 prebuilt binaries for+ # @napi-rs/keyring before electron-builder's universal merge runs. pnpm+ # under workspace conditions only installs the host-arch optionalDependency+ # (cpu constraint), so the darwin-x64 binary is missing on an arm64+ # runner. @electron/universal's lipo merge then either errors or hangs+ # waiting for x64 inputs that don't exist.+ - name: Force-install darwin keyring prebuilds for universal merge+ working-directory: packages/desktop+ run: node scripts/prepare-universal.mjs++ # Stage @parcel/watcher onto the bundled CLI's module path. This workflow+ # invokes electron-builder directly (not the build:mac npm script, which+ # DOES run this), so the step must be explicit here or the published DMG+ # ships without @parcel/watcher on the CLI path and the server degrades to+ # chokidar (#760).+ - name: Stage @parcel/watcher for the bundled CLI+ working-directory: packages/desktop+ run: node scripts/stage-parcel-watcher.mjs++ - name: Build desktop main/preload/renderer+ working-directory: packages/desktop+ run: pnpm run build:desktop++ - name: Validate variant provisioning profile+ if: steps.channel.outputs.variant == 'beta'+ working-directory: packages/desktop+ run: |+ set -euo pipefail+ PROFILE_PATH="build/embedded.${OK_DESKTOP_VARIANT}.provisionprofile"+ if [[ ! -f "$PROFILE_PATH" ]]; then+ echo "::error::The committed ${OK_DESKTOP_VARIANT} Developer ID provisioning profile is missing."+ exit 1+ fi+ security cms -D -i "$PROFILE_PATH" >/dev/null+# Stage the Developer ID cert in a keychain this job owns and hand it to# electron-builder via CSC_KEYCHAIN, instead of letting electron-builder# build one from CSC_LINK. electron-builder <= 26.16.0 authenticates its@@ -751,41 +786,6 @@ jobs:echo "APPLE_API_KEY=$KEY_PATH" >> "$GITHUB_ENV"echo "::notice::APPLE_API_KEY materialized to $KEY_PATH"- # Force-install both darwin-arm64 and darwin-x64 prebuilt binaries for- # @napi-rs/keyring before electron-builder's universal merge runs. pnpm- # under workspace conditions only installs the host-arch optionalDependency- # (cpu constraint), so the darwin-x64 binary is missing on an arm64- # runner. @electron/universal's lipo merge then either errors or hangs- # waiting for x64 inputs that don't exist.- - name: Force-install darwin keyring prebuilds for universal merge- working-directory: packages/desktop- run: node scripts/prepare-universal.mjs-- # Stage @parcel/watcher onto the bundled CLI's module path. This workflow- # invokes electron-builder directly (not the build:mac npm script, which- # DOES run this), so the step must be explicit here or the published DMG- # ships without @parcel/watcher on the CLI path and the server degrades to- # chokidar (#760).- - name: Stage @parcel/watcher for the bundled CLI- working-directory: packages/desktop- run: node scripts/stage-parcel-watcher.mjs-- - name: Build desktop main/preload/renderer- working-directory: packages/desktop- run: pnpm run build:desktop-- - name: Validate variant provisioning profile- if: steps.channel.outputs.variant == 'beta'- working-directory: packages/desktop- run: |- set -euo pipefail- PROFILE_PATH="build/embedded.${OK_DESKTOP_VARIANT}.provisionprofile"- if [[ ! -f "$PROFILE_PATH" ]]; then- echo "::error::The committed ${OK_DESKTOP_VARIANT} Developer ID provisioning profile is missing."- exit 1- fi- security cms -D -i "$PROFILE_PATH" >/dev/null-- name: Build + sign + notarize DMG/ZIP# electron-builder signs with the identity in CSC_KEYCHAIN (pushed# into $GITHUB_ENV by the "Prepare signing keychain" step). CSC_LINK@@ -866,8 +866,12 @@ jobs:echo "::notice::Retry wrapper materialized from workflow SHA ${GITHUB_WORKFLOW_SHA}."node "$WRAPPER" --label "electron-builder (macOS)" --max-attempts 3 --deadline-epoch-ms "$PACKAGING_DEADLINE_EPOCH_MS" --attempt-timeout "30m" --retry-warning "A macOS packaging retry can create a duplicate Apple notarization submission; up to 3 attempts bound this to at most 2 duplicates." --shell -- "$PKG_CMD"- # Placed HERE, not at the end of the job (where desktop-build.yml keeps- # its twin): release-cascade-shape.test.mjs forbids `if: always()` on any+ - name: Remove App Store Connect API key+ if: always()+ run: rm -f "$RUNNER_TEMP/AuthKey.p8"++ # Placed HERE, not at the end of the job:+ # release-cascade-shape.test.mjs forbids `if: always()` on any# step from the DMG smoke gate onward, and nothing after packaging needs# the key (notarize + staple run inside afterSign.mjs). Tearing down# before the smoke also keeps the private key out of reach of the