buildAndDeployFrameworks.sh 7.7 KB

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