Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # 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.
- #
- # Revisions:
- # bseelig 2020-09-04
- #
- branchName=$1
- versionNumber=$2
- customerCode=$3
- environment=$4
- clientType=$5
- otherOption=$6
- debugMode=$7
- logFile=$(date "+$HOME/autobuilds/${customerCode} ${clientType} %Y-%m-%d %H.%M.%S.log")
- 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.
- dropFolderPath="/Volumes/drop"
- buildNumber=""
- bundleID=""
- newBundleVersion=""
- plistExe="/usr/libexec/plistbuddy"
- plistInfoFile=""
- ipaUrl=""
- environmentSubdomain=""
- ipaFileName=""
- workingPath=""
- resultFileName="MarketCheck"
- workspace="Carbon.xcworkspace"
- buildProjectFile=""
- # Build .proj file overwrite. These values should be overwritten by the customer build project file.
- webModulesForPortal="accountmanager accountmessenger admin" #Add in order you want them to appear top to bottom, left to right
- appModulesForPortal="" #Add in order you want them to appear top to bottom, on right hand side (usually smartcallapp first, then marketcheckapp)
- phone="555-1212"
- mailto="helpdesk@rw3.com"
- projectName="Carbon"
- buildPath="$HOME/autobuilds/Carbon"
- sourcePath="$buildPath/Carbon"
- configurationName=""
- targetName=""
- appName=""
- targetEnvironmentName=""
- productCode=""
- customerLiveSubdomain=""
- appIDPrefix=""
- customerConstantCode=""
- doBuild=1
- doUploadToAppCenter=0
- dropFolderCustomer=""
- useSSL=0
- provisioningProfileID=""
- developmentTeamID=""
- displayUPCControls=0
- appCenterName=""
- echo "Command line was: $0 $1 $2 $3 $4 $5 $6 $7 $8 $9"
- if [ "$debugMode" == "" ]; then
- debugMode="false"
- fi
- # Parameter 1: Error message, is a message about the error.
- function IfError
- {
- if [[ $? -ne 0 ]]; then # check return code passed to function
- echo $(date "+[%Y-%m-%d %H:%M:%S]") "$1" # if rc > 0 then print error msg and quit
- echo
- echo "### Oh no! Something bad happened. :("
- echo "### This output is in the log file: \"$logFile\""
- echo "### View log with: tail -n 300 \"$logFile\""
- echo "### The build failed."
- exit $?
- fi
- }
- function ShowHelp
- {
- echo
- echo "Usage: $0 <branch name> <marketing version number> <customer code> <environment> <client type> <other option> [DebugMode option]"
- echo
- echo "Branch name - The git branch to build."
- echo "Marketing version number - Either 'update' to automatically increment the version or 'VERSION NUMBER' to use the specific version number (git tag)."
- echo "Customer code - Is one of: bfb, bushbeans, carbonsales, chobani, core, daisy, danone, directo, kcanada, lambweston, mk, pepsicosa"
- echo "Environment - Option is either: 'dev', 'test', 'demo', 'live', or 'all'."
- echo "Client type - Is either 'mc-iphone' for MarketCheck iPhone or 'mc' for MarketCheck iPad or 'sc' for SmartCall."
- echo "Other option - Is either: skip|cleanoldbinaries|clean|noclean|getsource|deployonly|deployskip"
- echo "DebugMode option - Is either 'true' or 'false'. If true then the script pauses for each task prompting to continue. Default is false."
- echo
- }
- function DebugPause
- {
- if [ "$debugMode" == "true" ]; then
- echo "===>> DEBUG MODE Step through is on: Press enter to continue or false to continue without stopping again."
- read
- if [ "${REPLY}" == "false" ]; then
- $debugMode="false"
- fi
- fi
- }
- # Removes any files and folders in the buildPath. Creaets buildPath if it does not exist.
- function BuildClean
- {
- echo
- echo "Task: Build Clean - Begin"
- if [ -d "$buildPath" ]; then
- echo Removing directory $buildPath
- rm -rf "$buildPath"
- fi
- echo Created the path $buildPath
- mkdir $buildPath
- echo "Task: Build Clean - End"
- }
- # Gets the files from Github
- function GetSourceFiles
- {
- echo
- echo "Task: Get Source Files - Begin"
- if [[ -z $buildPath ]]
- then
- mkdir $buildPath && cd $buildPath
- else
- cd "$buildPath"
- fi
- pwd
- IfError "cd into the project build directory error"
- if [[ -z $projectName ]]
- then
- echo "Running: git clone https://github.com/rw3/$projectName.git"
- git clone https://github.com/rw3/$projectName.git
- 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."
- cd "$projectName"
- IfError "cd into the project clone error"
- echo "version number is: $versionNumber"
- echo "Getting branch: $branchName"
- git checkout $branchName
- IfError "git checkout error"
- git pull origin $branchName
- IfError "git pull origin error"
- echo "Task: Get Source Files - End"
- else
- cd "$projectName"
- IfError "cd into the project clone error"
- echo "version number is: $versionNumber"
- echo "Getting branch: $branchName"
- git checkout $branchName .
- IfError "git checkout error"
- git pull origin $branchName
- IfError "git pull origin error"
- fi
- }
- # 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
- function ChangeDirToProjectPath
- {
- echo
- echo "Task: Change Dir To Project Path - Begin"
- echo cd "$buildPath"
- cd "$buildPath"
- IfError "cd into the project build directory error"
- echo cd "$projectName"
- cd "$projectName"
- IfError "cd into the project clone error"
- echo "Task: Change Dir To Project Path - End"
- }
- function GetLatestSource
- {
- echo
- echo "Task: Get Latest Source Files - Begin"
- echo cd "$buildPath"
- cd "$buildPath"
- IfError "cd into the project build directory error"
- echo cd "$projectName"
- cd "$projectName"
- IfError "cd into the project error"
- echo pwd
- pwd
- IfError "get current directory error"
- echo Running: git resest --hard HEAD
- git reset --hard HEAD
- IfError "git resest --hard HEAD failed"
- echo Running: git clean -f
- git clean -f
- IfError "git clean -f failed"
- echo Running: git fetch
- git fetch
- IfError "git fetch command failed"
- echo "Checking potentially changed files: git checkout -f"
- git checkout -f
- IfError "git checkout error: git checkout -f"
- echo "Version number is: $versionNumber"
- echo "git checkout $branchName"
- git checkout $branchName
- IfError "git checkout error"
- echo "git pull origin $branchName"
- git pull origin $branchName
- IfError "git pull origin error"
- echo "Task: Get Latest Source Files - End"
- }
- function CleanOldBuildBinaries
- {
- echo
- echo "Task: Clean Local Build Binaries - Begin"
- echo "cd into the buildPath: $buildPath"
- cd "$buildPath"
- IfError "cd into the project build directory error"
- echo "cd into the projectName: $projectName"
- cd "$projectName"
- IfError "cd into the project clone error"
- echo "Removing old build files: rm -f *.ipa *.plist *.dSYM.zip"
- rm -f *.ipa *.plist *.dSYM.zip
- IfError "Removing old build files failed."
- echo "Task: Clean Local Build Binaries - End"
- }
- function UpdateCustomerCode
- {
- echo
- echo "Task: Update Customer Code - Begin"
- echo echo -e "\n#define CurrentCustomer $customerConstantCode"
- echo -e "\n#define CurrentCustomer $customerConstantCode" >> "$sourcePath/Carbon/Customer.h"
- IfError "Failed to update Customer.h."
- echo tail -n 5 "$sourcePath/Carbon/Customer.h"
- echo "------"
- tail -n 5 "$sourcePath/Carbon/Customer.h"
- echo "------"
- echo "Task: Update Customer Code - End"
- }
- function UpdateVersionAndTagInGit
- {
- echo
- echo "Task: Update Version and Tag in Git - Begin"
- # revert the CFBundleIdentifier for when building manually (debugging).
- echo $plistExe -c "Set CFBundleIdentifier \"com.rw3.\${Customer_Code}\${Environment}.\${Product_Code}\"" "$plistInfoFile"
- $plistExe -c "Set CFBundleIdentifier \"com.rw3.\${Customer_Code}\${Environment}.\${Product_Code}\"" "$plistInfoFile"
- IfError "plistbuddy could not set bundle ID"
- echo git add "$plistInfoFile"
- git add "$plistInfoFile"
- IfError "Git add error"
- echo git add -v Carbon.xcodeproj
- git add -v Carbon.xcodeproj
- IfError "Git add Carbon.xcodeproj error"
- echo git commit -m "--- $newBundleVersion ($buildNumber) ---"
- git commit -m "--- $newBundleVersion ($buildNumber) ---"
- IfError "Git commit error"
- echo git push origin $branchName
- git push origin $branchName
- IfError "Git push error"
- echo git tag -a "v$newBundleVersion--$buildNumber" -m "version $newBundleVersion ($buildNumber)"
- git tag -a "v$newBundleVersion--$buildNumber" -m "version $newBundleVersion ($buildNumber)"
- IfError "Git add tag error"
- echo git push origin $branchName --tags
- git push origin $branchName --tags
- IfError "Git push tags error"
- echo "Task: Update Version and Tag in Git - End"
- }
- function GetSpecifiedTag
- {
- echo
- echo "Task: Get Specified Tag from Git - Begin"
- git add "$plistInfoFile"
- IfError "Git add error"
- echo git add -v Carbon.xcodeproj
- git add -v Carbon.xcodeproj
- IfError "Git add Carbon.xcodeproj error"
- git commit -m "--- $newBundleVersion ---"
- IfError "Git commit error"
- git push origin $branchName
- IfError "Git push error"
- git tag -a "v$newBundleVersion" -m "version $newBundleVersion"
- IfError "Git add tag error"
- git push origin $branchName --tags
- IfError "Git push tags error"
- echo "Task: Get Specified Tag from Git - End"
- }
- function UpdateBundleID
- {
- echo
- echo "Task: Update Bundle ID - Begin"
- if [ "$targetEnvironmentName" != "Live" ]; then
- environmentSubdomain=$(echo -$targetEnvironmentName | tr "[:upper:]" "[:lower:]") # converts to lowercase
- IfError "Convert target environment to lowercase failed."
- else
- environmentSubdomain=""
- fi
- if [ "$fullBundleId" == "" ]; then
- if [ "$appIDPrefix" == "" ]; then
- bundleID="com.rw3.$customerLiveSubdomain$environmentSubdomain.$productCode"
- else
- bundleID="com.rw3.$appIDPrefix$environmentSubdomain.$productCode"
- fi
- else
- bundleID=$fullBundleId
- fi
- echo "Using the bundle ID: \"$bundleID\"."
- echo "Updating the plist: $plistInfoFile"
- $plistExe -c "Set CFBundleIdentifier \"$bundleID\"" "$plistInfoFile"
- IfError "plistbuddy could not set bundle ID"
- echo "Task: Update BundleID - End"
- }
- function TaskUpdateInPlistInfoFile
- {
- echo "==="
- echo "=== Task: Update Build Number - Begin"
- echo "PlistInfoFilePath: $plistInfoFile"
- updatePlistCmd="$plistExe -c \"Set CFBundleVersion \"$buildNumber\"\" \"$plistInfoFile\""
- echo "Running: $updatePlistCmd"
- eval $updatePlistCmd
- IfError "plistbuddy could not set bundle version"
- echo "Task: Update Version - End"
- DebugPause
- }
- function TaskGenerateBuildNumber
- {
- echo "==="
- echo "=== Task: Generate Build Number - Begin"
- echo "Running: buildNumber=\$(date \"+%Y%m%d.%H%M%S\")"
- buildNumber=$(date "+%Y%m%d.%H%M%S")
- echo "Build number is: $buildNumber"
- echo "Task: Generate Build Number - End"
- DebugPause
- }
- function TaskGetCurrentMarketingVersion
- {
- echo "==="
- echo "=== Task: Get Current Marketing Version - Begin"
- echo Running: xcodebuild -workspace "$workspace" -scheme "$targetName" -configuration "$ConfigurationName" -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION ='
- MarketingVersion=$(xcodebuild -workspace "$workspace" -scheme "$targetName" -configuration "$ConfigurationName" -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION =')
- IfError "Get current version via xcodebuild failed"
- echo "Current version is: $MarketingVersion"
- if [ "$MarketingVersion" = "" ]; then
- echo "Marketing version not set."
- exit 1
- fi
- echo "Task: Get Current Marketing Version - End"
- DebugPause
- }
- function TaskGenerateMarketingVersion
- {
- echo "==="
- echo "=== Task: Generate Marketing Version - Begin"
- echo "Current version is: $MarketingVersion"
- versionPartToIncrement="${MarketingVersion##*.}"
- versionFirstPart=${MarketingVersion%.*}
- newVersionEndPart=$((versionPartToIncrement+1))
- NewMarketingVersion="$versionFirstPart.$newVersionEndPart" # new version
- echo "Previous version '$MarketingVersion' new version '$NewMarketingVersion'"
- echo "Task: Generate Marketing Version - End"
- DebugPause
- }
- function TaskUpdateMarketingVersion
- {
- echo "==="
- echo "=== Task: Update Marketing Version - Begin"
- echo sed -i '' -e "s/MARKETING_VERSION \= [^\;]*\;/MARKETING_VERSION = $NewMarketingVersion;/" $sourcePath/Carbon.xcodeproj/project.pbxproj
- sed -i '' -e "s/MARKETING_VERSION \= [^\;]*\;/MARKETING_VERSION = $NewMarketingVersion;/" $sourcePath/Carbon.xcodeproj/project.pbxproj
- IfError "Could not update MARKETING_VERSION"
- echo "Task: Update Marketing Version - End"
- DebugPause
- }
- function CreatePlist
- {
- echo
- echo "Task: Create Plist - Begin"
- plistFile="$resultFileName$targetEnvironmentName.plist"
- if [ -e "$plistFile" ]; then
- echo "Removing \"$plistFile\""
- rm "$plistFile"
- IfError "rm $plistFile failed"
- fi
- if [ "$clientType" == "mc" -o "$clientType" == "mc-iphone" ]; then
- clientUrlPathName="MarketCheck"
- else
- clientUrlPathName="SmartCall"
- fi
- # if [ "$targetEnvironmentName" != "Live" ]; then
- # longAppName="$appName ($customerLiveSubdomain $newBundleVersion)"
- # IfError "Convert target environment to lowercase failed."
- # else
- # longAppName=$appName
- # fi
- longAppName=$appName
- ipaUrl="https://$customerLiveSubdomain$environmentSubdomain.rw3.com/download/$clientUrlPathName/versions/$newBundleVersion/$ipaFileName"
- echo "Created IPA file URL: $ipaUrl"
- # document root
- plistCmds[0]="Add :items array"
- plistCmds[1]="Add :items:0 dict"
- plistCmds[2]="Add :items:0:assets array"
- # app ipa
- plistCmds[3]="Add :items:0:assets:0 dict"
- plistCmds[4]="Add :items:0:assets:0:url string \\\"$ipaUrl\\\""
- plistCmds[5]="Add :items:0:assets:0:kind string software-package"
- # meta data
- plistCmds[6]="Add :items:0:metadata dict"
- plistCmds[7]="Add :items:0:metadata:title string \\\"$longAppName\\\""
- plistCmds[8]="Add :items:0:metadata:kind string software"
- plistCmds[9]="Add :items:0:metadata:bundle-version string $newBundleVersion"
- plistCmds[10]="Add :items:0:metadata:bundle-identifier string $bundleID"
- for cmd in ${!plistCmds[*]}; do
- plistCmd="$plistExe -c \"${plistCmds[$cmd]}\" \"$plistFile\""
- echo "Running: $plistCmd"
- eval $plistCmd
- IfError "Plistbuddy command failed"
- done
- echo "Task: Create Plist - End"
- }
- function CreateDeployFolder
- {
- echo "Create Deploy Folder"
- ChangeDirToProjectPath
- IFS='/' read -r customerFolder productFolder <<< "$dropFolderCustomer"
- customerVersionPath="$customerFolder/$newBundleVersion"
- customerVersionEnvPath="$customerVersionPath/$targetEnvironmentName"
- customerVersionEnvDownloadPath="$customerVersionEnvPath/download"
- customerVersionEnvDownloadProductPath="$customerVersionEnvDownloadPath/$productFolder"
- customerVersionEnvDownloadProductVersionsPath="$customerVersionEnvDownloadProductPath/versions"
- customerVersionEnvDownloadProductVersionsThisVersionPath="$customerVersionEnvDownloadProductVersionsPath/$newBundleVersion"
- echo "Customer version path: $customerVersionPath"
- if [ -d "$customerVersionPath" ]; then
- echo "Clean $customerVersionPath: rm -rf $customerVersionPath"
- rm -rf "$customerVersionPath"
- fi
- mkdir -p "$customerVersionPath"
- mkdir -p "$customerVersionEnvPath"
- mkdir -p "$customerVersionEnvDownloadPath"
- mkdir -p "$customerVersionEnvDownloadProductPath"
- mkdir -p "$customerVersionEnvDownloadProductVersionsPath"
- mkdir -p "$customerVersionEnvDownloadProductVersionsThisVersionPath"
- plistFile="$resultFileName$targetEnvironmentName.plist"
- ipaFile="$resultFileName$targetEnvironmentName.ipa"
- dsymFile="$appName.app.dSYM.zip"
- echo "Copying the .ipa file to the deploy folder."
- echo cp -v "$(pwd)/$ipaFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
- cp -v "$(pwd)/$ipaFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
- IfError "Copying .ipa file failed"
- echo "Copying the .plist file to the deploy folder."
- echo cp -v "$(pwd)/$plistFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
- cp -v "$(pwd)/$plistFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
- IfError "Copying .plist file failed"
- echo "Copying the .dsym file to the deploy folder."
- echo cp -v "$(pwd)/$dsymFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
- cp -v "$(pwd)/$dsymFile" "$customerVersionEnvDownloadProductVersionsThisVersionPath"
- IfError "Copying .dsym file failed"
- deployFolder="$workingPath/deploy_files"
- mainIndexTemplate="$deployFolder/index.html.template"
- #echo $mainIndexTemplate
- smartcall_version="$newBundleVersion"
- marketcheck_version="$newBundleVersion"
- myyear=`date +'%Y'`
- mymonth=`date +'%b'`
- myday=`date +'%d'`
- mycat="cat $deployFolder/header.template $deployFolder/startwebmodules.template"
- for webModule in $webModulesForPortal; do
- mycat="$mycat $deployFolder/$webModule.template"
- done
- mycat="$mycat $deployFolder/endwebmodules.template $deployFolder/startappmodules.template"
- for appModule in $appModulesForPortal; do
- mycat="$mycat $deployFolder/$appModule.template"
- done
- mycat="$mycat $deployFolder/endappmodules.template $deployFolder/footer.template"
- mysed="$mycat |
- sed 's/#{PHONE}/$phone/g' |
- sed 's/#{MAILTO}/$mailto/g' |
- sed 's/#{SMARTCALL_VERSION}/$smartcall_version/g' |
- sed 's/#{MARKETCHECK_VERSION}/$marketcheck_version/g' |
- sed 's/#{COPYRIGHT_END_YEAR}/$myyear/g' > \"$customerVersionEnvPath/index.html\"
- "
- echo $mysed
- eval $mysed
- IfError "sed failed."
- if [ "$targetEnvironmentName" != "Live" ]; then
- environmentSubdomain=$(echo -$targetEnvironmentName | tr "[:upper:]" "[:lower:]") # converts to lowercase
- IfError "Convert target environment to lowercase failed."
- else
- environmentSubdomain=""
- fi
- urlPrefix="$customerLiveSubdomain$environmentSubdomain"
- buildDate="$mymonth $myday, $myyear"
- productIndexTemplate="$workingPath/deploy_files/$productFolder.index.html.template"
- #echo $urlPrefix
- #echo $buildDate
- #echo $productIndexTemplate
- mysed="sed 's/#{PHONE}/$phone/g' $productIndexTemplate |
- sed 's/#{MAILTO}/$mailto/g' |
- sed 's/#{BUILD_DATE}/$buildDate/g' |
- sed 's/#{URL_PREFIX}/$urlPrefix/g' |
- sed 's/#{PLIST_FILE}/$plistFile/g' |
- sed 's/#{SMARTCALL_VERSION}/$smartcall_version/g' |
- sed 's/#{MARKETCHECK_VERSION}/$marketcheck_version/g' |
- sed 's/#{COPYRIGHT_END_YEAR}/$myyear/g' > \"$customerVersionEnvDownloadProductPath/index.html\"
- "
- echo $mysed
- eval $mysed
- IfError "sed failed."
- }
- function UploadNewVersionToAppCenter
- {
- echo
- echo "Task: Upload New Version to AppCenter - Begin"
- echo Running: appcenter crashes upload-symbols -s "$1" --app "$appCenterName" --token "e2a3de01e07ba1eff16146835125f8dba5e5d6b2"
- appcenter crashes upload-symbols -s "$1" --app "$appCenterName" --token "e2a3de01e07ba1eff16146835125f8dba5e5d6b2"
- IfError "Upload to AppCenter failed"
- echo "Task: Upload New Version to AppCenter - End"
- }
- # Create the archive
- # Assumption: The output .app file name is the target name.
- function ArchiveTarget
- {
- echo
- echo "Task: Archive Target - Begin"
- payloadDirectory="Payload"
- if [ -d "$payloadDirectory" ]; then
- rm -r "$payloadDirectory"
- fi
- mkdir "$payloadDirectory"
- IfError "mkdir $payloadDirectory failed"
- #cp -r "build/$configurationName-iphoneos/Products/$configurationName-iphoneos/$appName.app" "$payloadDirectory"
- cp -r "build/$configurationName-iphoneos/$appName.app" "$payloadDirectory"
- IfError "copying the files to the $payloadDirectory failed."
- ipaFileName="$resultFileName$targetEnvironmentName.ipa"
- zip -r "$ipaFileName" "$payloadDirectory"
- IfError "zipping the files into a ipa failed."
- # copy the dsym directory so we have all files in the same directory.
- #cp -r "build/$configurationName-iphoneos/Products/$configurationName-iphoneos/$appName.app.dSYM" .
- cp -r "build/$configurationName-iphoneos/$appName.app.dSYM" .
- IfError "Copying the dSYM file failed"
- # Zip the dSYM files since this is necessary for copying them to AppCenter anyway.
- echo "Zipping the dSYM files."
- zip -r "$appName.app.dSYM.zip" "$appName.app.dSYM"
- IfError "zipping the dSYM file $appName.app.dSYM failed."
- if [ $doUploadToAppCenter -eq 1 ]; then
- echo "Upload the files to AppCenter"
- currentPath=$(pwd)
- UploadNewVersionToAppCenter "$currentPath/$appName.app.dSYM.zip"
- else
- echo "Skip uploading files to AppCenter"
- fi
- echo "Task: Archive Target - End"
- }
- function BuildProject
- {
- echo
- echo "Task: Build Project - Begin"
- cd "$buildPath/$projectName"
- IfError "cd into the project directory error"
- if [[ "$environment" == "dev" || "$environment" == "all" ]]; then
- GetDevConfig
- if [ $doBuild -eq 1 ]; then
- BuildTarget
- fi
- fi
- if [[ "$environment" == "test" || "$environment" == "all" ]]; then
- GetTestConfig
- if [ $doBuild -eq 1 ]; then
- BuildTarget
- fi
- fi
- if [[ "$environment" == "demo" || "$environment" == "all" ]]; then
- GetLiveAppStoreConfig
- if [ $doBuild -eq 1 ]; then
- BuildTarget
- fi
- fi
- if [[ "$environment" == "live" || "$environment" == "all" ]]; then
- GetLiveConfig
- if [ $doBuild -eq 1 ]; then
- BuildTarget
- fi
- fi
- echo "Task: Build Project - End"
- }
- function BuildTarget
- {
- echo
- echo "Task: Build Target \"$targetName\" - Begin"
- echo "Customer Live Subdomain: $customerLiveSubdomain"
- echo "Product Code: $productCode"
- echo "Configuration: $configurationName"
- UpdateBundleID
- ssl=""
- if [ $useSSL -eq 1 ]; then
- echo "Setting SSL flag"
- ssl=" USE_SSL"
- fi
- upc=""
- if [ $displayUPCControls -eq 1 ]; then
- echo "Setting UPC flag"
- upc=" UPC_SCANNING_ENABLED"
- fi
- # Likely don't need this but leaving it here just in case someone needs to copy and paste in terminal.
- # echo "Selecting Xcode path."
- # echo $sudoPassword | sudo -S xcode-select -s "$xcodePath"
- if [ -z "$workspace" ]; then
- echo "Workspace is empty."
- if [ "$provisioningProfileID" = "" ]; then
- xcodebuild -target "$targetName" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID clean
- xcodebuild -target "$targetName" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID
- else
- xcodebuild -target "$targetName" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID clean
- xcodebuild -target "$targetName" -configuration "$configurationName" GCC_PREPROCESSOR_DEFINITIONS="\$(value)$ssl$upc" PRODUCT_BUNDLE_IDENTIFIER=$bundleID
- fi
- else
- echo "Building from workspace"
- echo $workspace
- mybuilddirraw=$buildPath/$projectName/build
- mybuilddir=$buildPath/$projectName/build/$configurationName-iphoneos
- deriveddatadir=$mybuilddir/DerivedData
- echo "Build folder raw: $mybuilddirraw"
- echo "Build folder: $mybuilddir"
- echo "Derived data folder: $deriveddatadir"
- if [ -e "$mybuilddirraw" ]; then
- echo Removing build folder: rm -rf "$mybuilddirraw"
- rm -rf "$mybuilddirraw"
- IfError "rm $mybuilddirraw failed"
- fi
- if [ "$provisioningProfileID" = "" ]; then
- echo "Building without provisioning profile ID"
- 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
- 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
- else
- echo "Building with provisioning profile ID $provisioningProfileID"
- 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
- 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
- fi
- fi
- IfError "Build failed"
- ArchiveTarget
- CreatePlist
- CreateDeployFolder
- IfError "Copying files to the drop folder failed"
- echo "Task: Build Target \"$targetName\" - End"
- }
- function CopyDeployFolderToDropFolder
- {
- echo
- echo "Task: Copy Deploy Folder to Drop Folder - Begin"
- # Make sure we in the project build path
- ChangeDirToProjectPath
- IFS='/' read -r customerFolder productFolder <<< "$dropFolderCustomer"
- dropCustomerFullPath="$dropFolderPath/$customerFolder"
- customerVersionPath="$customerFolder/$newBundleVersion"
- # Ensure the drop folder is mounted.
- if [ ! -d "$dropFolderPath" ]; then
- echo "It appears the drop folder ($dropFolderPath) is not mounted. Please mount the UNC path first: $dropFolderMountUncPath"
- echo -e -n "\nPress R to Retry after mounting the share or C to Cancel."
- read -n 1 reply
- echo
- if [[ $reply =~ ^[Rr]$ ]]; then
- CopyDeployFolderToDropFolder
- return 0
- else
- return 1
- fi
- fi
- if [ ! -d "$dropCustomerFullPath" ]; then
- echo "Create client drop folder: $dropCustomerFullPath"
- echo mkdir "$dropCustomerFullPath"
- mkdir "$dropCustomerFullPath"
- fi
- IfError "Failed creating $dropCustomerFullPath"
- echo "Copying deploy folder to the drop folder."
- mycmd="cp -Rv \"$customerVersionPath\" \"$dropCustomerFullPath\""
- echo $mycmd
- eval $mycmd
- IfError "Copying deploy folder failed"
- echo "Task: Copy Deploy Folder to Drop Folder - End"
- }
- function main
- {
- if [ "$branchName" == "" ]; then
- echo "Invalid <branch name> argument: $branchName"
- ShowHelp
- return 1
- fi
- if [ "$versionNumber" == "" ]; then
- echo "Invalid <update marketing version> argument: $versionNumber"
- ShowHelp
- return 1
- fi
- if ! [[ "$clientType" =~ ^(sc|mc|mc-iphone)$ ]]; then
- echo "Invalid <client type> argument: $clientType"
- ShowHelp
- return 1
- fi
- if ! [[ "$customerCode" =~ ^(bfb|bushbeans|carbonsales|chobani|core|daisy|danone|directo|kcanada|lambweston|mk|pepsicosa)$ ]]; then
- echo "Invalid <customer code> argument: $customerCode"
- ShowHelp
- return 1
- fi
- if [ "$environment" == "" ]; then
- echo "Invalid <environment> argument: $environment"
- ShowHelp
- return 1
- fi
- if ! [[ "$environment" =~ ^(dev|test|demo|live|all)$ ]]; then
- echo "Invalid <environment> argument: $environment"
- ShowHelp
- return 1
- fi
- if [ "$otherOption" == "" ]; then
- otherOption="noclean"
- fi
- if ! [[ "$otherOption" =~ ^(skip|cleanoldbinaries|clean|noclean|getsource|deployonly|deployskip)$ ]]; then
- echo "Invalid <other option> argument: $otherOption"
- ShowHelp
- return 1
- fi
- if ! [[ "$debugMode" =~ ^(false|true)$ ]]; then
- echo Invalid [DebugMode option] argument: $DebugMode
- ShowHelp
- return 1
- fi
- if [ "$clientType" != "mc" -o "$clientType" != "mc-iphone" -o "$clientType" != "sc" ]; then
- echo "The <client_type> is either mc for MarketCheck or sc for SmartCall."
- fi
- if [ "$clientType" == "sc" ]; then
- resultFileName="SmartCall"
- fi
- buildProjectFile="Build/${customerCode}_${clientType}.proj"
- echo source "$buildProjectFile"
- source "$buildProjectFile"
- IfError "Could not open the project file '$buildProjectFile'."
- if [ "$environment" == "dev" ]; then
- GetDevConfig
- elif [ "$environment" == "test" ]; then
- GetTestConfig
- elif [ "$environment" == "demo" ]; then
- GetLiveAppStoreConfig
- elif [ "$environment" == "live" ]; then
- GetLiveConfig
- fi
- echo "----------------------------------------------------------------"
- echo "Customer constant code: $customerConstantCode"
- echo "Branch: $branchName"
- echo "Customer Code: \"$customerCode\""
- echo "Project File: \"$buildProjectFile\""
- echo "Version: $versionNumber"
- echo "Target Name: $targetName"
- echo "Client Type: $clientType"
- echo "Environment: $environment"
- echo "Other Option: $otherOption"
- echo "Build Path: $buildPath"
- echo "Log File: $logFile"
- workingPath=$(pwd)
- echo "Working path: $workingPath"
- echo "----------------------------------------------------------------"
- if [ "$clientType" == "mc" ]; then
- plistInfoFile="$sourcePath/Carbon/MarketCheck-Info.plist"
- elif [ "$clientType" == "mc-iphone" ]; then
- plistInfoFile="$sourcePath/Carbon/MarketCheckIphone-Info.plist"
- else
- plistInfoFile="$sourcePath/Carbon/SmartCall-Info.plist"
- fi
- if [ "$otherOption" == "skip" ]; then
- echo "Skipping checkout, but changing dir to project path"
- ChangeDirToProjectPath
- elif [ "$otherOption" == "cleanoldbinaries" ]; then
- CleanOldBuildBinaries
- elif [ "$otherOption" == "clean" ]; then
- BuildClean
- elif [ "$otherOption" == "noclean" ]; then
- GetLatestSource
- elif [ "$otherOption" == "getsource" ]; then
- GetSourceFiles
- elif [ "$otherOption" == "deployonly" ]; then
- NewMarketingVersion=$versionNumber
- newBundleVersion=$versionNumber
- CopyDeployFolderToDropFolder
- echo "### Done. The deployment was successful."
- return;
- fi
- TaskGenerateBuildNumber
- if [ "$versionNumber" == "update" ]; then
- TaskGetCurrentMarketingVersion
- TaskGenerateMarketingVersion
- newBundleVersion=$NewMarketingVersion
- TaskUpdateInPlistInfoFile
- TaskUpdateMarketingVersion
- else
- NewMarketingVersion=$versionNumber
- newBundleVersion=$versionNumber
- TaskUpdateInPlistInfoFile
- TaskUpdateMarketingVersion
- fi
- UpdateCustomerCode
- BuildProject
- if [ "$versionNumber" == "update" ]; then
- UpdateVersionAndTagInGit
- fi
- if [ "$otherOption" <> "deployskip" ]; then
- CopyDeployFolderToDropFolder
- fi
- echo
- echo "### Done. The build was successful."
- echo
- }
- # Runs the script and logs to the specified file.
- main | tee -a "$logFile"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement