Skip to content

Commit 891a020

Browse files
authored
fix(ci): import passwordless macOS signing certificate (#59768)
1 parent 45b53fe commit 891a020

2 files changed

Lines changed: 40 additions & 12 deletions

File tree

‎.github/workflows/release-dry-run.yml‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,23 @@ jobs:
380380
uses: ./.github/release/download
381381
with:
382382
pattern: "{build-npm,build-desktop-darwin-*}"
383+
# The certificate has no password, which apple-actions/import-codesign-certs rejects. The sign scripts look up
384+
# the identity in build.keychain, and codesign finds the key through the user search list.
383385
- name: Import certificate
384386
if: needs.plan.outputs.dry_run != 'true'
385-
uses: apple-actions/import-codesign-certs@8f3fb608891dd2244cdab3d69cd68c0d37a7fe93 # v2.0.0
386-
with:
387-
keychain: build
388-
p12-file-base64: ${{ secrets.APPLE_SIGNING_CERTIFICATE }}
389-
# The certificate has no password; the action passes this to `security import -P`.
390-
p12-password: ""
387+
run: |
388+
cert="$RUNNER_TEMP/cert.p12"
389+
keychain_password=$(openssl rand -base64 32)
390+
printf '%s' "$APPLE_SIGNING_CERTIFICATE" | base64 --decode > "$cert"
391+
security create-keychain -p "$keychain_password" build.keychain
392+
security set-keychain-settings -lut 21600 build.keychain
393+
security unlock-keychain -p "$keychain_password" build.keychain
394+
security import "$cert" -k build.keychain -P "" -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productsign
395+
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$keychain_password" build.keychain > /dev/null
396+
security list-keychains -d user -s build.keychain $(security list-keychains -d user | tr -d '"')
397+
rm -f "$cert"
398+
env:
399+
APPLE_SIGNING_CERTIFICATE: ${{ secrets.APPLE_SIGNING_CERTIFICATE }}
391400
- name: Sign CLI
392401
if: needs.plan.outputs.cli == 'true'
393402
run: bash .github/release/sign-cli-macos.sh "$RUNNER_TEMP/in/build-npm" "$RUNNER_TEMP/out"
@@ -406,6 +415,11 @@ jobs:
406415
with:
407416
name: sign-macos
408417
path: ${{ runner.temp }}/out
418+
- name: Delete keychain
419+
if: always() && needs.plan.outputs.dry_run != 'true'
420+
run: |
421+
rm -f "$RUNNER_TEMP/cert.p12"
422+
security delete-keychain build.keychain || true
409423
410424
# Signs the Windows CLI and every executable and native module of the unpacked desktop apps.
411425
sign-windows:

‎.github/workflows/release.yml‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,23 @@ jobs:
399399
uses: ./.github/release/download
400400
with:
401401
pattern: "{build-npm,build-desktop-darwin-*}"
402+
# The certificate has no password, which apple-actions/import-codesign-certs rejects. The sign scripts look up
403+
# the identity in build.keychain, and codesign finds the key through the user search list.
402404
- name: Import certificate
403405
if: needs.plan.outputs.dry_run != 'true'
404-
uses: apple-actions/import-codesign-certs@8f3fb608891dd2244cdab3d69cd68c0d37a7fe93 # v2.0.0
405-
with:
406-
keychain: build
407-
p12-file-base64: ${{ secrets.APPLE_SIGNING_CERTIFICATE }}
408-
# The certificate has no password; the action passes this to `security import -P`.
409-
p12-password: ""
406+
run: |
407+
cert="$RUNNER_TEMP/cert.p12"
408+
keychain_password=$(openssl rand -base64 32)
409+
printf '%s' "$APPLE_SIGNING_CERTIFICATE" | base64 --decode > "$cert"
410+
security create-keychain -p "$keychain_password" build.keychain
411+
security set-keychain-settings -lut 21600 build.keychain
412+
security unlock-keychain -p "$keychain_password" build.keychain
413+
security import "$cert" -k build.keychain -P "" -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productsign
414+
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$keychain_password" build.keychain > /dev/null
415+
security list-keychains -d user -s build.keychain $(security list-keychains -d user | tr -d '"')
416+
rm -f "$cert"
417+
env:
418+
APPLE_SIGNING_CERTIFICATE: ${{ secrets.APPLE_SIGNING_CERTIFICATE }}
410419
- name: Sign CLI
411420
if: needs.plan.outputs.cli == 'true'
412421
run: bash .github/release/sign-cli-macos.sh "$RUNNER_TEMP/in/build-npm" "$RUNNER_TEMP/out"
@@ -425,6 +434,11 @@ jobs:
425434
with:
426435
name: sign-macos
427436
path: ${{ runner.temp }}/out
437+
- name: Delete keychain
438+
if: always() && needs.plan.outputs.dry_run != 'true'
439+
run: |
440+
rm -f "$RUNNER_TEMP/cert.p12"
441+
security delete-keychain build.keychain || true
428442
429443
# Signs the Windows CLI and every executable and native module of the unpacked desktop apps.
430444
sign-windows:

0 commit comments

Comments
 (0)