@@ -187,12 +187,47 @@ jobs:
187187 printf '%s' "$APPLE_API_KEY_P8" > "$RUNNER_TEMP/appstoreconnect/AuthKey.p8"
188188 chmod 600 "$RUNNER_TEMP/appstoreconnect/AuthKey.p8"
189189
190- - name : Package, sign, and notarize
190+ - name : Import Apple signing certificate
191191 if : ${{ inputs.sign }}
192- working-directory : apps/desktop
193192 env :
194193 CSC_LINK : ${{ secrets.CSC_LINK }}
195194 CSC_KEY_PASSWORD : ${{ secrets.CSC_KEY_PASSWORD }}
195+ run : |
196+ CERTIFICATE_PATH="$RUNNER_TEMP/desktop-signing.p12"
197+ KEYCHAIN_PATH="$RUNNER_TEMP/desktop-signing.keychain-db"
198+ KEYCHAIN_PASSWORD="$(openssl rand -base64 32)"
199+
200+ printf '%s' "$CSC_LINK" | base64 --decode > "$CERTIFICATE_PATH"
201+ chmod 600 "$CERTIFICATE_PATH"
202+ security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
203+ security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
204+ security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
205+ security import "$CERTIFICATE_PATH" -k "$KEYCHAIN_PATH" -P "$CSC_KEY_PASSWORD" \
206+ -T /usr/bin/codesign -T /usr/bin/productbuild
207+ security set-key-partition-list -S apple-tool:,apple: -s \
208+ -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH" > /dev/null
209+
210+ EXISTING_KEYCHAINS=("$KEYCHAIN_PATH")
211+ while IFS= read -r EXISTING_KEYCHAIN; do
212+ EXISTING_KEYCHAIN="${EXISTING_KEYCHAIN#*\"}"
213+ EXISTING_KEYCHAIN="${EXISTING_KEYCHAIN%\"}"
214+ if [ "$EXISTING_KEYCHAIN" != "$KEYCHAIN_PATH" ]; then
215+ EXISTING_KEYCHAINS+=("$EXISTING_KEYCHAIN")
216+ fi
217+ done < <(security list-keychains -d user)
218+ security list-keychains -d user -s "${EXISTING_KEYCHAINS[@]}"
219+
220+ SIGNING_IDENTITIES="$(security find-identity -v -p codesigning "$KEYCHAIN_PATH")"
221+ if ! grep -q 'Developer ID Application' <<< "$SIGNING_IDENTITIES"; then
222+ echo '::error::The signing certificate does not contain a valid Developer ID Application identity.'
223+ exit 1
224+ fi
225+
226+ - name : Package, sign, and notarize
227+ if : ${{ inputs.sign }}
228+ working-directory : apps/desktop
229+ env :
230+ CSC_KEYCHAIN : ${{ runner.temp }}/desktop-signing.keychain-db
196231 # Absolute path — @electron/notarize reads this via Node fs, which
197232 # does not expand a leading '~'.
198233 APPLE_API_KEY : ${{ runner.temp }}/appstoreconnect/AuthKey.p8
@@ -205,6 +240,13 @@ jobs:
205240 bunx electron-builder --mac --publish never
206241 -c.productName="$PRODUCT_NAME" -c.appId="$APP_ID"
207242
243+ - name : Remove Apple signing credentials
244+ if : ${{ always() && inputs.sign }}
245+ run : |
246+ security delete-keychain "$RUNNER_TEMP/desktop-signing.keychain-db" || true
247+ rm -f "$RUNNER_TEMP/desktop-signing.p12"
248+ rm -f "$RUNNER_TEMP/appstoreconnect/AuthKey.p8"
249+
208250 # Unsigned artifact-only path: no Developer ID or notarization. The bundle
209251 # is ad-hoc signed with Hardened Runtime off for local workflow testing and
210252 # must never be published.
0 commit comments