Advertisement
Badal_hs_shah

Untitled

Jul 14th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.06 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # bseelig 2012-04-02 "Gits" a specified git project and branch, or tag and builds iOS apps. It also updates the version number and builds a client applicatoin based on parameters.
  4. #
  5. # Revisions:
  6. # bseelig 2020-09-04
  7. #
  8.  
  9. branchName=$1
  10. versionNumber=$2
  11. customerCode=$3
  12. environment=$4
  13. clientType=$5
  14. otherOption=$6
  15. debugMode=$7
  16. logFile=$(date "+$HOME/autobuilds/${customerCode} ${clientType} %Y-%m-%d %H.%M.%S.log")
  17. dropFolderMountUncPath="smb://tfsbuild01.inside.rw3.com/drop" # This is used to display an informational message to the user. It is not used to mount the drop folder.
  18. dropFolderPath="/Volumes/drop"
  19. buildNumber=""
  20. bundleID=""
  21. newBundleVersion=""
  22. plistExe="/usr/libexec/plistbuddy"
  23. plistInfoFile=""
  24. ipaUrl=""
  25. environmentSubdomain=""
  26. ipaFileName=""
  27. workingPath=""
  28. resultFileName="MarketCheck"
  29. workspace="Carbon.xcworkspace"
  30. buildProjectFile=""
  31.  
  32. # Build .proj file overwrite. These values should be overwritten by the customer build project file.
  33. webModulesForPortal="accountmanager accountmessenger admin" #Add in order you want them to appear top to bottom, left to right
  34. appModulesForPortal="" #Add in order you want them to appear top to bottom, on right hand side (usually smartcallapp first, then marketcheckapp)
  35. phone="555-1212"
  36. mailto="helpdesk@rw3.com"
  37. projectName="Carbon"
  38. buildPath="$HOME/autobuilds/Carbon"
  39. sourcePath="$buildPath/Carbon"
  40. configurationName=""
  41. targetName=""
  42. appName=""
  43. targetEnvironmentName=""
  44. productCode=""
  45. customerLiveSubdomain=""
  46. appIDPrefix=""
  47. customerConstantCode=""
  48. doBuild=1
  49. doUploadToAppCenter=0
  50. dropFolderCustomer=""
  51. useSSL=0
  52. provisioningProfileID=""
  53. developmentTeamID=""
  54. displayUPCControls=0
  55. appCenterName=""
  56.  
  57. echo "Command line was: $0 $1 $2 $3 $4 $5 $6 $7 $8 $9"
  58.  
  59. if [ "$debugMode" == "" ]; then
  60. debugMode="false"
  61. fi
  62.  
  63. # Parameter 1: Error message, is a message about the error.
  64. function IfError
  65. {
  66. if [[ $? -ne 0 ]]; then # check return code passed to function
  67. echo $(date "+[%Y-%m-%d %H:%M:%S]") "$1" # if rc > 0 then print error msg and quit
  68. echo
  69. echo "### Oh no! Something bad happened. :("
  70. echo "### This output is in the log file: \"$logFile\""
  71. echo "### View log with: tail -n 300 \"$logFile\""
  72. echo "### The build failed."
  73. exit $?
  74. fi
  75. }
  76.  
  77. function ShowHelp
  78. {
  79. echo
  80. echo "Usage: $0 <branch name> <marketing version number> <customer code> <environment> <client type> <other option> [DebugMode option]"
  81. echo
  82. echo "Branch name - The git branch to build."
  83. echo "Marketing version number - Either 'update' to automatically increment the version or 'VERSION NUMBER' to use the specific version number (git tag)."
  84. echo "Customer code - Is one of: bfb, bushbeans, carbonsales, chobani, core, daisy, danone, directo, kcanada, lambweston, mk, pepsicosa"
  85. echo "Environment - Option is either: 'dev', 'test', 'demo', 'live', or 'all'."
  86. echo "Client type - Is either 'mc-iphone' for MarketCheck iPhone or 'mc' for MarketCheck iPad or 'sc' for SmartCall."
  87. echo "Other option - Is either: skip|cleanoldbinaries|clean|noclean|getsource|deployonly|deployskip"
  88. echo "DebugMode option - Is either 'true' or 'false'. If true then the script pauses for each task prompting to continue. Default is false."
  89. echo
  90. }
  91.  
  92. function DebugPause
  93. {
  94. if [ "$debugMode" == "true" ]; then
  95. echo "===>> DEBUG MODE Step through is on: Press enter to continue or false to continue without stopping again."
  96. read
  97. if [ "${REPLY}" == "false" ]; then
  98. $debugMode="false"
  99. fi
  100. fi
  101. }
  102.  
  103. # Removes any files and folders in the buildPath. Creaets buildPath if it does not exist.
  104. function BuildClean
  105. {
  106. echo
  107. echo "Task: Build Clean - Begin"
  108.  
  109. if [ -d "$buildPath" ]; then
  110. echo Removing directory $buildPath
  111. rm -rf "$buildPath"
  112. fi
  113.  
  114. echo Created the path $buildPath
  115. mkdir $buildPath
  116.  
  117. echo "Task: Build Clean - End"
  118. }
  119.  
  120. # Gets the files from Github
  121. function GetSourceFiles
  122. {
  123. echo
  124. echo "Task: Get Source Files - Begin"
  125.  
  126. if [[ -z $buildPath ]]
  127. then
  128. mkdir $buildPath && cd $buildPath
  129. else
  130. cd "$buildPath"
  131. fi
  132.  
  133. pwd
  134. IfError "cd into the project build directory error"
  135.  
  136. if [[ -z $projectName ]]
  137. then
  138. echo "Running: git clone https://github.com/rw3/$projectName.git"
  139. git clone https://github.com/rw3/$projectName.git
  140. IfError "Git clone error. If the error is about a broken pipe then the problem might be with the network or load on the github server. Please try again a few times before assuming the autobuild is broken."
  141.  
  142. cd "$projectName"
  143. IfError "cd into the project clone error"
  144.  
  145. echo "version number is: $versionNumber"
  146. echo "Getting branch: $branchName"
  147. git checkout $branchName
  148. IfError "git checkout error"
  149.  
  150. git pull origin $branchName
  151. IfError "git pull origin error"
  152.  
  153. echo "Task: Get Source Files - End"
  154. else
  155. cd "$projectName"
  156. IfError "cd into the project clone error"
  157.  
  158. echo "version number is: $versionNumber"
  159. echo "Getting branch: $branchName"
  160. git checkout $branchName .
  161. IfError "git checkout error"
  162.  
  163. git pull origin $branchName
  164. IfError "git pull origin error"
  165. fi
  166. }
  167.  
  168. # When we skip getting files to the build directory, call this function to change to the same folder that GetSourceFiles changes you into and leaves you in for next ssteps
  169. function ChangeDirToProjectPath
  170. {
  171. echo
  172. echo "Task: Change Dir To Project Path - Begin"
  173.  
  174. echo cd "$buildPath"
  175. cd "$buildPath"
  176. IfError "cd into the project build directory error"
  177.  
  178. echo cd "$projectName"
  179. cd "$projectName"
  180. IfError "cd into the project clone error"
  181.  
  182. echo "Task: Change Dir To Project Path - End"
  183. }
  184.  
  185. function GetLatestSource
  186. {
  187. echo
  188. echo "Task: Get Latest Source Files - Begin"
  189.  
  190. echo cd "$buildPath"
  191. cd "$buildPath"
  192. IfError "cd into the project build directory error"
  193.  
  194. echo cd "$projectName"
  195. cd "$projectName"
  196. IfError "cd into the project error"
  197.  
  198. echo pwd
  199. pwd
  200. IfError "get current directory error"
  201.  
  202. echo Running: git resest --hard HEAD
  203. git reset --hard HEAD
  204. IfError "git resest --hard HEAD failed"
  205.  
  206. echo Running: git clean -f
  207. git clean -f
  208. IfError "git clean -f failed"
  209.  
  210. echo Running: git fetch
  211. git fetch
  212. IfError "git fetch command failed"
  213.  
  214. echo "Checking potentially changed files: git checkout -f"
  215. git checkout -f
  216. IfError "git checkout error: git checkout -f"
  217.  
  218. echo "Version number is: $versionNumber"
  219. echo "git checkout $branchName"
  220. git checkout $branchName
  221. IfError "git checkout error"
  222.  
  223. echo "git pull origin $branchName"
  224. git pull origin $branchName
  225. IfError "git pull origin error"
  226.  
  227. echo "Task: Get Latest Source Files - End"
  228. }
  229.  
  230. function CleanOldBuildBinaries
  231. {
  232. echo
  233. echo "Task: Clean Local Build Binaries - Begin"
  234.  
  235. echo "cd into the buildPath: $buildPath"
  236. cd "$buildPath"
  237. IfError "cd into the project build directory error"
  238.  
  239. echo "cd into the projectName: $projectName"
  240. cd "$projectName"
  241. IfError "cd into the project clone error"
  242.  
  243. echo "Removing old build files: rm -f *.ipa *.plist *.dSYM.zip"
  244. rm -f *.ipa *.plist *.dSYM.zip
  245. IfError "Removing old build files failed."
  246.  
  247. echo "Task: Clean Local Build Binaries - End"
  248. }
  249.  
  250. function UpdateCustomerCode
  251. {
  252. echo
  253. echo "Task: Update Customer Code - Begin"
  254.  
  255. echo echo -e "\n#define CurrentCustomer $customerConstantCode"
  256. echo -e "\n#define CurrentCustomer $customerConstantCode" >> "$sourcePath/Carbon/Customer.h"
  257. IfError "Failed to update Customer.h."
  258.  
  259. echo tail -n 5 "$sourcePath/Carbon/Customer.h"
  260. echo "------"
  261. tail -n 5 "$sourcePath/Carbon/Customer.h"
  262. echo "------"
  263.  
  264. echo "Task: Update Customer Code - End"
  265. }
  266.  
  267. function UpdateVersionAndTagInGit
  268. {
  269. echo
  270. echo "Task: Update Version and Tag in Git - Begin"
  271.  
  272. # revert the CFBundleIdentifier for when building manually (debugging).
  273. echo $plistExe -c "Set CFBundleIdentifier \"com.rw3.\${Customer_Code}\${Environment}.\${Product_Code}\"" "$plistInfoFile"
  274. $plistExe -c "Set CFBundleIdentifier \"com.rw3.\${Customer_Code}\${Environment}.\${Product_Code}\"" "$plistInfoFile"
  275. IfError "plistbuddy could not set bundle ID"
  276.  
  277. echo git add "$plistInfoFile"
  278. git add "$plistInfoFile"
  279. IfError "Git add error"
  280.  
  281. echo git add -v Carbon.xcodeproj
  282. git add -v Carbon.xcodeproj
  283. IfError "Git add Carbon.xcodeproj error"
  284.  
  285. echo git commit -m "--- $newBundleVersion ($buildNumber) ---"
  286. git commit -m "--- $newBundleVersion ($buildNumber) ---"
  287. IfError "Git commit error"
  288.  
  289. echo git push origin $branchName
  290. git push origin $branchName
  291. IfError "Git push error"
  292.  
  293. echo git tag -a "v$newBundleVersion--$buildNumber" -m "version $newBundleVersion ($buildNumber)"
  294. git tag -a "v$newBundleVersion--$buildNumber" -m "version $newBundleVersion ($buildNumber)"
  295. IfError "Git add tag error"
  296.  
  297. echo git push origin $branchName --tags
  298. git push origin $branchName --tags
  299. IfError "Git push tags error"
  300.  
  301. echo "Task: Update Version and Tag in Git - End"
  302. }
  303.  
  304. function GetSpecifiedTag
  305. {
  306. echo
  307. echo "Task: Get Specified Tag from Git - Begin"
  308.  
  309. git add "$plistInfoFile"
  310. IfError "Git add error"
  311.  
  312. echo git add -v Carbon.xcodeproj
  313. git add -v Carbon.xcodeproj
  314. IfError "Git add Carbon.xcodeproj error"
  315.  
  316. git commit -m "--- $newBundleVersion ---"
  317. IfError "Git commit error"
  318.  
  319. git push origin $branchName
  320. IfError "Git push error"
  321.  
  322. git tag -a "v$newBundleVersion" -m "version $newBundleVersion"
  323. IfError "Git add tag error"
  324.  
  325. git push origin $branchName --tags
  326. IfError "Git push tags error"
  327.  
  328. echo "Task: Get Specified Tag from Git - End"
  329. }
  330.  
  331. function UpdateBundleID
  332. {
  333. echo
  334. echo "Task: Update Bundle ID - Begin"
  335.  
  336. if [ "$targetEnvironmentName" != "Live" ]; then
  337. environmentSubdomain=$(echo -$targetEnvironmentName | tr "[:upper:]" "[:lower:]") # converts to lowercase
  338. IfError "Convert target environment to lowercase failed."
  339. else
  340. environmentSubdomain=""
  341. fi
  342.  
  343. if [ "$fullBundleId" == "" ]; then
  344. if [ "$appIDPrefix" == "" ]; then
  345. bundleID="com.rw3.$customerLiveSubdomain$environmentSubdomain.$productCode"
  346. else
  347. bundleID="com.rw3.$appIDPrefix$environmentSubdomain.$productCode"
  348. fi
  349. else
  350. bundleID=$fullBundleId
  351. fi
  352. echo "Using the bundle ID: \"$bundleID\"."
  353. echo "Updating the plist: $plistInfoFile"
  354. $plistExe -c "Set CFBundleIdentifier \"$bundleID\"" "$plistInfoFile"
  355. IfError "plistbuddy could not set bundle ID"
  356.  
  357. echo "Task: Update BundleID - End"
  358. }
  359.  
  360. function TaskUpdateInPlistInfoFile
  361. {
  362. echo "==="
  363. echo "=== Task: Update Build Number - Begin"
  364.  
  365. echo "PlistInfoFilePath: $plistInfoFile"
  366.  
  367. updatePlistCmd="$plistExe -c \"Set CFBundleVersion \"$buildNumber\"\" \"$plistInfoFile\""
  368. echo "Running: $updatePlistCmd"
  369. eval $updatePlistCmd
  370. IfError "plistbuddy could not set bundle version"
  371.  
  372. echo "Task: Update Version - End"
  373. DebugPause
  374. }
  375.  
  376. function TaskGenerateBuildNumber
  377. {
  378. echo "==="
  379. echo "=== Task: Generate Build Number - Begin"
  380.  
  381. echo "Running: buildNumber=\$(date \"+%Y%m%d.%H%M%S\")"
  382. buildNumber=$(date "+%Y%m%d.%H%M%S")
  383. echo "Build number is: $buildNumber"
  384.  
  385. echo "Task: Generate Build Number - End"
  386. DebugPause
  387. }
  388.  
  389. function TaskGetCurrentMarketingVersion
  390. {
  391. echo "==="
  392. echo "=== Task: Get Current Marketing Version - Begin"
  393.  
  394. echo Running: xcodebuild -workspace "$workspace" -scheme "$targetName" -configuration "$ConfigurationName" -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION ='
  395. MarketingVersion=$(xcodebuild -workspace "$workspace" -scheme "$targetName" -configuration "$ConfigurationName" -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION =')
  396. IfError "Get current version via xcodebuild failed"
  397.  
  398. echo "Current version is: $MarketingVersion"
  399. if [ "$MarketingVersion" = "" ]; then
  400. echo "Marketing version not set."
  401. exit 1
  402. fi
  403.  
  404. echo "Task: Get Current Marketing Version - End"
  405. DebugPause
  406. }
  407.  
  408. function TaskGenerateMarketingVersion
  409. {
  410. echo "==="
  411. echo "=== Task: Generate Marketing Version - Begin"
  412.  
  413. echo "Current version is: $MarketingVersion"
  414. versionPartToIncrement="${MarketingVersion##*.}"
  415. versionFirstPart=${MarketingVersion%.*}
  416. newVersionEndPart=$((versionPartToIncrement+1))
  417. NewMarketingVersion="$versionFirstPart.$newVersionEndPart" # new version
  418. echo "Previous version '$MarketingVersion' new version '$NewMarketingVersion'"
  419.  
  420. echo "Task: Generate Marketing Version - End"
  421. DebugPause
  422. }
  423.  
  424. function TaskUpdateMarketingVersion
  425. {
  426. echo "==="
  427. echo "=== Task: Update Marketing Version - Begin"
  428.  
  429. echo sed -i '' -e "s/MARKETING_VERSION \= [^\;]*\;/MARKETING_VERSION = $NewMarketingVersion;/" $sourcePath/Carbon.xcodeproj/project.pbxproj
  430. sed -i '' -e "s/MARKETING_VERSION \= [^\;]*\;/MARKETING_VERSION = $NewMarketingVersion;/" $sourcePath/Carbon.xcodeproj/project.pbxproj
  431. IfError "Could not update MARKETING_VERSION"
  432.  
  433. echo "Task: Update Marketing Version - End"
  434. DebugPause
  435. }
  436.  
  437. function CreatePlist
  438. {
  439. echo
  440. echo "Task: Create Plist - Begin"
  441. plistFile="$resultFileName$targetEnvironmentName.plist"
  442.  
  443. if [ -e "$plistFile" ]; then
  444. echo "Removing \"$plistFile\""
  445. rm "$plistFile"
  446. IfError "rm $plistFile failed"
  447. fi
  448.  
  449. if [ "$clientType" == "mc" -o "$clientType" == "mc-iphone" ]; then
  450. clientUrlPathName="MarketCheck"
  451. else
  452. clientUrlPathName="SmartCall"
  453. fi
  454.  
  455. # if [ "$targetEnvironmentName" != "Live" ]; then
  456. # longAppName="$appName ($customerLiveSubdomain $newBundleVersion)"
  457. # IfError "Convert target environment to lowercase failed."
  458. # else
  459. # longAppName=$appName
  460. # fi
  461.  
  462. longAppName=$appName
  463.  
  464. ipaUrl="https://$customerLiveSubdomain$environmentSubdomain.rw3.com/download/$clientUrlPathName/versions/$newBundleVersion/$ipaFileName"
  465. echo "Created IPA file URL: $ipaUrl"
  466.  
  467. # document root
  468. plistCmds[0]="Add :items array"
  469. plistCmds[1]="Add :items:0 dict"
  470. plistCmds[2]="Add :items:0:assets array"
  471.  
  472. # app ipa
  473. plistCmds[3]="Add :items:0:assets:0 dict"
  474. plistCmds[4]="Add :items:0:assets:0:url string \\\"$ipaUrl\\\""
  475. plistCmds[5]="Add :items:0:assets:0:kind string software-package"
  476.  
  477. # meta data
  478. plistCmds[6]="Add :items:0:metadata dict"
  479. plistCmds[7]="Add :items:0:metadata:title string \\\"$longAppName\\\""
  480. plistCmds[8]="Add :items:0:metadata:kind string software"
  481. plistCmds[9]="Add :items:0:metadata:bundle-version string $newBundleVersion"
  482. plistCmds[10]="Add :items:0:metadata:bundle-identifier string $bundleID"
  483.  
  484. for cmd in ${!plistCmds[*]}; do
  485. plistCmd="$plistExe -c \"${plistCmds[$cmd]}\" \"$plistFile\""
  486. echo "Running: $plistCmd"
  487. eval $plistCmd
  488. IfError "Plistbuddy command failed"
  489. done
  490.  
  491. echo "Task: Create Plist - End"
  492. }
  493.  
  494. function CreateDeployFolder
  495. {
  496. echo "Create Deploy Folder"
  497.  
  498. ChangeDirToProjectPath
  499.  
  500. IFS='/' read -r customerFolder productFolder <<< "$dropFolderCustomer"
  501.  
  502. customerVersionPath="$customerFolder/$newBundleVersion"
  503. customerVersionEnvPath="$customerVersionPath/$targetEnvironmentName"
  504. customerVersionEnvDownloadPath="$customerVersionEnvPath/download"
  505. customerVersionEnvDownloadProductPath="$customerVersionEnvDownloadPath/$productFolder"
  506. customerVersionEnvDownloadProductVersionsPath="$customerVersionEnvDownloadProductPath/versions"
  507. customerVersionEnvDownloadProductVersionsThisVersionPath="$customerVersionEnvDownloadProductVersionsPath/$newBundleVersion"
  508.  
  509. echo "Customer version path: $customerVersionPath"
  510.  
  511. if [ -d "$customerVersionPath" ]; then
  512. echo "Clean $customerVersionPath: rm -rf $customerVersionPath"
  513. rm -rf "$customerVersionPath"
  514. fi
  515.  
  516. mkdir -p "$customerVersionPath"
  517. mkdir -p "$customerVersionEnvPath"
  518. mkdir -p "$customerVersionEnvDownloadPath"
  519. mkdir -p "$customerVersionEnvDownloadProductPath"
  520. mkdir -p "$customerVersionEnvDownloadProductVersionsPath"
  521. mkdir -p "$customerVersionEnvDownloadProductVersionsThisVersionPath"
  522.  
  523. plistFile="$resultFileName$targetEnvironmentName.plist"
  524. ipaFile="$resultFileName$targetEnvironmentName.ipa"
  525. dsymFile="$appName.app.dSYM.zip"
  526.  
  527. echo "Copying the .ipa file to the deploy folder."
  528. echo cp -v "$(pwd)/$ipaFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
  529. cp -v "$(pwd)/$ipaFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
  530. IfError "Copying .ipa file failed"
  531.  
  532. echo "Copying the .plist file to the deploy folder."
  533. echo cp -v "$(pwd)/$plistFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
  534. cp -v "$(pwd)/$plistFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
  535. IfError "Copying .plist file failed"
  536.  
  537. echo "Copying the .dsym file to the deploy folder."
  538. echo cp -v "$(pwd)/$dsymFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
  539. cp -v "$(pwd)/$dsymFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
  540. IfError "Copying .dsym file failed"
  541.  
  542. deployFolder="$workingPath/deploy_files"
  543. mainIndexTemplate="$deployFolder/index.html.template"
  544. #echo $mainIndexTemplate
  545.  
  546. smartcall_version="$newBundleVersion"
  547. marketcheck_version="$newBundleVersion"
  548. myyear=`date +'%Y'`
  549. mymonth=`date +'%b'`
  550. myday=`date +'%d'`
  551.  
  552. mycat="cat $deployFolder/header.template $deployFolder/startwebmodules.template"
  553. for webModule in $webModulesForPortal; do
  554. mycat="$mycat $deployFolder/$webModule.template"
  555. done
  556. mycat="$mycat $deployFolder/endwebmodules.template $deployFolder/startappmodules.template"
  557. for appModule in $appModulesForPortal; do
  558. mycat="$mycat $deployFolder/$appModule.template"
  559. done
  560. mycat="$mycat $deployFolder/endappmodules.template $deployFolder/footer.template"
  561.  
  562. mysed="$mycat |
  563. sed 's/#{PHONE}/$phone/g' |
  564. sed 's/#{MAILTO}/$mailto/g' |
  565. sed 's/#{SMARTCALL_VERSION}/$smartcall_version/g' |
  566. sed 's/#{MARKETCHECK_VERSION}/$marketcheck_version/g' |
  567. sed 's/#{COPYRIGHT_END_YEAR}/$myyear/g' > \"$customerVersionEnvPath/index.html\"
  568. "
  569. echo $mysed
  570. eval $mysed
  571. IfError "sed failed."
  572.  
  573. if [ "$targetEnvironmentName" != "Live" ]; then
  574. environmentSubdomain=$(echo -$targetEnvironmentName | tr "[:upper:]" "[:lower:]") # converts to lowercase
  575. IfError "Convert target environment to lowercase failed."
  576. else
  577. environmentSubdomain=""
  578. fi
  579.  
  580. urlPrefix="$customerLiveSubdomain$environmentSubdomain"
  581. buildDate="$mymonth $myday, $myyear"
  582. productIndexTemplate="$workingPath/deploy_files/$productFolder.index.html.template"
  583. #echo $urlPrefix
  584. #echo $buildDate
  585. #echo $productIndexTemplate
  586.  
  587. mysed="sed 's/#{PHONE}/$phone/g' $productIndexTemplate |
  588. sed 's/#{MAILTO}/$mailto/g' |
  589. sed 's/#{BUILD_DATE}/$buildDate/g' |
  590. sed 's/#{URL_PREFIX}/$urlPrefix/g' |
  591. sed 's/#{PLIST_FILE}/$plistFile/g' |
  592. sed 's/#{SMARTCALL_VERSION}/$smartcall_version/g' |
  593. sed 's/#{MARKETCHECK_VERSION}/$marketcheck_version/g' |
  594. sed 's/#{COPYRIGHT_END_YEAR}/$myyear/g' > \"$customerVersionEnvDownloadProductPath/index.html\"
  595. "
  596. echo $mysed
  597. eval $mysed
  598. IfError "sed failed."
  599. }
  600.  
  601. function UploadNewVersionToAppCenter
  602. {
  603. echo
  604. echo "Task: Upload New Version to AppCenter - Begin"
  605.  
  606. echo Running: appcenter crashes upload-symbols -s "$1" --app "$appCenterName" --token "e2a3de01e07ba1eff16146835125f8dba5e5d6b2"
  607. appcenter crashes upload-symbols -s "$1" --app "$appCenterName" --token "e2a3de01e07ba1eff16146835125f8dba5e5d6b2"
  608. IfError "Upload to AppCenter failed"
  609.  
  610. echo "Task: Upload New Version to AppCenter - End"
  611. }
  612.  
  613. # Create the archive
  614. # Assumption: The output .app file name is the target name.
  615. function ArchiveTarget
  616. {
  617. echo
  618. echo "Task: Archive Target - Begin"
  619. payloadDirectory="Payload"
  620.  
  621. if [ -d "$payloadDirectory" ]; then
  622. rm -r "$payloadDirectory"
  623. fi
  624.  
  625. mkdir "$payloadDirectory"
  626. IfError "mkdir $payloadDirectory failed"
  627.  
  628. #cp -r "build/$configurationName-iphoneos/Products/$configurationName-iphoneos/$appName.app" "$payloadDirectory"
  629. cp -r "build/$configurationName-iphoneos/$appName.app" "$payloadDirectory"
  630. IfError "copying the files to the $payloadDirectory failed."
  631.  
  632. ipaFileName="$resultFileName$targetEnvironmentName.ipa"
  633. zip -r "$ipaFileName" "$payloadDirectory"
  634. IfError "zipping the files into a ipa failed."
  635.  
  636. # copy the dsym directory so we have all files in the same directory.
  637. #cp -r "build/$configurationName-iphoneos/Products/$configurationName-iphoneos/$appName.app.dSYM" .
  638. cp -r "build/$configurationName-iphoneos/$appName.app.dSYM" .
  639. IfError "Copying the dSYM file failed"
  640.  
  641. # Zip the dSYM files since this is necessary for copying them to AppCenter anyway.
  642. echo "Zipping the dSYM files."
  643. zip -r "$appName.app.dSYM.zip" "$appName.app.dSYM"
  644. IfError "zipping the dSYM file $appName.app.dSYM failed."
  645.  
  646. if [ $doUploadToAppCenter -eq 1 ]; then
  647. echo "Upload the files to AppCenter"
  648. currentPath=$(pwd)
  649. UploadNewVersionToAppCenter "$currentPath/$appName.app.dSYM.zip"
  650. else
  651. echo "Skip uploading files to AppCenter"
  652. fi
  653.  
  654. echo "Task: Archive Target - End"
  655. }
  656.  
  657. function BuildProject
  658. {
  659. echo
  660. echo "Task: Build Project - Begin"
  661.  
  662. cd "$buildPath/$projectName"
  663. IfError "cd into the project directory error"
  664.  
  665. if [[ "$environment" == "dev" || "$environment" == "all" ]]; then
  666. GetDevConfig
  667. if [ $doBuild -eq 1 ]; then
  668. BuildTarget
  669. fi
  670. fi
  671.  
  672. if [[ "$environment" == "test" || "$environment" == "all" ]]; then
  673. GetTestConfig
  674. if [ $doBuild -eq 1 ]; then
  675. BuildTarget
  676. fi
  677. fi
  678.  
  679. if [[ "$environment" == "demo" || "$environment" == "all" ]]; then
  680. GetLiveAppStoreConfig
  681. if [ $doBuild -eq 1 ]; then
  682. BuildTarget
  683. fi
  684. fi
  685.  
  686. if [[ "$environment" == "live" || "$environment" == "all" ]]; then
  687. GetLiveConfig
  688. if [ $doBuild -eq 1 ]; then
  689. BuildTarget
  690. fi
  691. fi
  692.  
  693. echo "Task: Build Project - End"
  694. }
  695.  
  696. function BuildTarget
  697. {
  698. echo
  699. echo "Task: Build Target \"$targetName\" - Begin"
  700. echo "Customer Live Subdomain: $customerLiveSubdomain"
  701. echo "Product Code: $productCode"
  702. echo "Configuration: $configurationName"
  703. UpdateBundleID
  704.  
  705. ssl=""
  706. if [ $useSSL -eq 1 ]; then
  707. echo "Setting SSL flag"
  708. ssl=" USE_SSL"
  709. fi
  710.  
  711. upc=""
  712. if [ $displayUPCControls -eq 1 ]; then
  713. echo "Setting UPC flag"
  714. upc=" UPC_SCANNING_ENABLED"
  715. fi
  716.  
  717. # Likely don't need this but leaving it here just in case someone needs to copy and paste in terminal.
  718. # echo "Selecting Xcode path."
  719. # echo $sudoPassword | sudo -S xcode-select -s "$xcodePath"
  720.  
  721. if [ -z "$workspace" ]; then
  722. echo "Workspace is empty."
  723. if [ "$provisioningProfileID" = "" ]; then
  724. xcodebuild -target "$targetName" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID clean
  725. xcodebuild -target "$targetName" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID
  726. else
  727. xcodebuild -target "$targetName" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID clean
  728. xcodebuild -target "$targetName" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID
  729. fi
  730. else
  731. echo "Building from workspace"
  732. echo $workspace
  733. mybuilddirraw=$buildPath/$projectName/build
  734. mybuilddir=$buildPath/$projectName/build/$configurationName-iphoneos
  735. deriveddatadir=$mybuilddir/DerivedData
  736.  
  737. echo "Build folder raw: $mybuilddirraw"
  738. echo "Build folder: $mybuilddir"
  739. echo "Derived data folder: $deriveddatadir"
  740.  
  741. if [ -e "$mybuilddirraw" ]; then
  742. echo Removing build folder: rm -rf "$mybuilddirraw"
  743. rm -rf "$mybuilddirraw"
  744. IfError "rm $mybuilddirraw failed"
  745. fi
  746.  
  747. if [ "$provisioningProfileID" = "" ]; then
  748. echo "Building without provisioning profile ID"
  749. xcodebuild -workspace "$workspace" -scheme "$targetName" -derivedDataPath "$deriveddatadir" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID MODULE_CACHE_DIR=$deriveddatadir/ModuleCache OBJROOT=$mybuilddir/Intermediates SHARED_PRECOMPS_DIR=$mybuilddir/Intermediates/PrecompiledHeaders clean
  750.  
  751. xcodebuild -workspace "$workspace" -scheme "$targetName" -derivedDataPath "$deriveddatadir" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID MODULE_CACHE_DIR=$deriveddatadir/ModuleCache OBJROOT=$mybuilddir/Intermediates SHARED_PRECOMPS_DIR=$mybuilddir/Intermediates/PrecompiledHeaders SYMROOT=$mybuilddirraw
  752. else
  753. echo "Building with provisioning profile ID $provisioningProfileID"
  754. xcodebuild -workspace "$workspace" -scheme "$targetName" -derivedDataPath "$deriveddatadir" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID MODULE_CACHE_DIR=$deriveddatadir/ModuleCache OBJROOT=$mybuilddir/Intermediates SHARED_PRECOMPS_DIR=$mybuilddir/Intermediates/PrecompiledHeaders clean
  755.  
  756. xcodebuild -workspace "$workspace" -scheme "$targetName" -derivedDataPath "$deriveddatadir" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID MODULE_CACHE_DIR=$deriveddatadir/ModuleCache OBJROOT=$mybuilddir/Intermediates SHARED_PRECOMPS_DIR=$mybuilddir/Intermediates/PrecompiledHeaders SYMROOT=$mybuilddirraw
  757. fi
  758. fi
  759.  
  760. IfError "Build failed"
  761.  
  762. ArchiveTarget
  763. CreatePlist
  764. CreateDeployFolder
  765. IfError "Copying files to the drop folder failed"
  766.  
  767. echo "Task: Build Target \"$targetName\" - End"
  768. }
  769.  
  770. function CopyDeployFolderToDropFolder
  771. {
  772. echo
  773. echo "Task: Copy Deploy Folder to Drop Folder - Begin"
  774.  
  775. # Make sure we in the project build path
  776. ChangeDirToProjectPath
  777.  
  778. IFS='/' read -r customerFolder productFolder <<< "$dropFolderCustomer"
  779. dropCustomerFullPath="$dropFolderPath/$customerFolder"
  780. customerVersionPath="$customerFolder/$newBundleVersion"
  781.  
  782. # Ensure the drop folder is mounted.
  783. if [ ! -d "$dropFolderPath" ]; then
  784. echo "It appears the drop folder ($dropFolderPath) is not mounted. Please mount the UNC path first: $dropFolderMountUncPath"
  785. echo -e -n "\nPress R to Retry after mounting the share or C to Cancel."
  786. read -n 1 reply
  787. echo
  788. if [[ $reply =~ ^[Rr]$ ]]; then
  789. CopyDeployFolderToDropFolder
  790. return 0
  791. else
  792. return 1
  793. fi
  794. fi
  795.  
  796. if [ ! -d "$dropCustomerFullPath" ]; then
  797. echo "Create client drop folder: $dropCustomerFullPath"
  798. echo mkdir "$dropCustomerFullPath"
  799. mkdir "$dropCustomerFullPath"
  800. fi
  801. IfError "Failed creating $dropCustomerFullPath"
  802.  
  803. echo "Copying deploy folder to the drop folder."
  804. mycmd="cp -Rv \"$customerVersionPath\" \"$dropCustomerFullPath\""
  805. echo $mycmd
  806. eval $mycmd
  807. IfError "Copying deploy folder failed"
  808.  
  809. echo "Task: Copy Deploy Folder to Drop Folder - End"
  810. }
  811.  
  812. function main
  813. {
  814. if [ "$branchName" == "" ]; then
  815. echo "Invalid <branch name> argument: $branchName"
  816. ShowHelp
  817. return 1
  818. fi
  819.  
  820. if [ "$versionNumber" == "" ]; then
  821. echo "Invalid <update marketing version> argument: $versionNumber"
  822. ShowHelp
  823. return 1
  824. fi
  825.  
  826. if ! [[ "$clientType" =~ ^(sc|mc|mc-iphone)$ ]]; then
  827. echo "Invalid <client type> argument: $clientType"
  828. ShowHelp
  829. return 1
  830. fi
  831.  
  832. if ! [[ "$customerCode" =~ ^(bfb|bushbeans|carbonsales|chobani|core|daisy|danone|directo|kcanada|lambweston|mk|pepsicosa)$ ]]; then
  833. echo "Invalid <customer code> argument: $customerCode"
  834. ShowHelp
  835. return 1
  836. fi
  837.  
  838. if [ "$environment" == "" ]; then
  839. echo "Invalid <environment> argument: $environment"
  840. ShowHelp
  841. return 1
  842. fi
  843.  
  844. if ! [[ "$environment" =~ ^(dev|test|demo|live|all)$ ]]; then
  845. echo "Invalid <environment> argument: $environment"
  846. ShowHelp
  847. return 1
  848. fi
  849.  
  850. if [ "$otherOption" == "" ]; then
  851. otherOption="noclean"
  852. fi
  853.  
  854. if ! [[ "$otherOption" =~ ^(skip|cleanoldbinaries|clean|noclean|getsource|deployonly|deployskip)$ ]]; then
  855. echo "Invalid <other option> argument: $otherOption"
  856. ShowHelp
  857. return 1
  858. fi
  859.  
  860. if ! [[ "$debugMode" =~ ^(false|true)$ ]]; then
  861. echo Invalid [DebugMode option] argument: $DebugMode
  862. ShowHelp
  863. return 1
  864. fi
  865.  
  866. if [ "$clientType" != "mc" -o "$clientType" != "mc-iphone" -o "$clientType" != "sc" ]; then
  867. echo "The <client_type> is either mc for MarketCheck or sc for SmartCall."
  868. fi
  869.  
  870. if [ "$clientType" == "sc" ]; then
  871. resultFileName="SmartCall"
  872. fi
  873.  
  874. buildProjectFile="Build/${customerCode}_${clientType}.proj"
  875. echo source "$buildProjectFile"
  876. source "$buildProjectFile"
  877. IfError "Could not open the project file '$buildProjectFile'."
  878.  
  879. if [ "$environment" == "dev" ]; then
  880. GetDevConfig
  881. elif [ "$environment" == "test" ]; then
  882. GetTestConfig
  883. elif [ "$environment" == "demo" ]; then
  884. GetLiveAppStoreConfig
  885. elif [ "$environment" == "live" ]; then
  886. GetLiveConfig
  887. fi
  888.  
  889. echo "----------------------------------------------------------------"
  890. echo "Customer constant code: $customerConstantCode"
  891. echo "Branch: $branchName"
  892. echo "Customer Code: \"$customerCode\""
  893. echo "Project File: \"$buildProjectFile\""
  894. echo "Version: $versionNumber"
  895. echo "Target Name: $targetName"
  896. echo "Client Type: $clientType"
  897. echo "Environment: $environment"
  898. echo "Other Option: $otherOption"
  899. echo "Build Path: $buildPath"
  900. echo "Log File: $logFile"
  901. workingPath=$(pwd)
  902. echo "Working path: $workingPath"
  903. echo "----------------------------------------------------------------"
  904.  
  905. if [ "$clientType" == "mc" ]; then
  906. plistInfoFile="$sourcePath/Carbon/MarketCheck-Info.plist"
  907. elif [ "$clientType" == "mc-iphone" ]; then
  908. plistInfoFile="$sourcePath/Carbon/MarketCheckIphone-Info.plist"
  909. else
  910. plistInfoFile="$sourcePath/Carbon/SmartCall-Info.plist"
  911. fi
  912.  
  913. if [ "$otherOption" == "skip" ]; then
  914. echo "Skipping checkout, but changing dir to project path"
  915. ChangeDirToProjectPath
  916. elif [ "$otherOption" == "cleanoldbinaries" ]; then
  917. CleanOldBuildBinaries
  918. elif [ "$otherOption" == "clean" ]; then
  919. BuildClean
  920. elif [ "$otherOption" == "noclean" ]; then
  921. GetLatestSource
  922. elif [ "$otherOption" == "getsource" ]; then
  923. GetSourceFiles
  924. elif [ "$otherOption" == "deployonly" ]; then
  925. NewMarketingVersion=$versionNumber
  926. newBundleVersion=$versionNumber
  927. CopyDeployFolderToDropFolder
  928. echo "### Done. The deployment was successful."
  929. return;
  930. fi
  931.  
  932. TaskGenerateBuildNumber
  933.  
  934. if [ "$versionNumber" == "update" ]; then
  935. TaskGetCurrentMarketingVersion
  936. TaskGenerateMarketingVersion
  937.  
  938. newBundleVersion=$NewMarketingVersion
  939.  
  940. TaskUpdateInPlistInfoFile
  941. TaskUpdateMarketingVersion
  942. else
  943. NewMarketingVersion=$versionNumber
  944. newBundleVersion=$versionNumber
  945.  
  946. TaskUpdateInPlistInfoFile
  947. TaskUpdateMarketingVersion
  948. fi
  949.  
  950. UpdateCustomerCode
  951. BuildProject
  952.  
  953. if [ "$versionNumber" == "update" ]; then
  954. UpdateVersionAndTagInGit
  955. fi
  956.  
  957. if [ "$otherOption" <> "deployskip" ]; then
  958. CopyDeployFolderToDropFolder
  959. fi
  960.  
  961. echo
  962. echo "### Done. The build was successful."
  963. echo
  964. }
  965.  
  966. # Runs the script and logs to the specified file.
  967. main | tee -a "$logFile"
  968.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement