buildAndDeployFrameworks.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #!/usr/bin/env bash
  2. set -e
  3. CLEAN=yes
  4. DEPLOY_MOBILEVLCKIT=no
  5. DEPLOY_TVVLCKIT=no
  6. TEST_MODE=no
  7. BUILD_MOBILEVLCKIT="./buildMobileVLCKit.sh -vf"
  8. CREATE_DISTRIBUTION_PACKAGE="./create-distributable-package.sh"
  9. STABLE_UPLOAD_URL="https://download.videolan.org/cocoapods/unstable/"
  10. MOBILE_PODSPEC="MobileVLCKit-unstable.podspec"
  11. TV_PODSPEC="TVVLCKit-unstable.podspec"
  12. # Note: create-distributable-package script is building VLCKit(s) if not found.
  13. # Note: by default, VLCKit will be build if no option is passed.
  14. usage()
  15. {
  16. cat << EOF
  17. usage: $0 [options]
  18. OPTIONS
  19. -d Disable cleaning of build directory
  20. -m Deploy MobileVLCKit
  21. -t Deploy TVVLCKit
  22. -l Start test for build phases
  23. EOF
  24. }
  25. while getopts "hdmtl" OPTION
  26. do
  27. case $OPTION in
  28. h)
  29. usage
  30. exit 1
  31. ;;
  32. d)
  33. CLEAN=no
  34. ;;
  35. m)
  36. DEPLOY_MOBILEVLCKIT=yes
  37. ;;
  38. t)
  39. DEPLOY_TVVLCKIT=yes
  40. ;;
  41. l)
  42. TEST_MODE=yes
  43. ;;
  44. \?)
  45. usage
  46. exit 1
  47. ;;
  48. esac
  49. done
  50. shift "$((OPTIND-1))"
  51. VERSION=""
  52. VERSION_DELIMITER="3.0.1a"
  53. ROOT_DIR="$(dirname "$(pwd)")"
  54. UPLOAD_URL=""
  55. VLC_HASH=""
  56. VLCKIT_HASH=""
  57. DISTRIBUTION_PACKAGE=""
  58. DISTRIBUTION_PACKAGE_SHA=""
  59. TARGET=""
  60. ##################
  61. # Helper methods #
  62. ##################
  63. spushd()
  64. {
  65. pushd $1 2>&1> /dev/null
  66. }
  67. spopd()
  68. {
  69. popd 2>&1> /dev/null
  70. }
  71. log()
  72. {
  73. local green='\033[1;32m'
  74. local orange='\033[1;91m'
  75. local red='\033[1;31m'
  76. local normal='\033[0m'
  77. local color=$green
  78. local msgType=$1
  79. if [ "$1" = "Warning" ]; then
  80. color=$orange
  81. msgType="Warning"
  82. elif [ "$1" = "Error" ]; then
  83. color=$red
  84. msgType="Error"
  85. fi
  86. echo -e "[${color}${msgType}${normal}] $2"
  87. }
  88. clean()
  89. {
  90. log "Info" "Starting cleaning..."
  91. if [ -d "build" ]; then
  92. rm -rf "$ROOT_DIR/build"
  93. else
  94. log "Warning" "Build directory not found!"
  95. fi
  96. log "Info" "Build directory cleaned"
  97. }
  98. buildMobileVLCKit()
  99. {
  100. log "Info" "Staring MobileVLCKit build..."
  101. if ! $BUILD_MOBILEVLCKIT; then
  102. log "Error" "MobileVLCKit build failed"
  103. rm -fr "build/"
  104. exit 1
  105. fi
  106. log "Info" "MobileVLCKit build finished!"
  107. }
  108. getVLCHashes()
  109. {
  110. VLCKIT_HASH=$(git rev-parse --short HEAD)
  111. VERSION=$(git describe --tags HEAD)
  112. spushd "libvlc/vlc"
  113. VLC_HASH=$(git rev-parse --short HEAD)
  114. spopd #libvlc/vlc
  115. }
  116. renamePackage()
  117. {
  118. if [ "$1" = "-m" ]; then
  119. TARGET="MobileVLCKit"
  120. elif [ "$1" = "-t" ]; then
  121. TARGET="TVVLCKit"
  122. fi
  123. getVLCHashes
  124. local packageName="${TARGET}-REPLACEWITHVERSION.tar.xz"
  125. if [ -f $packageName ]; then
  126. DISTRIBUTION_PACKAGE="${TARGET}-${VERSION}-${VLCKIT_HASH}-${VLC_HASH}.tar.xz"
  127. mv $packageName "$DISTRIBUTION_PACKAGE"
  128. log "Info" "Finished renaming package with name: ${DISTRIBUTION_PACKAGE}"
  129. fi
  130. }
  131. packageBuild()
  132. {
  133. spushd "Packaging"
  134. if ! $CREATE_DISTRIBUTION_PACKAGE "$1"; then
  135. log "Error" "Failed to package!"
  136. exit 1
  137. fi
  138. spopd #Packaging
  139. }
  140. getSHA()
  141. {
  142. DISTRIBUTION_PACKAGE_SHA=$(shasum -a 256 "$DISTRIBUTION_PACKAGE" | cut -d " " -f 1)
  143. log "Info" "Distribution package checksum: ${DISTRIBUTION_PACKAGE_SHA}"
  144. }
  145. bumpPodspec()
  146. {
  147. local podVersion="s.version = '${VERSION}'"
  148. local uploadURL=":http => '${UPLOAD_URL}${DISTRIBUTION_PACKAGE}'"
  149. local podSHA=":sha256 => '${DISTRIBUTION_PACKAGE_SHA}'"
  150. perl -i -pe's#s.version.*#'"${podVersion}"'#g' $1
  151. perl -i -pe's#:http.*#'"${uploadURL},"'#g' $1
  152. perl -i -pe's#:sha256.*#'"${podSHA}"'#g' $1
  153. }
  154. gitCommit()
  155. {
  156. local podspec="$1"
  157. git add "$podspec"
  158. git commit -m "${podspec}: Update version to ${VERSION}"
  159. }
  160. startPodTesting()
  161. {
  162. # Testing on a side even though it ressembles podDeploy() for future tests.
  163. log "Info" "Starting local tests..."
  164. spushd "Packaging/podspecs"
  165. if bumpPodspec $CURRENT_PODSPEC && \
  166. pod spec lint --verbose $CURRENT_PODSPEC ; then
  167. log "Info" "Testing succesfull!"
  168. else
  169. log "Error" "Testing failed."
  170. fi
  171. git checkout $CURRENT_PODSPEC
  172. spopd #Packaging/podspecs
  173. rm ${DISTRIBUTION_PACKAGE}
  174. rm -rf ${TARGET}-binary
  175. log "Warning" "All files generated during tests have been removed."
  176. }
  177. podDeploy()
  178. {
  179. log "Info" "Starting podspec operations..."
  180. spushd "Packaging/podspecs"
  181. if bumpPodspec $CURRENT_PODSPEC && \
  182. pod spec lint --verbose $CURRENT_PODSPEC && \
  183. pod trunk push $CURRENT_PODSPEC && \
  184. gitCommit $CURRENT_PODSPEC; then
  185. log "Info" "Podpsec operations successfully finished!"
  186. else
  187. git checkout $CURRENT_PODSPEC
  188. log "Error" "Podspec operations failed."
  189. fi
  190. spopd #Packaging/podspecs
  191. }
  192. checkIfExistOnRemote()
  193. {
  194. if ! curl --head --silent "$1" | head -n 1 | grep -q 404; then
  195. return 0
  196. else
  197. return 1
  198. fi
  199. }
  200. uploadPackage()
  201. {
  202. # handle upload of distribution package.
  203. if [ "$DISTRIBUTION_PACKAGE" = "" ]; then
  204. log "Error" "Distribution package not found!"
  205. exit 1
  206. fi
  207. while read -r -n 1 -p "The package is ready please upload it to \"${UPLOAD_URL}\", press a key to continue when uploaded [y,a,r]: " response
  208. do
  209. printf '\r'
  210. case $response in
  211. y)
  212. log "Info" "Checking for: '${UPLOAD_URL}${DISTRIBUTION_PACKAGE}'..."
  213. if checkIfExistOnRemote "${UPLOAD_URL}${DISTRIBUTION_PACKAGE}"; then
  214. log "Info" "Package found on ${UPLOAD_URL}!"
  215. break
  216. fi
  217. log "Warning" "Package not found on ${UPLOAD_URL}!"
  218. ;;
  219. a)
  220. log "Warning" "Aborting deployment process!"
  221. exit 1
  222. ;;
  223. *)
  224. ;;
  225. esac
  226. done
  227. }
  228. setCurrentPodspec()
  229. {
  230. # Addded extra precision of target to protect against future targets
  231. if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
  232. CURRENT_PODSPEC=$MOBILE_PODSPEC
  233. elif [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
  234. CURRENT_PODSPEC=$TV_PODSPEC
  235. fi
  236. }
  237. podOperations()
  238. {
  239. if [ "$TEST_MODE" = "yes" ]; then
  240. startPodTesting
  241. else
  242. podDeploy
  243. log "Info" "Removing distribution package ${DISTRIBUTION_PACKAGE} and build directory ${TARGET}-binary."
  244. rm ${DISTRIBUTION_PACKAGE}
  245. rm -rf ${TARGET}-binary
  246. fi
  247. }
  248. ##################
  249. # Command Center #
  250. ##################
  251. # Currently, mobile and tv cannot be deployed at the same time.
  252. if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ] && [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
  253. log "Error" "Cannot depoy MobileVLCKit and TVVLCKit at the same time!"
  254. exit 1
  255. fi
  256. if [ "$CLEAN" = "yes" ]; then
  257. clean
  258. fi
  259. # Used to send parameter to the other scripts.
  260. options=""
  261. if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
  262. options="-m"
  263. elif [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
  264. options="-t"
  265. fi
  266. UPLOAD_URL=${STABLE_UPLOAD_URL}
  267. spushd "$ROOT_DIR"
  268. buildMobileVLCKit
  269. setCurrentPodspec
  270. packageBuild $options
  271. renamePackage $options
  272. getSHA
  273. # Note: Disable uploading and podoperations for now.
  274. #uploadPackage
  275. #podOperations
  276. spopd #ROOT_DIR