Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Update current Xcode target's build number with the number of commits on a specified branch.
# Usage: ` [branch]`
# Run this script after the 'Copy Bundle Resources' build phase
# Ref:
buildNumber=$(expr $(git rev-list $branch --count) - $(git rev-list HEAD..$branch --count))
echo "Updating build number to $buildNumber using branch '$branch'."
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
if [ -f "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment