create_keychain.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. # Inspired by
  3. # https://localazy.com/blog/how-to-automatically-sign-macos-apps-using-github-actions
  4. TEMP_CI_CERT_FILENAME="temp_ci_appleDistribution.p12"
  5. # Get the following variables from MacOS-pack.yaml:
  6. # APP_NAME
  7. # APPLE_DEV_IDENTITY
  8. # APPLE_DEVELOPER_ID_APPLICATION_CERT_PASS
  9. # APPLE_DEVELOPER_ID_APPLICATION_CERT_DATA
  10. # APPLE_TEMP_CI_KEYCHAIN_PASS
  11. # For the Community (if no Apple Developer ID available)
  12. if [[ "${APPLE_DEV_IDENTITY}" == "" ]]; then
  13. echo "WARNING: No credentials for signing found"
  14. echo "WARNING: Cannot create keychain for signing"
  15. echo "WARNING: dmg package won't be signed and notarized"
  16. exit 0
  17. fi
  18. # create keychain
  19. security create-keychain -p "${APPLE_TEMP_CI_KEYCHAIN_PASS}" build.keychain
  20. security default-keychain -s build.keychain
  21. security unlock-keychain -p "${APPLE_TEMP_CI_KEYCHAIN_PASS}" build.keychain
  22. # import certificate
  23. [ -r "${TEMP_CI_CERT_FILENAME}" ] && rm "${TEMP_CI_CERT_FILENAME}"
  24. echo "${APPLE_DEVELOPER_ID_APPLICATION_CERT_DATA}" | base64 --decode > "${TEMP_CI_CERT_FILENAME}"
  25. security import "${TEMP_CI_CERT_FILENAME}" -P "${APPLE_DEVELOPER_ID_APPLICATION_CERT_PASS}" -k build.keychain -T /usr/bin/codesign
  26. [ -r "${TEMP_CI_CERT_FILENAME}" ] && rm "${TEMP_CI_CERT_FILENAME}"
  27. security find-identity -v
  28. security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "${APPLE_TEMP_CI_KEYCHAIN_PASS}" build.keychain