Skip to content

Instantly share code, notes, and snippets.

@ctreffs
Created February 5, 2021 13:38
Show Gist options
  • Save ctreffs/686c3b3ec7f527a28ba7b2a626390d2f to your computer and use it in GitHub Desktop.
Save ctreffs/686c3b3ec7f527a28ba7b2a626390d2f to your computer and use it in GitHub Desktop.
Increase build number in plist
#!/bin/sh
# fail fast & fail uninizialized
set -ex
GIT=`xcrun -find git`
if [[ -n $1 && $1 == "YES" ]]; then paket=true; else paket=false; fi
if [[ -n $2 && $2 == "YES" ]]; then watch=true; else watch=false; fi
if [[ -n $3 && $3 == "YES" ]]; then appex=true; else appex=false; fi
if [[ -n $4 && $4 == "YES" ]]; then pushe=true; else pushe=false; fi
if [ $appex == true ]; then
PLIST_IOS_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.appex/Info.plist"
elif [ $pushe == true ]; then
PLIST_IOS_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.appex/Info.plist"
else
PLIST_IOS_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Info.plist"
fi
if [ $paket == true ]; then
PLIST_PUSHE_PATH=`echo "${BUILT_PRODUCTS_DIR}/${PUSHE_TARGET_NAME}.app/Info.plist" | sed -E s/iphone\(os\|simulator\)/watch\\\1/`
PLIST_WATCH_PATH=`echo "${BUILT_PRODUCTS_DIR}/${WATCH_TARGET_NAME}.app/Info.plist" | sed -E s/iphone\(os\|simulator\)/watch\\\1/`
PLIST_WATCH_APPEX_PATH=`echo "${BUILT_PRODUCTS_DIR}/${WATCH_APPEX_NAME}.appex/Info.plist" | sed -E s/iphone\(os\|simulator\)/watch\\\1/`
PLIST_WATCH_EMBED_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/${WATCH_FOLDER}/${WATCH_TARGET_NAME}.app/Info.plist"
PLIST_WATCH_APPEX_EMBED_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/${WATCH_FOLDER}/${WATCH_TARGET_NAME}.app/PlugIns/${WATCH_APPEX_NAME}.appex/Info.plist"
fi
dir="$( cd "$(dirname "$0")" ; pwd -P )"
# Use the commit count before HEAD as CFBundleVersion
GIT_COMMIT_COUNT=$($dir/get_build_number.sh $GIT)
## Use the last annotated 'develop' tag as CFBundleShortVersionString
VERSION=$($dir/get_version_number.sh $GIT)
setInInfo () { # Info.plist path, Build, Version?
PlistBuddy=/usr/libexec/PlistBuddy
INFO_PLIST=$1
INFO_BUILD=$2
INFO_VERSION=$3
OPTIONAL=$4
if [[ -z $INFO_VERSION ]]; then
INFO_VERSION=$INFO_BUILD
fi
if [ -e $PlistBuddy ]; then
if ls "${INFO_PLIST}" 1> /dev/null 2>&1; then
$PlistBuddy -c "Set :CFBundleVersion ${INFO_BUILD}" "${INFO_PLIST}"
$PlistBuddy -c "Set :CFBundleShortVersionString ${INFO_VERSION}" "${INFO_PLIST}"
$PlistBuddy -c "Save" "${INFO_PLIST}"
elif [[ $OPTIONAL == false ]]; then
echo "error: ${INFO_PLIST} was not present"
else
echo "warning: ${INFO_PLIST} was not present"
fi
else
echo "error: PlistBuddy is not installed"
exit
fi
}
setDefaultsInInfo () { # Info.plist path
setInInfo "${1}" $GIT_COMMIT_COUNT $VERSION $2
}
## Set Build/Version in Plists
setDefaultsInInfo "${PLIST_IOS_PATH}" false
if [ $paket == true ]; then
setDefaultsInInfo "${PLIST_PUSHE_PATH}" true
setDefaultsInInfo "${PLIST_WATCH_PATH}" true
setDefaultsInInfo "${PLIST_WATCH_APPEX_PATH}" true
setDefaultsInInfo "${PLIST_WATCH_EMBED_PATH}" true
setDefaultsInInfo "${PLIST_WATCH_APPEX_EMBED_PATH}" true
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment