Created
November 22, 2016 19:32
-
-
Save Gerst20051/6a4fea08ed3611891cf6488f3dee97d3 to your computer and use it in GitHub Desktop.
Build And Archive IPA Bash Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo '' | |
################################# PROMPT ################################# | |
itunesconnect_user='email@email.com' | |
printf "itunesconnect password for email '$itunesconnect_user': " | |
read -s itunesconnect_pass | |
########################################################################## | |
echo $'\n' | |
################################ SETTINGS ################################ | |
XCODE_APP_NAME='Xcode.app' | |
########################################################################## | |
################################ CONSTANT ################################ | |
DATETIME=$(date +%F--%T) | |
TARGET_SDK='iphoneos' | |
PROJECT_BUILD_DIR='build' | |
PROJECT_RELEASE_DIR="$PWD/$PROJECT_BUILD_DIR/Build/Products/Release-iphoneos" | |
BUILD_ARCHIVE_DIR="$HOME/Desktop/Release-iphoneos" | |
CURRENT_BUILD_DIR="$BUILD_ARCHIVE_DIR/$DATETIME" | |
########################################################################## | |
apps_to_ignore=( | |
'some_app_name' # different itunesconnect account | |
) | |
function remove_app_transport_bypass { | |
/usr/libexec/PlistBuddy -c 'Remove NSAppTransportSecurity' mobilepay/Info.plist | |
} | |
function create_build_directories { | |
mkdir -p $PROJECT_RELEASE_DIR | |
mkdir -p $BUILD_ARCHIVE_DIR | |
mkdir -p $CURRENT_BUILD_DIR | |
} | |
function load_whitelabels { | |
DIRS=`ls -l whitelabels | egrep '^d' | awk '{print $9}' | egrep '^\d' | sort -n` | |
DIRS_ARR=($DIRS) | |
DIRS_ARR=('some_app_name') | |
} | |
function clean_and_update { | |
xcodebuild clean | |
update_cocoapods | |
} | |
function build_and_archive_whitelabels { | |
BUILDS_FAILED=0 | |
for i in "${!DIRS_ARR[@]}"; do | |
if [[ " ${apps_to_ignore[@]} " =~ " ${DIRS_ARR[$i]} " ]]; then | |
continue | |
fi | |
./switch_operator ${DIRS_ARR[$i]} | |
APPLICATION_NAME=$(grep -m 1 'PRODUCT_NAME = .*' appname.xcodeproj/project.pbxproj | awk -F'[= ;]' '{print $4}') | |
CODE_SIGN_IDENTITY='iPhone Distribution: Company Name (IDENTIFIER)' | |
PROVISIONING_PROFILE_ID='XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' | |
PROVISIONING_PROFILE_NAME='XC: *' | |
echo Starting ${DIRS_ARR[$i]} | |
build_project | |
if [ $BUILD_OUTPUT != 0 ]; then | |
echo Failed To Build $APPLICATION_NAME | |
$BUILDS_FAILED+=1 | |
continue | |
fi | |
update_plist_file | |
archive_project | |
package_ipa | |
validate_archive | |
if [ $VALIDATE_OUTPUT != 0 ]; then | |
BUILDS_FAILED=$(($BUILDS_FAILED + 1)) | |
echo Failed To Validate $APPLICATION_NAME | |
continue | |
fi | |
remove_project | |
upload_archive | |
echo Successfully Archived $APPLICATION_NAME | |
done | |
echo Finished Building and Archiving Whitelabels $BUILDS_FAILED | |
# if [ "${#DIRS_ARR[@]}" -eq 1 && "$VALIDATE_OUTPUT" == 0 ] || [ "${#DIRS_ARR[@]}" -gt 1 ]; then | |
# echo Finished Building and Archiving Whitelabels | |
# if [ "$BUILDS_FAILED" -gt 0 ]; then | |
# echo Failed To Build "$BUILDS_FAILED/${#DIRS_ARR[@]}" Whitelabels | |
# fi | |
# fi | |
} | |
function update_cocoapods { | |
pod install | |
} | |
function build_project { | |
echo Building Project $APPLICATION_NAME | |
xcodebuild archive -workspace mobilepay.xcworkspace -scheme mobilepay -sdk "$TARGET_SDK" -configuration Release ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" PROVISIONING_PROFILE="$PROVISIONING_PROFILE_ID" OTHER_CODE_SIGN_FLAGS="--keychain $HOME/Library/Keychains/login.keychain" -archivePath "$CURRENT_BUILD_DIR/$APPLICATION_NAME.xcarchive" | xcpretty -c | |
BUILD_OUTPUT=$? | |
} | |
function update_plist_file { | |
echo Updating BuildMachineOSBuild In PList File | |
path_to_plist="$CURRENT_BUILD_DIR/$APPLICATION_NAME.xcarchive/Products/Applications/$APPLICATION_NAME.app/Info.plist" | |
plutil -convert xml1 $path_to_plist | |
line=$((`grep -n '<key>BuildMachineOSBuild</key>' $path_to_plist | cut -d : -f1` + 1)) | |
sed -i '' "${line}s/.*/${TAB}<string>14F27<\\/string>/" $path_to_plist | |
plutil -convert binary1 $path_to_plist | |
} | |
function archive_project { | |
echo Archiving Project $APPLICATION_NAME | |
xcodebuild -exportProvisioningProfile "$PROVISIONING_PROFILE_NAME" -exportArchive -exportFormat IPA -archivePath "$CURRENT_BUILD_DIR/$APPLICATION_NAME.xcarchive" -exportPath "$CURRENT_BUILD_DIR/$APPLICATION_NAME.ipa" CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" | xcpretty -c | |
} | |
function package_ipa { | |
echo Packaging IPA | |
./package_ipa "$CURRENT_BUILD_DIR" "$APPLICATION_NAME" | |
} | |
function remove_project { | |
rm -rf $CURRENT_BUILD_DIR/$APPLICATION_NAME.xcarchive | |
} | |
function validate_archive { | |
echo Validating Archive $APPLICATION_NAME | |
ALTOOL="/Applications/$XCODE_APP_NAME/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool" | |
$("$ALTOOL" --validate-app -f "$CURRENT_BUILD_DIR/Packaged$APPLICATION_NAME.ipa" -u $itunesconnect_user -p $itunesconnect_pass) | |
VALIDATE_OUTPUT=$? | |
} | |
function upload_archive { | |
echo Uploading Archive $APPLICATION_NAME | |
ALTOOL="/Applications/$XCODE_APP_NAME/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool" | |
$("$ALTOOL" --upload-app -f "$CURRENT_BUILD_DIR/Packaged$APPLICATION_NAME.ipa" -u $itunesconnect_user -p $itunesconnect_pass) | |
} | |
function init { | |
remove_app_transport_bypass | |
create_build_directories | |
load_whitelabels | |
clean_and_update | |
build_and_archive_whitelabels | |
} | |
init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment