buildAndDeployFrameworks.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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.0a"
  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. spushd "libvlc/vlc"
  112. VLC_HASH=$(git rev-parse --short HEAD)
  113. spopd #libvlc/vlc
  114. }
  115. renamePackage()
  116. {
  117. if [ "$1" = "-m" ]; then
  118. TARGET="MobileVLCKit"
  119. elif [ "$1" = "-t" ]; then
  120. TARGET="TVVLCKit"
  121. fi
  122. getVLCHashes
  123. local packageName="${TARGET}-REPLACEWITHVERSION.tar.xz"
  124. if [ -f $packageName ]; then
  125. DISTRIBUTION_PACKAGE="${TARGET}-${VERSION}-${VLCKIT_HASH}-${VLC_HASH}.tar.xz"
  126. mv $packageName "$DISTRIBUTION_PACKAGE"
  127. log "Info" "Finished renaming package!"
  128. fi
  129. }
  130. packageBuild()
  131. {
  132. spushd "Packaging"
  133. if ! $CREATE_DISTRIBUTION_PACKAGE "$1"; then
  134. log "Error" "Failed to package!"
  135. exit 1
  136. fi
  137. spopd #Packaging
  138. }
  139. getSHA()
  140. {
  141. log "Info" "Getting SHA from distrubition package..."
  142. DISTRIBUTION_PACKAGE_SHA=$(shasum -a 256 "$DISTRIBUTION_PACKAGE" | cut -d " " -f 1 )
  143. }
  144. bumpPodspec()
  145. {
  146. local podVersion="s.version = '${VERSION}'"
  147. local uploadURL=":http => '${UPLOAD_URL}${DISTRIBUTION_PACKAGE}'"
  148. local podSHA=":sha256 => '${DISTRIBUTION_PACKAGE_SHA}'"
  149. perl -i -pe's#s.version.*#'"${podVersion}"'#g' $1
  150. perl -i -pe's#:http.*#'"${uploadURL},"'#g' $1
  151. perl -i -pe's#:sha256.*#'"${podSHA}"'#g' $1
  152. }
  153. gitCommit()
  154. {
  155. local podspec="$1"
  156. git add "$podspec"
  157. git commit -m "${podspec}: Update version to ${VERSION}"
  158. }
  159. startPodTesting()
  160. {
  161. # Testing on a side even though it ressembles podDeploy() for future tests.
  162. log "Info" "Starting local tests..."
  163. spushd "Packaging/podspecs"
  164. if bumpPodspec $CURRENT_PODSPEC && \
  165. pod spec lint --verbose $CURRENT_PODSPEC ; then
  166. log "Info" "Testing succesfull!"
  167. else
  168. log "Error" "Testing failed."
  169. fi
  170. git checkout $CURRENT_PODSPEC
  171. spopd #Packaging/podspecs
  172. rm ${DISTRIBUTION_PACKAGE}
  173. rm -rf ${TARGET}-binary
  174. log "Warning" "All files generated during tests have been removed."
  175. }
  176. podDeploy()
  177. {
  178. log "Info" "Starting podspec operations..."
  179. spushd "Packaging/podspecs"
  180. if bumpPodspec $CURRENT_PODSPEC && \
  181. pod spec lint --verbose $CURRENT_PODSPEC && \
  182. pod trunk push $CURRENT_PODSPEC && \
  183. gitCommit $CURRENT_PODSPEC; then
  184. log "Info" "Podpsec operations successfully finished!"
  185. else
  186. git checkout $CURRENT_PODSPEC
  187. log "Error" "Podspec operations failed."
  188. fi
  189. spopd #Packaging/podspecs
  190. }
  191. checkIfExistOnRemote()
  192. {
  193. if ! curl --head --silent "$1" | head -n 1 | grep -q 404; then
  194. return 0
  195. else
  196. return 1
  197. fi
  198. }
  199. uploadPackage()
  200. {
  201. # handle upload of distribution package.
  202. if [ "$DISTRIBUTION_PACKAGE" = "" ]; then
  203. log "Error" "Distribution package not found!"
  204. exit 1
  205. fi
  206. 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
  207. do
  208. printf '\r'
  209. case $response in
  210. y)
  211. log "Info" "Checking for: '${UPLOAD_URL}${DISTRIBUTION_PACKAGE}'..."
  212. if checkIfExistOnRemote "${UPLOAD_URL}${DISTRIBUTION_PACKAGE}"; then
  213. log "Info" "Package found on ${UPLOAD_URL}!"
  214. break
  215. fi
  216. log "Warning" "Package not found on ${UPLOAD_URL}!"
  217. ;;
  218. a)
  219. log "Warning" "Aborting deployment process!"
  220. exit 1
  221. ;;
  222. *)
  223. ;;
  224. esac
  225. done
  226. }
  227. getVersion()
  228. {
  229. spushd "Packaging/podspecs"
  230. # Basing on the version of the MobileVLCKit podspec to retreive old version
  231. local oldVersion=$(grep s.version $MOBILE_PODSPEC | cut -d "'" -f 2)
  232. VERSION=$(echo $oldVersion | awk -F$VERSION_DELIMITER -v OFS=$VERSION_DELIMITER 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}')
  233. spopd #Packaging/podspecs
  234. }
  235. setCurrentPodspec()
  236. {
  237. # Addded extra precision of target to protect against future targets
  238. if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
  239. CURRENT_PODSPEC=$MOBILE_PODSPEC
  240. elif [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
  241. CURRENT_PODSPEC=$TV_PODSPEC
  242. fi
  243. }
  244. podOperations()
  245. {
  246. if [ "$TEST_MODE" = "yes" ]; then
  247. startPodTesting
  248. else
  249. podDeploy
  250. log "Info" "Removing distribution package ${DISTRIBUTION_PACKAGE} and build directory ${TARGET}-binary."
  251. rm ${DISTRIBUTION_PACKAGE}
  252. rm -rf ${TARGET}-binary
  253. fi
  254. }
  255. ##################
  256. # Command Center #
  257. ##################
  258. if [ "$CLEAN" = "yes" ]; then
  259. clean
  260. fi
  261. # Used to send parameter to the other scripts.
  262. options=""
  263. if [ "$DEPLOY_MOBILEVLCKIT" = "yes" ]; then
  264. options="-m"
  265. elif [ "$DEPLOY_TVVLCKIT" = "yes" ]; then
  266. options="-t"
  267. fi
  268. UPLOAD_URL=${STABLE_UPLOAD_URL}
  269. spushd "$ROOT_DIR"
  270. buildMobileVLCKit
  271. setCurrentPodspec
  272. getVersion
  273. packageBuild $options
  274. renamePackage $options
  275. getSHA
  276. uploadPackage
  277. podOperations
  278. spopd #ROOT_DIR