Auto incrementing build number in Xcode revisited

July 29, 2015

For sometime now, I’ve been using the script in the post The Best of All Possible Xcode Automated Build Numbering Techniques to automatically update the build number in Xcode based on the number of git commits. Unfortunately this script doesn’t update the version number in the dSYM bundle, which causes Hockey to complain when uploading a new build. A quick search found the answer in a comment on this post A sensible way to increment bundle version (CFBundleVersion) in Xcode

Here’s the complete script:

git=`sh /etc/profile; which git`
appBuild=`$git rev-list --all | wc -l`
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 "Updated ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"