sign_qtapp.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # Inspired by
  3. # https://localazy.com/blog/how-to-automatically-sign-macos-apps-using-github-actions
  4. # https://forum.qt.io/topic/96652/how-to-notarize-qt-application-on-macos/18
  5. # Get the following variables from the MacOS-pack.yaml:
  6. # APP_NAME
  7. # APPLE_DEV_IDENTITY
  8. # APPLE_DEV_USER
  9. # APPLE_DEV_PASS
  10. # For the Community (if no Apple Developer ID available)
  11. if [[ "${APPLE_DEV_IDENTITY}" == "" ]]; then
  12. echo "WARNING: No credentials for signing found"
  13. echo "WARNING: dmg package won't be signed and notarized"
  14. echo "--> Start packaging process"
  15. "$(brew --prefix qt5)/bin/macdeployqt" "${APP_NAME}.app" -dmg
  16. echo "--> Update dmg package links"
  17. "./${HELPERS_SCRIPTS_PATH}/update_package.sh"
  18. exit 0
  19. fi
  20. echo "--> Start application signing process"
  21. codesign --sign "${APPLE_DEV_IDENTITY}" --verbose --deep "${APP_NAME}.app"
  22. echo "--> Start packaging process"
  23. "$(brew --prefix qt5)/bin/macdeployqt" "${APP_NAME}.app" -dmg -sign-for-notarization="${APPLE_DEV_IDENTITY}"
  24. echo "--> Update dmg package links"
  25. "./${HELPERS_SCRIPTS_PATH}/update_package.sh"
  26. echo "--> Start dmg signing process"
  27. codesign --sign "${APPLE_DEV_IDENTITY}" --verbose --deep "${APP_NAME}.dmg"
  28. echo "--> Start Notarization process"
  29. response=$(xcrun altool -t osx -f "${APP_NAME}.dmg" --primary-bundle-id "org.namecheap.${APP_NAME}" --notarize-app -u "${APPLE_DEV_USER}" -p "${APPLE_DEV_PASS}")
  30. requestUUID=$(echo "${response}" | tr ' ' '\n' | tail -1)
  31. for ((ATTEMPT=5; ATTEMPT>=1; ATTEMPT--))
  32. do
  33. echo "--> Checking notarization status"
  34. statusCheckResponse=$(xcrun altool --notarization-info "${requestUUID}" -u "${APPLE_DEV_USER}" -p "${APPLE_DEV_PASS}")
  35. isSuccess=$(echo "${statusCheckResponse}" | grep "success")
  36. isFailure=$(echo "${statusCheckResponse}" | grep "invalid")
  37. if [[ "${isSuccess}" != "" ]]; then
  38. echo "Notarization done!"
  39. xcrun stapler staple "${APP_NAME}.dmg"
  40. EXIT_CODE=$?
  41. if [ ${EXIT_CODE} -ne 0 ]; then
  42. echo "Stapler failed!"
  43. exit ${EXIT_CODE}
  44. fi
  45. echo "Stapler done!"
  46. break
  47. fi
  48. if [[ "${isFailure}" != "" ]]; then
  49. echo "${statusCheckResponse}"
  50. echo "Notarization failed"
  51. exit 1
  52. fi
  53. echo "Notarization not finished yet, sleep 2m then check again..."
  54. for num in {1..12}
  55. do
  56. sleep 10
  57. echo "Elapsed: ${num}0 sec"
  58. done
  59. done
  60. if [[ "${ATTEMPT}" == 0 ]]; then
  61. export NOTARIZATION_CHECK="false"
  62. echo "::warning Notarization check failed"
  63. else
  64. export NOTARIZATION_CHECK="true"
  65. fi
  66. echo "--> Start verify signing process"
  67. codesign -dv --verbose=4 "${APP_NAME}.dmg"