Skip to content

Instantly share code, notes, and snippets.

@alexkent
Created December 7, 2016 22:47
Show Gist options
  • Save alexkent/6b313a552713f21023cc3963596e3406 to your computer and use it in GitHub Desktop.
Save alexkent/6b313a552713f21023cc3963596e3406 to your computer and use it in GitHub Desktop.
update build number during as build phase
#!/bin/bash
# update_build_number.sh
# Usage: `update_build_number.sh [branch]`
# Run this script after the 'Copy Bundle Resources' build phase
# Ref: http://tgoode.com/2014/06/05/sensible-way-increment-bundle-version-cfbundleversion-xcode/
branch=${1:-'develop'}
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"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment