build-release.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env bash
  2. set -xeu
  3. set -o pipefail
  4. function finish() {
  5. ditto -c -k --sequesterRsrc --keepParent "${RESULT_BUNDLE_PATH}" "${RESULT_BUNDLE_PATH}.zip"
  6. rm -rf "${RESULT_BUNDLE_PATH}"
  7. }
  8. trap finish EXIT
  9. SDK="${SDK:-iphoneos}"
  10. WORKSPACE="${WORKSPACE:-Mastodon.xcworkspace}"
  11. SCHEME="${SCHEME:-Mastodon}"
  12. CONFIGURATION=${CONFIGURATION:-Release}
  13. BUILD_DIR=${BUILD_DIR:-.build}
  14. ARTIFACT_PATH=${RESULT_PATH:-${BUILD_DIR}/Artifacts}
  15. RESULT_BUNDLE_PATH="${ARTIFACT_PATH}/${SCHEME}.xcresult"
  16. ARCHIVE_PATH=${ARCHIVE_PATH:-${BUILD_DIR}/Archives/${SCHEME}.xcarchive}
  17. DERIVED_DATA_PATH=${DERIVED_DATA_PATH:-${BUILD_DIR}/DerivedData}
  18. EXPORT_OPTIONS_FILE=".github/support/ExportOptions.plist"
  19. WORK_DIR=$(pwd)
  20. API_PRIVATE_KEYS_PATH="${WORK_DIR}/${BUILD_DIR}/private_keys"
  21. API_KEY_FILE="${API_PRIVATE_KEYS_PATH}/api_key.p8"
  22. rm -rf "${RESULT_BUNDLE_PATH}"
  23. rm -rf "${API_PRIVATE_KEYS_PATH}"
  24. mkdir -p "${API_PRIVATE_KEYS_PATH}"
  25. echo -n "${ENV_API_PRIVATE_KEY_BASE64}" | base64 --decode > "${API_KEY_FILE}"
  26. BUILD_NUMBER=$(app-store-connect get-latest-testflight-build-number $ENV_APP_ID --issuer-id $ENV_ISSUER_ID --key-id $ENV_API_KEY_ID --private-key @file:$API_KEY_FILE)
  27. BUILD_NUMBER=$((BUILD_NUMBER+1))
  28. CURRENT_PROJECT_VERSION=${BUILD_NUMBER:-0}
  29. echo "GITHUB_TAG_NAME=build-$CURRENT_PROJECT_VERSION" >> $GITHUB_ENV
  30. agvtool new-version -all $CURRENT_PROJECT_VERSION
  31. xcrun xcodebuild clean \
  32. -workspace "${WORKSPACE}" \
  33. -scheme "${SCHEME}" \
  34. -configuration "${CONFIGURATION}"
  35. xcrun xcodebuild archive \
  36. -workspace "${WORKSPACE}" \
  37. -scheme "${SCHEME}" \
  38. -configuration "${CONFIGURATION}" \
  39. -destination generic/platform=iOS \
  40. -sdk "${SDK}" \
  41. -parallelizeTargets \
  42. -showBuildTimingSummary \
  43. -derivedDataPath "${DERIVED_DATA_PATH}" \
  44. -archivePath "${ARCHIVE_PATH}" \
  45. -resultBundlePath "${RESULT_BUNDLE_PATH}" \
  46. -allowProvisioningUpdates \
  47. -authenticationKeyPath "${API_KEY_FILE}" \
  48. -authenticationKeyID "${ENV_API_KEY_ID}" \
  49. -authenticationKeyIssuerID "${ENV_ISSUER_ID}"
  50. xcrun xcodebuild \
  51. -exportArchive \
  52. -archivePath "${ARCHIVE_PATH}" \
  53. -exportOptionsPlist "${EXPORT_OPTIONS_FILE}" \
  54. -exportPath "${ARTIFACT_PATH}/${SCHEME}.ipa" \
  55. -allowProvisioningUpdates \
  56. -authenticationKeyPath "${API_KEY_FILE}" \
  57. -authenticationKeyID "${ENV_API_KEY_ID}" \
  58. -authenticationKeyIssuerID "${ENV_ISSUER_ID}"
  59. # Zip up the Xcode Archive into Artifacts folder.
  60. ditto -c -k --sequesterRsrc --keepParent "${ARCHIVE_PATH}" "${ARTIFACT_PATH}/${SCHEME}.xcarchive.zip"