Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stealthv/47e0637a2fbd3f8fc998e55e701258e8 to your computer and use it in GitHub Desktop.
Save stealthv/47e0637a2fbd3f8fc998e55e701258e8 to your computer and use it in GitHub Desktop.
Simple, Git-friendly run script for automated build numbering in Xcode
#
# Set the build number to the current git commit count.
# If we're using the Dev scheme, then we'll suffix the build
# number with the current branch name, to make collisions
# far less likely across feature branches.
# 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`
if [ $CONFIGURATION = "Debug" ]; then
branchName=`"$git" rev-parse --abbrev-ref HEAD`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild-$branchName" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild-$branchName" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
else
/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"
fi
echo "Incremented the build number to $appBuild on ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
@stealthv
Copy link
Author

stealthv commented Nov 19, 2016

To use just go to Build Phases and add a Run Script phase after Copy Bundle Resources

See related blog post at: http://blog.jaredsinclair.com/post/97193356620/the-best-of-all-possible-xcode-automated-build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment