Skip to content

Instantly share code, notes, and snippets.

@jaredsinclair
Last active January 1, 2020 15:41
Show Gist options
  • Save jaredsinclair/af6898f93674ee5923f3 to your computer and use it in GitHub Desktop.
Save jaredsinclair/af6898f93674ee5923f3 to your computer and use it in GitHub Desktop.
Git-friendly run script for automated build numbering in Xcode
# Set the build number to the current git commit count.
#
# Permanent home:
# https://gist.github.com/jaredsinclair/af6898f93674ee5923f3
#
# Based on: http://w3facility.info/question/how-do-i-force-xcode-to-rebuild-the-info-plist-file-in-my-project-every-time-i-build-the-project/
# Updated with dSYM handling from http://yellowfeather.co.uk/blog/auto-incrementing-build-number-in-xcode-revisited/
git=`sh /etc/profile; which git`
appBuild=`"$git" rev-list HEAD --count`
settingsBundleDir="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Settings.bundle"
settingsPlist="${settingsBundleDir}/Root.plist"
appVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" )
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue $appVersion" "${settingsPlist}"
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:2:DefaultValue $appBuild" "${settingsPlist}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
echo "Incremented the build number ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment