Advertisement
Badal_hs_shah

Untitled

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