Skip to content

Instantly share code, notes, and snippets.

@hassanrazahasrat
Last active October 16, 2022 13:24
Show Gist options
  • Save hassanrazahasrat/e97441765eb79afe06f5c2377afc07af to your computer and use it in GitHub Desktop.
Save hassanrazahasrat/e97441765eb79afe06f5c2377afc07af to your computer and use it in GitHub Desktop.
iOS Automation | Build and Deploy
#!/bin/bash
#
# .env must exist in this format OR define these keys in this file
# PROJECT_NAME=testproject
# IOS_KEY_NAME=
# IOS_ISSUER=
#
WORKSPACE="."
PROJDIR=${WORKSPACE}/ios
if [ -f .env ]; then
export $(echo $(cat $WORKSPACE/.env | sed 's/#.*//g'| xargs) | envsubst)
fi
if [ "$PROJECT_NAME" == "" ] || [ "$IOS_KEY_NAME" == "" ] || [ "$IOS_ISSUER" == "" ]; then
echo "Required vars are not defined"
exit 1
fi
WORKSPACE_NAME="${PROJECT_NAME}.xcworkspace"
ARCHIVE_PATH="../build/${PROJECT_NAME}.xcarchive"
TARGET_SDK="iphoneos15.5"
EXPORT_PATH="~/Desktop/${PROJECT_NAME}-releases"
if [ "$IOS_KEY_NAME" == "" ]; then
echo "IOS credentials not defined"
exit 1
fi
cd "$PROJDIR"
echo "Increase Version Build Code"
agvtool next-version -all # will increase build code to next version
echo "Cleaning Project"
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -scheme "$PROJECT_NAME" -sdk "$TARGET_SDK" -configuration Release clean
echo "Building Project"
xcodebuild -scheme "$PROJECT_NAME" -workspace "$WORKSPACE_NAME" -sdk "$TARGET_SDK" -allowProvisioningUpdates -configuration Release archive -archivePath "$ARCHIVE_PATH" BUILD_LIBRARY_FOR_DISTRIBUTION=YES
# exportOptions.plist content
# ---------------------------
# <?xml version="1.0" encoding="UTF-8"?>
# <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
# <plist version="1.0">
# <dict>
# <key>method</key>
# <string>app-store</string>
# <key>teamID</key>
# <string>{YOUR TEAM ID}</string>
# <key>teamName</key>
# <string>{YOUR TEAM NAME}</string>
# </dict>
# </plist>
echo "Export IPA" # exportOptions.plist must exists in the $PROJDIR directory
xcodebuild -exportArchive -archivePath "$ARCHIVE_PATH" -exportOptionsPlist exportOptions.plist -exportPath "$EXPORT_PATH" -allowProvisioningUpdates
xcrun altool --upload-app --type ios --file "$EXPORT_PATH/${PROJECT_NAME}.ipa" --apiKey "$IOS_KEY_NAME" --apiIssuer "$IOS_ISSUER"
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment