You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build-ipa.sh 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash
  2. set -e
  3. # The script is based on tutorial written by Antonis Tsakiridis published at:
  4. # https://medium.com/@atsakiridis/continuous-deployment-for-ios-using-travis-ci-55dcea342d9
  5. #
  6. # It is intended to be executed through the Travis CI REST API call, as it
  7. # requires few arguments which are mandatory with no default values provided:
  8. # PR_REPO_SLUG - the Github name of the repo to be merged into the origin/master
  9. # PR_BRANCH - the branch to be merged, if set to "master" no merge will happen
  10. # IPA_DEPLOY_LOCATION - the location understandable by the "scp" command
  11. # executed at the end of the script to deploy the output .ipa file
  12. # LIB_JITSI_MEET_PKG (optional) - the npm package for lib-jitsi-meet which will
  13. # be put in place of the current version in the package.json file.
  14. #
  15. # Other than that the script requires the following env variables to be set
  16. # (reading the tutorial mentioned above will help in understanding the
  17. # variables):
  18. #
  19. # APPLE_CERT_URL - the URL pointing to Apple certificate (set to
  20. # http://developer.apple.com/certificationauthority/AppleWWDRCA.cer by default)
  21. # DEPLOY_SSH_CERT_URL - the SSH private key used by the 'scp' command to deploy
  22. # the .ipa. It is expected to be encrypted with the $ENCRYPTION_PASSWORD.
  23. # ENCRYPTION_PASSWORD - the password used to decrypt certificate/key files used
  24. # in the script.
  25. # IOS_DEV_CERT_KEY_URL - URL pointing to provisioning profile certificate key
  26. # file (development-key.p12.enc from the tutorial) encrypted with the
  27. # $ENCRYPTION_PASSWORD.
  28. # IOS_DEV_CERT_URL - URL pointing to provisioning profile certificate file
  29. # (development-cert.cer.enc from the tutorial) encrypted with the
  30. # $ENCRYPTION_PASSWORD.
  31. # IOS_DEV_PROV_PROFILE_URL - URL pointing to provisioning profile file
  32. # (profile-development-olympus.mobileprovision.enc from the tutorial) encrypted
  33. # with the $ENCRYPTION_PASSWORD.
  34. # IOS_SIGNING_CERT_PASSWORD - the password to the provisioning profile
  35. # certificate key (used to open development-key.p12 from the tutorial).
  36. # IOS_TEAM_ID - the team ID inserted into build-ipa-.plist.template file in
  37. # place of "YOUR_TEAM_ID".
  38. # Travis will not print the last echo if there's no sleep 1
  39. function echoSleepAndExit1() {
  40. echo $1
  41. sleep 1
  42. exit 1
  43. }
  44. echo "TRAVIS_BRANCH=${TRAVIS_BRANCH}"
  45. echo "TRAVIS_REPO_SLUG=${TRAVIS_REPO_SLUG}"
  46. if [ -z $PR_REPO_SLUG ]; then
  47. echoSleepAndExit1 "No PR_REPO_SLUG defined"
  48. fi
  49. if [ -z $PR_BRANCH ]; then
  50. echoSleepAndExit1 "No PR_BRANCH defined"
  51. fi
  52. if [ -z $IPA_DEPLOY_LOCATION ]; then
  53. echoSleepAndExit1 "No IPA_DEPLOY_LOCATION defined"
  54. fi
  55. if [ -z $APPLE_CERT_URL ]; then
  56. APPLE_CERT_URL="http://developer.apple.com/certificationauthority/AppleWWDRCA.cer"
  57. fi
  58. echo "PR_REPO_SLUG=${PR_REPO_SLUG} PR_BRANCH=${PR_BRANCH}"
  59. # do the marge and git log
  60. if [ $PR_BRANCH != "master" ]; then
  61. echo "Will merge ${PR_REPO_SLUG}/${PR_BRANCH} into master"
  62. git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
  63. git fetch origin master
  64. git checkout master
  65. git pull https://github.com/${PR_REPO_SLUG}.git $PR_BRANCH --no-edit
  66. fi
  67. # Link this lib-jitsi-meet checkout in jitsi-meet through the package.json
  68. if [ ! -z ${LIB_JITSI_MEET_PKG} ];
  69. then
  70. echo "Adjusting lib-jitsi-meet package in package.json to ${LIB_JITSI_MEET_PKG}"
  71. # escape for the sed
  72. LIB_JITSI_MEET_PKG=$(echo $LIB_JITSI_MEET_PKG | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')
  73. sed -i.bak -e "s/\"lib-jitsi-meet.*/\"lib-jitsi-meet\"\: \"${LIB_JITSI_MEET_PKG}\",/g" package.json
  74. echo "Package.json lib-jitsi-meet line:"
  75. grep lib-jitsi-meet package.json
  76. else
  77. echo "LIB_JITSI_MEET_PKG var not set - will not modify the package.json"
  78. fi
  79. git log -20 --graph --pretty=format':%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset'
  80. # certificates
  81. CERT_DIR="ios/travis-ci/certs"
  82. mkdir $CERT_DIR
  83. curl -L -o ${CERT_DIR}/AppleWWDRCA.cer 'http://developer.apple.com/certificationauthority/AppleWWDRCA.cer'
  84. curl -L -o ${CERT_DIR}/dev-cert.cer.enc ${IOS_DEV_CERT_URL}
  85. curl -L -o ${CERT_DIR}/dev-key.p12.enc ${IOS_DEV_CERT_KEY_URL}
  86. curl -L -o ${CERT_DIR}/dev-profile.mobileprovision.enc ${IOS_DEV_PROV_PROFILE_URL}
  87. curl -L -o ${CERT_DIR}/id_rsa.enc ${DEPLOY_SSH_CERT_URL}
  88. openssl aes-256-cbc -k "$ENCRYPTION_PASSWORD" -in ${CERT_DIR}/dev-cert.cer.enc -d -a -out ${CERT_DIR}/dev-cert.cer
  89. openssl aes-256-cbc -k "$ENCRYPTION_PASSWORD" -in ${CERT_DIR}/dev-key.p12.enc -d -a -out ${CERT_DIR}/dev-key.p12
  90. openssl aes-256-cbc -k "$ENCRYPTION_PASSWORD" -in ${CERT_DIR}/dev-profile.mobileprovision.enc -d -a -out ${CERT_DIR}/dev-profile.mobileprovision
  91. openssl aes-256-cbc -k "$ENCRYPTION_PASSWORD" -in ${CERT_DIR}/id_rsa.enc -d -a -out ${CERT_DIR}/id_rsa
  92. chmod 0600 ${CERT_DIR}/id_rsa
  93. security create-keychain -p $ENCRYPTION_PASSWORD ios-build.keychain
  94. security default-keychain -s ios-build.keychain
  95. security unlock-keychain -p $ENCRYPTION_PASSWORD ios-build.keychain
  96. security set-keychain-settings -t 3600 -l ~/Library/Keychains/ios-build.keychain
  97. echo "importing Apple cert"
  98. security import ${CERT_DIR}/AppleWWDRCA.cer -k ios-build.keychain -A
  99. echo "importing dev-cert.cer"
  100. security import ${CERT_DIR}/dev-cert.cer -k ios-build.keychain -A
  101. echo "importing dev-key.p12"
  102. security import ${CERT_DIR}/dev-key.p12 -k ios-build.keychain -P $IOS_SIGNING_CERT_PASSWORD -A
  103. echo "will set-key-partition-list"
  104. # Fix for OS X Sierra that hungs in the codesign step
  105. security set-key-partition-list -S apple-tool:,apple: -s -k $ENCRYPTION_PASSWORD ios-build.keychain > /dev/null
  106. echo "done set-key-partition-list"
  107. mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
  108. cp "${CERT_DIR}/dev-profile.mobileprovision" ~/Library/MobileDevice/Provisioning\ Profiles/
  109. npm install
  110. cd ios
  111. pod update
  112. pod install
  113. cd ..
  114. mkdir -p /tmp/jitsi-meet/
  115. xcodebuild archive -workspace ios/jitsi-meet.xcworkspace -scheme jitsi-meet -configuration Release -archivePath /tmp/jitsi-meet/jitsi-meet.xcarchive
  116. sed -e "s/YOUR_TEAM_ID/${IOS_TEAM_ID}/g" ios/travis-ci/build-ipa.plist.template > ios/travis-ci/build-ipa.plist
  117. IPA_EXPORT_DIR=/tmp/jitsi-meet/jitsi-meet-ipa
  118. xcodebuild -exportArchive -archivePath /tmp/jitsi-meet/jitsi-meet.xcarchive -exportPath $IPA_EXPORT_DIR -exportOptionsPlist ios/travis-ci/build-ipa.plist
  119. echo "Will try deploy the .ipa to: ${IPA_DEPLOY_LOCATION}"
  120. scp -i ${CERT_DIR}/id_rsa -o StrictHostKeyChecking=no -o LogLevel=DEBUG "${IPA_EXPORT_DIR}/jitsi-meet.ipa" "${IPA_DEPLOY_LOCATION}"