Created
April 22, 2022 18:16
-
-
Save ryandevore/7d4d9e35c6e2136f0441deaf986a421f to your computer and use it in GitHub Desktop.
iOS Build Scripts
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/sh | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
cd $SCRIPT_DIR | |
# import common helper functions | |
. xcode_build_functions.sh | |
UUDebugLog "Building App Store IPA" | |
./build_appstore_ipa.sh | |
UUCheckReturnCode $? "build_appstore_ipa" | |
UUDebugLog "Building InHouse IPA" | |
./build_inhouse_ipa.sh | |
UUCheckReturnCode $? "build_inhouse_ipa" | |
UUDebugLog "Uploading InHouse IPA to Firebase" | |
./upload_to_firebase.sh ../../build_inhouse/*.ipa | |
UUCheckReturnCode $? "upload_to_firebase" | |
UUDebugLog "Uploading InHouse symbols to Firebase" | |
./upload-symbols -gsp ../../src/Config/GoogleService-Info-InHouse.plist -p ios ../../build_inhouse/*.xcarchive/dSYMs | |
UUCheckReturnCode $? "upload-symbols" | |
UUDebugLog "Cleaning output folder" | |
rm -rf ../../build | |
UUDebugLog "Copying builds into output folder" | |
mkdir ../../build | |
mv ../../build_inhouse/* ../../build | |
mv ../../build_appstore/* ../../build | |
UUDebugLog "Cleanup temp build folders" | |
rm -rf ../../build_inhouse | |
rm -rf ../../build_appstore | |
cd ../../build | |
FULL_VERSION_NUMBER=`cat full_version_number` | |
zip -r PROJECT_NAME_HERE_iOS_${FULL_VERSION_NUMBER}.zip *.ipa *.xcarchive | |
rm full_version_number | |
rm -rf *.ipa | |
rm -rf *.xcarchive | |
UUDebugLog "All Done!" | |
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/sh | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
cd $SCRIPT_DIR | |
# import common helper functions | |
. xcode_build_functions.sh | |
OUTPUT_DIR="../../build_appstore" | |
XCODE_PROJECT_PATH="../../src/XCODE_PROJECT_NAME_HERE.xcodeproj" | |
SCHEME_NAME="AppStore" | |
EXPORT_PLIST_PATH="../../src/Config/AppStoreExport.plist" | |
rm -rf ../build/certs/AppStoreCert* | |
mkdir ../build | |
mkdir ../build/certs | |
echo $APPSTORE_CERT >> ../build/certs/AppStoreCertBase64.tmp | |
base64 --decode ../build/certs/AppStoreCertBase64.tmp > ../build/certs/AppStoreCert.p12 | |
CERT_PATH=../build/certs/AppStoreCert.p12 | |
CERT_PASS=$APPSTORE_CERT_PASSWORD | |
PROFILE_PATH="../profiles/APPSTORE_PROVISIONING_PROFILE_NAME_HERE.mobileprovision" | |
UUMakeBuildFixed "${XCODE_PROJECT_PATH}" "${SCHEME_NAME}" "${EXPORT_PLIST_PATH}" "${CERT_PATH}" "${CERT_PASS}" "${PROFILE_PATH}" "${OUTPUT_DIR}" | |
rm -rf ../certs/AppStoreCert* |
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/sh | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
cd $SCRIPT_DIR | |
# import common helper functions | |
. xcode_build_functions.sh | |
OUTPUT_DIR="../../build_inhouse" | |
XCODE_PROJECT_PATH="../../src/XCODE_PROJECT_NAME_HERE.xcodeproj" | |
SCHEME_NAME="InHouse" | |
EXPORT_PLIST_PATH="../../src/Config/InHouseExport.plist" | |
rm -rf ../build/certs/InHouseCert* | |
mkdir ../build | |
mkdir ../build/certs | |
echo $INHOUSE_CERT >> ../build/certs/InHouseCertBase64.tmp | |
base64 --decode ../build/certs/InHouseCertBase64.tmp > ../build/certs/InHouseCert.p12 | |
CERT_PATH=../build/certs/InHouseCert.p12 | |
CERT_PASS=$INHOUSE_CERT_PASSWORD | |
PROFILE_PATH="../profiles/INHOUSE_PROVISIONING_PROFILE_NAME_HERE.mobileprovision" | |
UUMakeBuildFixed "${XCODE_PROJECT_PATH}" "${SCHEME_NAME}" "${EXPORT_PLIST_PATH}" "${CERT_PATH}" "${CERT_PASS}" "${PROFILE_PATH}" "${OUTPUT_DIR}" | |
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/sh | |
function UUDebugLog | |
{ | |
LINE=$1 | |
# Uncomment this line to print debug info | |
echo "${LINE}" | |
} | |
function UUCheckReturnCode | |
{ | |
if [ $1 != 0 ] | |
then | |
echo "Return Code check failed for action $2, exiting with error code $1" | |
exit $1 | |
fi | |
} | |
function UURemoveSpaces | |
{ | |
local INPUT=$1 | |
echo ${INPUT//[[:blank:]]/} | |
} | |
function UUTrimWhitespace | |
{ | |
local INPUT=$1 | |
NO_SPACE="$(echo "${INPUT}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" | |
echo ${NO_SPACE} | |
} | |
function UUIsGitRepo | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UUIsGitRepo [Output Variable]" | |
exit 1 | |
fi | |
local OUTPUT_VAR=$1 | |
eval $OUTPUT_VAR=1 | |
git rev-parse --is-inside-work-tree | |
if [ $? != 0 ] | |
then | |
eval $OUTPUT_VAR=0 | |
fi | |
} | |
function UUIsSvnRepo | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UUIsSvnRepo [Output Variable]" | |
exit 1 | |
fi | |
local OUTPUT_VAR=$1 | |
eval $OUTPUT_VAR=1 | |
svn info | |
if [ $? != 0 ] | |
then | |
eval $OUTPUT_VAR=0 | |
fi | |
} | |
# This method will replace the last digit in a dotted version string with a fixed number. | |
# The intention is that the project plist will have either a three or four digit build number | |
function UUGenerateBuildNumber | |
{ | |
if [ $# != 3 ] | |
then | |
echo "Usage: UUGenerateBuildNumber [Current Version String] [Build Number] [Output Variable]" | |
exit 1 | |
fi | |
local CURRENT_VERSION=$1 | |
local BUILD_NUMBER=$2 | |
local OUTPUT_VAR=$3 | |
PARTS=() | |
IFS='.' read -ra ARR <<< "${CURRENT_VERSION}" | |
PART_COUNT=0 | |
for i in "${ARR[@]}"; do | |
COMPONENT=${i} | |
PARTS+=(${COMPONENT}) | |
let PART_COUNT=PART_COUNT+1 | |
done | |
let PART_COUNT=PART_COUNT-1 | |
if (( ${PART_COUNT} <= 0 )) | |
then | |
echo "UUGenerateBuildNumber expects current version to have at least 1 components" | |
exit 1 | |
fi | |
NEW_VERSION='' | |
for i in `seq 1 ${PART_COUNT}`; | |
do | |
let INDEX=i-1 | |
PART=${PARTS[${INDEX}]} | |
NEW_VERSION+="${PART}." | |
done | |
NEW_VERSION+="${BUILD_NUMBER}" | |
eval $OUTPUT_VAR="'${NEW_VERSION}'" | |
} | |
# Slices off the fourth part of a build number if needed | |
function UUGetShortBuildNumber | |
{ | |
if [ $# != 2 ] | |
then | |
echo "Usage: UUGetShortBuildNumber [Version String] [Output Variable]" | |
exit 1 | |
fi | |
local CURRENT_VERSION=$1 | |
local OUTPUT_VAR=$2 | |
PARTS=() | |
IFS='.' read -ra ARR <<< "${CURRENT_VERSION}" | |
PART_COUNT=0 | |
for i in "${ARR[@]}"; do | |
COMPONENT=${i} | |
PARTS+=(${COMPONENT}) | |
let PART_COUNT=PART_COUNT+1 | |
done | |
let PART_COUNT=PART_COUNT-1 | |
if (( ${PART_COUNT} <= 3 )) | |
then | |
eval $OUTPUT_VAR="'${CURRENT_VERSION}'" | |
fi | |
let PERIOD_STOP=PART_COUNT-1 | |
NEW_VERSION='' | |
for i in `seq 1 ${PART_COUNT}`; | |
do | |
let INDEX=i-1 | |
PART=${PARTS[${INDEX}]} | |
NEW_VERSION+="${PART}" | |
if [ ${INDEX} -lt ${PERIOD_STOP} ] | |
then | |
NEW_VERSION+="." | |
fi | |
done | |
eval $OUTPUT_VAR="'${NEW_VERSION}'" | |
} | |
function UUReadGitRevisionNumber | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UUReadGitRevNumber [Output Variable]" | |
exit 1 | |
fi | |
local OUTPUT_VAR=$1 | |
VAR_RESULT=`git rev-list --count HEAD` | |
eval $OUTPUT_VAR="'${VAR_RESULT}'" | |
UUCheckReturnCode $? "readGitRevisionNumber" | |
} | |
function UURevertGitChanges | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UURevertGitChanges [Path to File]" | |
exit 1 | |
fi | |
local FILE_PATH=$1 | |
echo "Resetting git changes to ${FILE_PATH}" | |
git checkout HEAD "${FILE_PATH}" | |
UUCheckReturnCode $? "revert git changes ${FILE_PATH}" | |
} | |
function UURevertSvnChanges | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UURevertSvnChanges [Path to File]" | |
exit 1 | |
fi | |
local FILE_PATH=$1 | |
echo "Resetting svn changes to ${FILE_PATH}" | |
svn revert -R "${FILE_PATH}" | |
UUCheckReturnCode $? "revert svn changes ${FILE_PATH}" | |
} | |
function UURevertChanges | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UURevertChanges [Path to File]" | |
exit 1 | |
fi | |
local FILE_PATH=$1 | |
UUIsGitRepo LOCAL_IS_GIT_REPO | |
UUIsSvnRepo LOCAL_IS_SVN_REPO | |
if [ ${LOCAL_IS_GIT_REPO} == 1 ] | |
then | |
UURevertGitChanges "${FILE_PATH}" | |
fi | |
if [ ${LOCAL_IS_SVN_REPO} == 1 ] | |
then | |
UURevertSvnChanges "${FILE_PATH}" | |
fi | |
} | |
function UUDeleteFile | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UUDeleteFile [Source]" | |
exit 1 | |
fi | |
local SOURCE=$1 | |
echo "Deleting ${SOURCE}" | |
rm -rf "${SOURCE}" | |
UUCheckReturnCode $? "delete file failed" | |
} | |
function UUCopyFile | |
{ | |
if [ $# != 2 ] | |
then | |
echo "Usage: UUCopyFile [Source] [Dest]" | |
exit 1 | |
fi | |
local SOURCE=$1 | |
local DEST=$2 | |
# echo "Deleting ${DEST}" | |
# rm -rf "${DEST}" | |
UUDebugLog "Copying ${SOURCE} to ${DEST}" | |
cp -r "${SOURCE}" "${DEST}" | |
UUCheckReturnCode $? "copy file failed" | |
} | |
function UUCreateFolder | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UUCreateFolder [FolderName]" | |
exit 1 | |
fi | |
local FOLDER_NAME=$1 | |
UUDebugLog "Creating folder ${FOLDER_NAME}" | |
mkdir -p "${FOLDER_NAME}" | |
UUCheckReturnCode $? "creating folder" | |
} | |
function UUExtractFileName | |
{ | |
if [ $# != 2 ] | |
then | |
echo "Usage: UUExtractFileName [Full Path] [Output Variable]" | |
exit 1 | |
fi | |
local FULL_PATH=$1 | |
local OUTPUT_VAR=$2 | |
local FILE_NAME=$(basename "$FULL_PATH") | |
eval $OUTPUT_VAR="'${FILE_NAME}'" | |
UUCheckReturnCode $? "UUExtractFileName" | |
} | |
function UUExtractFileNameNoExtension | |
{ | |
if [ $# != 2 ] | |
then | |
echo "Usage: UUExtractFileNameNoExtension [Full Path] [Output Variable]" | |
exit 1 | |
fi | |
local FULL_PATH=$1 | |
local OUTPUT_VAR=$2 | |
local FILE_WITH_EXTENSION=$(basename "$FULL_PATH") | |
local FILE_WITHOUT_EXTENSION="${FILE_WITH_EXTENSION%.*}" | |
eval $OUTPUT_VAR="'${FILE_WITHOUT_EXTENSION}'" | |
UUCheckReturnCode $? "UUExtractFileNameNoExtension" | |
} | |
function UUExtractFileExtension | |
{ | |
if [ $# != 2 ] | |
then | |
echo "Usage: UUExtractFileExtension [Full Path] [Output Variable]" | |
exit 1 | |
fi | |
local FULL_PATH=$1 | |
local OUTPUT_VAR=$2 | |
local FILE_EXTENSION="${FULL_PATH##*.}" | |
eval $OUTPUT_VAR="'${FILE_EXTENSION}'" | |
UUCheckReturnCode $? "UUExtractFileExtension" | |
} | |
function UUExtractFolder | |
{ | |
if [ $# != 2 ] | |
then | |
echo "Usage: UUExtractFolder [Full Path] [Output Variable]" | |
exit 1 | |
fi | |
local FULL_PATH=$1 | |
local OUTPUT_VAR=$2 | |
local DIR=$(dirname "${FULL_PATH}") | |
eval $OUTPUT_VAR="'${DIR}'" | |
UUCheckReturnCode $? "UUExtractFolder" | |
} | |
function UUFindFolder | |
{ | |
if [ $# != 3 ] | |
then | |
echo "Usage: UUFindFolder [Root Search Path] [VarName] [Output Variable]" | |
exit 1 | |
fi | |
local ROOT_SEARCH_PATH=$1 | |
local VAR_NAME=$2 | |
local OUTPUT_VAR=$3 | |
local RESULT=`find "${ROOT_SEARCH_PATH}" -type d -name "${VAR_NAME}" | head -n 1` | |
eval $OUTPUT_VAR="'${RESULT}'" | |
UUCheckReturnCode $? "UUFindFolder" | |
} | |
function UUZipFolder | |
{ | |
if [ $# != 2 ] | |
then | |
echo "Usage: UUZipFolder [Source] [Dest]" | |
exit 1 | |
fi | |
local SOURCE=$1 | |
local DEST=$2 | |
CWD=$(pwd) | |
cd "${SOURCE}" | |
cd .. | |
local FOLDER=$(basename "$SOURCE") | |
UUDebugLog "CWD: $(pwd)" | |
UUDebugLog "FOLDER: ${FOLDER}" | |
zip -r "${DEST}" "${FOLDER}" | |
UUCheckReturnCode $? "UUZipFolder" | |
cd "${CWD}" | |
} | |
function UUEscapeChars | |
{ | |
if [ $# != 1 ] | |
then | |
echo "Usage: UUEscapeChars [input]" | |
exit 1 | |
fi | |
local INPUT=$1 | |
INPUT="${INPUT/\&/\\\&}" | |
echo ${INPUT} | |
} | |
function UUReplaceStringInFile | |
{ | |
if [ $# != 3 ] | |
then | |
echo "Usage: UUReplaceStringInFile [file] [to replace] [replacement]" | |
exit 1 | |
fi | |
local FILE=$1 | |
local TO_REPLAC=$2 | |
local REPLACEMENT=$3 | |
sed -i "" -e "s/${TO_REPLAC}/${REPLACEMENT}/g" "${FILE}" | |
} |
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/sh | |
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
cd $SCRIPT_DIR | |
if [ $# -lt 1 ] | |
then | |
echo "Usage: upload_to_firebase.sh [ipa path]" | |
exit 1 | |
fi | |
IPA_PATH=$1 | |
FIREBASE_APP_ID=INSERT_FIREBASE_PROJECT_ID_HERE | |
firebase appdistribution:distribute "${IPA_PATH}" --app "${FIREBASE_APP_ID}" --release-notes-file "../../docs/ci_build_notes.md" --groups "dev" --token ${FIREBASE_TOKEN} --debug |
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/sh | |
# import common helper functions | |
. common_build_functions.sh | |
function UUSetupBuildKeychain | |
{ | |
if [ $# -lt 4 ] | |
then | |
echo "Usage: UUSetupBuildKeychain [Keychain Path] [Keychain Password] [Cert Path] [Cert Password] (optional) [Verbose Mode]" | |
exit 1 | |
fi | |
local KEYCHAIN_PATH=$1 | |
local KEYCHAIN_PASS=$2 | |
local IMPORT_CERT_PATH=$3 | |
local IMPORT_CERT_PASS=$4 | |
local VERBOSE_MODE=$5 | |
UUDebugLog "Creating temporary build keychain ${KEYCHAIN_PATH}" | |
security ${VERBOSE_MODE} create-keychain -p ${KEYCHAIN_PASS} ${KEYCHAIN_PATH} | |
if [ $? == 48 ] # keychain already exists | |
then | |
UUDebugLog "Keychain already exists, let's try deleting it" | |
security ${VERBOSE_MODE} delete-keychain ${KEYCHAIN_PATH} | |
UUDebugLog "Trying to creating keychain again" | |
security ${VERBOSE_MODE} create-keychain -p ${KEYCHAIN_PASS} ${KEYCHAIN_PATH} | |
fi | |
UUCheckReturnCode $? "createKeychain" | |
UUDebugLog "Unlocking temporary build keychain ${KEYCHAIN_PATH}" | |
security ${VERBOSE_MODE} unlock-keychain -p ${KEYCHAIN_PASS} ${KEYCHAIN_PATH} | |
UUCheckReturnCode $? "unlockKeychain" | |
UUDebugLog "Importing build certificate into keychain" | |
security ${VERBOSE_MODE} import ${IMPORT_CERT_PATH} -k ${KEYCHAIN_PATH} -P ${IMPORT_CERT_PASS} -T /usr/bin/codesign -A | |
UUCheckReturnCode $? "importCertificate" | |
UUDebugLog "Listing keychain" | |
security ${VERBOSE_MODE} list-keychain -s ${KEYCHAIN_PATH} | |
UUCheckReturnCode $? "listKeychain" | |
UUDebugLog "Setting keychain timeout" | |
security -v set-keychain-settings -lut 7200 ${KEYCHAIN_PATH} | |
UUCheckReturnCode $? "setKeychainTimeout" | |
UUDebugLog "Setting key paritition list ${KEYCHAIN_PATH}" | |
security ${VERBOSE_MODE} set-key-partition-list -S apple-tool:,apple: -s -k ${KEYCHAIN_PASS} ${KEYCHAIN_PATH} | |
# Don't check return code here because this is a Sierra only command | |
# UUCheckReturnCode $? "setKeyPartition List" | |
} | |
function UUCleanupBuildKeychain | |
{ | |
if [ $# -lt 1 ] | |
then | |
echo "Usage: UUCleanupBuildKeychain [Keychain Path] (optional) [Verbose Mode]" | |
exit 1 | |
fi | |
local KEYCHAIN_PATH=$1 | |
local VERBOSE_MODE=$2 | |
UUDebugLog "Deleting temporary keychain ${KEYCHAIN_PATH}" | |
security ${VERBOSE_MODE} delete-keychain ${KEYCHAIN_PATH} | |
UUCheckReturnCode $? "deleteKeychain" | |
UUDebugLog "Re-listing current user login keychain" | |
security ${VERBOSE_MODE} list-keychain -s "${HOME}/Library/Keychains/login.keychain" | |
} | |
function UUMakeTempKeychain | |
{ | |
if [ $# -lt 3 ] | |
then | |
echo "Usage: UUMakeTempKeychain [path to certificate] [certificate password] [keychain path (out)]" | |
exit 1 | |
fi | |
CWD=$(pwd) | |
local CERT_PATH=$1 | |
local CERT_PASSWORD=$2 | |
local OUTPUT_VAR=$3 | |
KEYCHAIN_NAME=`uuidgen` | |
KEYCHAIN_PATH=~/Library/Keychains/${KEYCHAIN_NAME}.keychain | |
KEYCHAIN_PASS=masterpassword | |
UUDebugLog "KEYCHAIN_NAME: ${KEYCHAIN_NAME}" | |
UUSetupBuildKeychain ${KEYCHAIN_PATH} ${KEYCHAIN_PASS} ${CERT_PATH} ${CERT_PASSWORD} -v | |
eval $OUTPUT_VAR="'${KEYCHAIN_PATH}'" | |
} | |
function UUInstallProvisioningProfile | |
{ | |
if [ $# -lt 1 ] | |
then | |
echo "Usage: UUInstallProvisioningProfile [full path to profile] " | |
exit 1 | |
fi | |
local PROVISION_PROFILE_PATH=$1 | |
PROVISION_PROFILE_LOC=~/Library/MobileDevice/Provisioning\ Profiles/ | |
UUDebugLog "Installing Provisioning profile: ${PROVISION_PROFILE_PATH}" | |
mkdir -p "${PROVISION_PROFILE_LOC}" | |
UUCopyFile "${PROVISION_PROFILE_PATH}" "${PROVISION_PROFILE_LOC}" | |
} | |
function UUReadPlistString | |
{ | |
if [ $# != 3 ] | |
then | |
echo "Usage: UUReadPlistString [Full Path to Plist] [VarName] [Output Variable]" | |
exit 1 | |
fi | |
local PLIST_PATH=$1 | |
local VAR_NAME=$2 | |
local OUTPUT_VAR=$3 | |
VAR_RESULT=`/usr/libexec/PlistBuddy -c "Print :${VAR_NAME}" "${PLIST_PATH}"` | |
eval $OUTPUT_VAR="'${VAR_RESULT}'" | |
UUCheckReturnCode $? "read ${VAR_NAME}" | |
} | |
function UUReadBundleVersion | |
{ | |
UUReadPlistString "$1" "CFBundleVersion" "$2" | |
} | |
function UUReadBundleShortVersionString | |
{ | |
UUReadPlistString "$1" "CFBundleShortVersionString" "$2" | |
} | |
function UUWritePlistString | |
{ | |
if [ $# != 3 ] | |
then | |
echo "Usage: UUWritePlistString [Full Path to Plist] [VarName] [VarValue]" | |
exit 1 | |
fi | |
local PLIST_PATH=$1 | |
local VAR_NAME=$2 | |
local VAR_VALUE=$3 | |
`/usr/libexec/PlistBuddy -c "Set :${VAR_NAME} ${VAR_VALUE}" "${PLIST_PATH}"` | |
UUCheckReturnCode $? "write ${VAR_NAME}" | |
} | |
function UUUpdateWatchAppBundleIdentifier | |
{ | |
if [ $# != 2 ] | |
then | |
echo "Usage: UUUpdateWatchAppBunbleIdentifier [Plist Path] [bundle id]" | |
exit 1 | |
fi | |
local PLIST_PATH=$1 | |
local BUNDLE_ID=$2 | |
UUDebugLog "PLIST_PATH: ${PLIST_PATH}" | |
UUDebugLog "BUNDLE_ID: ${BUNDLE_ID}" | |
`/usr/libexec/PlistBuddy -c "Set :NSExtension:NSExtensionAttributes:WKAppBundleIdentifier ${BUNDLE_ID}" "${PLIST_PATH}"` | |
UUCheckReturnCode $? "write watch bundle id ${VAR_NAME}" | |
} | |
function UUWriteBundleVersion | |
{ | |
UUWritePlistString "$1" "CFBundleVersion" "$2" | |
} | |
function UUWriteBundleShortVersionString | |
{ | |
UUWritePlistString "$1" "CFBundleShortVersionString" "$2" | |
} | |
function UUWriteBundleVersionShort | |
{ | |
local VERSION=$2 | |
UUGetShortBuildNumber ${VERSION} UPDATED_VERSION | |
UUDebugLog "VERSION: ${VERSION}, UPDATED_VERSION: ${UPDATED_VERSION}" | |
UUWritePlistString "$1" "CFBundleShortVersionString" "${UPDATED_VERSION}" | |
} | |
function UUWriteBundleIdentifier | |
{ | |
UUWritePlistString "$1" "CFBundleIdentifier" "$2" | |
} | |
function UUWriteBundleDisplayName | |
{ | |
UUWritePlistString "$1" "CFBundleDisplayName" "$2" | |
} | |
function UUGenerateArchive | |
{ | |
if [ $# != 4 ] | |
then | |
echo "Usage: UUGenerateArchive [full project path] [scheme name] [profile path] [Output Path]" | |
exit 1 | |
fi | |
local PROJECT_PATH=$1 | |
local SCHEME=$2 | |
local PROFILE_PATH=$3 | |
local OUTPUT_DIR=$4 | |
UUDebugLog "UUGenerateArchive, PROJECT_PATH=${PROJECT_PATH}" | |
UUDebugLog "UUGenerateArchive, SCHEME=${SCHEME}" | |
UUDebugLog "UUGenerateArchive, PROFILE_PATH=${PROFILE_PATH}" | |
UUDebugLog "UUGenerateArchive, OUTPUT_DIR=${OUTPUT_DIR}" | |
UUExtractXcodeBuildSetting "${PROJECT_PATH}" "${SCHEME}" "FULL_PRODUCT_NAME" FULL_PRODUCT_NAME | |
UUDebugLog "FULL_PRODUCT_NAME: ${FULL_PRODUCT_NAME}" | |
UUGenerateBuildNumber "${PROJECT_PATH}" "${SCHEME}" FULL_VERSION_NUMBER | |
FULL_PRODUCT_NAME_NO_SPACES=`UURemoveSpaces "${FULL_PRODUCT_NAME}"` | |
PROJECT_NAME_NO_SPACES="${FULL_PRODUCT_NAME_NO_SPACES/.app/}" | |
OUTPUT_FILE_NAME="${PROJECT_NAME_NO_SPACES}-${SCHEME}-${FULL_VERSION_NUMBER}" | |
ARCHIVE_OUTPUT_PATH="${OUTPUT_DIR}/${OUTPUT_FILE_NAME}.xcarchive" | |
UUDebugLog "UUGenerateArchive, ARCHIVE_OUTPUT_PATH=${ARCHIVE_OUTPUT_PATH}" | |
UUInstallProvisioningProfile "${PROFILE_PATH}" | |
UUExtractMobileProvisionValue "${PROFILE_PATH}" "UUID" PROVISION_PROFILE_GUID | |
UUExtractMobileProvisionValue "${PROFILE_PATH}" "Name" PROVISION_PROFILE_NAME | |
BUILD_TYPE="-project" | |
if [[ ${PROJECT_PATH} == *".xcworkspace" ]] | |
then | |
BUILD_TYPE="-workspace" | |
fi | |
UUDebugLog "Building Xcode Project" | |
xcodebuild "${BUILD_TYPE}" "${PROJECT_PATH}" -sdk iphoneos -scheme "${SCHEME}" -configuration "${SCHEME}" -archivePath "${ARCHIVE_OUTPUT_PATH}" clean archive CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="iPhone Distribution" PROVISIONING_PROFILE="${PROVISION_PROFILE_GUID}" PROVISIONING_PROFILE_SPECIFIER="${PROVISION_PROFILE_NAME}" CURRENT_PROJECT_VERSION="${FULL_VERSION_NUMBER}" | |
UUCheckReturnCode $? "Xcode Build Failed" | |
echo ${FULL_VERSION_NUMBER} >> ${OUTPUT_DIR}/full_version_number | |
} | |
function UUExtractXcodeBuildSetting | |
{ | |
if [ $# != 4 ] | |
then | |
echo "Usage: UUExtractXcodeBuildSetting [Project Path] [config name] [VarName] [Output Variable]" | |
exit 1 | |
fi | |
local FULL_PATH=$1 | |
local CONFIG_NAME=$2 | |
local VAR_NAME=$3 | |
local OUTPUT_VAR=$4 | |
BUILD_TYPE="-project" | |
if [[ ${FULL_PATH} == *".xcworkspace" ]] | |
then | |
BUILD_TYPE="-workspace" | |
fi | |
local RESULT=$(xcodebuild "${BUILD_TYPE}" "${FULL_PATH}" -configuration "${CONFIG_NAME}" -scheme "${CONFIG_NAME}" -showBuildSettings | grep -m 1 -w ${VAR_NAME} | awk -F"=" '/=/ { print $2 }' | sed 's/^ *//g' | sed 's/ *$//g') | |
eval $OUTPUT_VAR="'${RESULT}'" | |
UUCheckReturnCode $? "UUExtractXcodeBuildSetting" | |
} | |
function UUExtractMobileProvisionValue | |
{ | |
if [ $# != 3 ] | |
then | |
echo "Usage: UUExtractMobileProvisionValue [Provision Path] [VarName] [Output Variable]" | |
exit 1 | |
fi | |
local FULL_PATH=$1 | |
local VAR_NAME=$2 | |
local OUTPUT_VAR=$3 | |
local TMP_PLIST_PATH=tmp.plist | |
local RESULT=`security cms -D -i "${FULL_PATH}" > "${TMP_PLIST_PATH}" && /usr/libexec/PlistBuddy -c "Print ${VAR_NAME}" "${TMP_PLIST_PATH}"` | |
eval $OUTPUT_VAR="'${RESULT}'" | |
UUCheckReturnCode $? "UUExtractMobileProvisionValue" | |
rm -rf "${TMP_PLIST_PATH}" | |
} | |
function UUGetFullPlistPath | |
{ | |
if [ $# -lt 3 ] | |
then | |
echo "Usage: UUGetFullPlistPath [full path to xcode project] [configuration] [output variable] " | |
exit 1 | |
fi | |
local PROJECT_PATH=$1 | |
local CONFIGURATION=$2 | |
local OUTPUT_VAR=$3 | |
UUExtractXcodeBuildSetting "${PROJECT_PATH}" "${CONFIGURATION}" "PROJECT_DIR" PROJECT_DIR | |
UUExtractXcodeBuildSetting "${PROJECT_PATH}" "${CONFIGURATION}" "INFOPLIST_FILE" INFO_PLIST_FILE | |
UUDebugLog "UUGetFullPlistPath-PROJECT_DIR: ${PROJECT_DIR}" | |
UUDebugLog "UUGetFullPlistPath-INFO_PLIST_FILE: ${INFO_PLIST_FILE}" | |
PLIST_PATH="${PROJECT_DIR}/${INFO_PLIST_FILE}" | |
if [[ ${INFO_PLIST_FILE} == /* ]] | |
then | |
UUDebugLog "UUGetFullPlistPath-INFO_PLIST_FILE is absolute path, don't append project path" | |
PLIST_PATH="${INFO_PLIST_FILE}" | |
fi | |
eval $OUTPUT_VAR="'${PLIST_PATH}'" | |
} | |
function UUGenerateBuildNumber | |
{ | |
if [ $# -lt 3 ] | |
then | |
echo "Usage: UUGenerateBuildNumber [full path to xcode project] [configuration] [output var - full build number] " | |
exit 1 | |
fi | |
local PROJECT_PATH=$1 | |
local CONFIGURATION=$2 | |
local OUTPUT_VAR=$3 | |
UUExtractXcodeBuildSetting "${PROJECT_PATH}" "${CONFIGURATION}" "MARKETING_VERSION" MARKETING_VERSION | |
UUDebugLog "UUGenerateBuildNumber-MARKETING_VERSION: ${MARKETING_VERSION}" | |
BUILD_VERSION=${MARKETING_VERSION} | |
if [ $BUILD_NUMBER ] | |
then | |
UUDebugLog "Build number env var is set: ${BUILD_NUMBER}" | |
BUILD_VERSION="${BUILD_VERSION}.${BUILD_NUMBER}" | |
else | |
UUIsGitRepo IS_GIT_REPO | |
if [ ${IS_GIT_REPO} == 1 ] | |
then | |
UUReadGitRevisionNumber GIT_REV_NUMBER | |
BUILD_VERSION="${BUILD_VERSION}.${GIT_REV_NUMBER}" | |
fi | |
fi | |
UUDebugLog "UUGenerateBuildNumber-BUILD_VERSION: ${BUILD_VERSION}" | |
eval $OUTPUT_VAR="'${BUILD_VERSION}'" | |
} | |
function UUMakeIpa | |
{ | |
if [ $# -lt 3 ] | |
then | |
echo "Usage: UUMakeIpa [full path to archive] [full path to export plist] [output dir] " | |
exit 1 | |
fi | |
local ARCHIVE_PATH=$1 | |
local EXPORT_PLIST_FILE=$2 | |
local OUTPUT_DIR=$3 | |
TMP_FOLDER_NAME=`uuidgen` | |
TMP_EXPORT_PATH="/tmp/${TMP_FOLDER_NAME}" | |
xcodebuild \ | |
-exportArchive \ | |
-archivePath "${ARCHIVE_PATH}" \ | |
-exportOptionsPlist "${EXPORT_PLIST_FILE}" \ | |
-exportPath "${TMP_EXPORT_PATH}" | |
UUCheckReturnCode $? "Make IPA" | |
cp -r ${TMP_EXPORT_PATH}/*.ipa ${OUTPUT_DIR} | |
UUCheckReturnCode $? "Copy IPA" | |
rm -rf ${TMP_EXPORT_PATH} | |
UUCheckReturnCode $? "Remove Temp export folder" | |
} | |
function UUMakeBuildFixed | |
{ | |
if [ $# -lt 7 ] | |
then | |
echo "Usage: UUMakeBuildFixed [full path to xcode project] [scheme name] [full path to export plist] [cert path] [cert password] [profile path] [output dir] " | |
exit 1 | |
fi | |
local PROJECT_PATH=$1 | |
local SCHEME_NAME=$2 | |
local EXPORT_PLIST_FILE=$3 | |
local CERT_PATH=$4 | |
local CERT_PASSWORD=$5 | |
local PROFILE_PATH=$6 | |
local OUTPUT_DIR=$7 | |
UUDebugLog "PROJECT_PATH: ${PROJECT_PATH}" | |
TMP_KEYCHAIN_PATH="" | |
trap 'UUCleanupAfterBuild ${TMP_KEYCHAIN_PATH}' EXIT | |
rm -rf "${OUTPUT_DIR}" | |
UUMakeTempKeychain "${CERT_PATH}" "${CERT_PASSWORD}" TMP_KEYCHAIN_PATH | |
UUGenerateArchive "${PROJECT_PATH}" "${SCHEME_NAME}" "${PROFILE_PATH}" "${OUTPUT_DIR}" | |
# ARCHIVE_OUTPUT_PATH and FULL_VERSION_NUMBER are set by UUGenerateArchive | |
UUMakeIpa "${ARCHIVE_OUTPUT_PATH}" "${EXPORT_PLIST_FILE}" "${OUTPUT_DIR}" | |
mv ${OUTPUT_DIR}/*.ipa "${OUTPUT_DIR}/${OUTPUT_FILE_NAME}.ipa" | |
UUCheckReturnCode $? "Rename IPA" | |
} | |
function UUCleanupAfterBuild | |
{ | |
UUDebugLog "Doing final cleanup" | |
KEYCHAIN_PATH=$1 | |
if [ ! -z "${KEYCHAIN_PATH}" ] | |
then | |
UUDebugLog "Cleaning up temporary keychain" | |
UUCleanupBuildKeychain "${KEYCHAIN_PATH}" -v | |
else | |
UUDebugLog "No keychain to cleanup" | |
fi | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment