Skip to content

Instantly share code, notes, and snippets.

@slycrel
Created August 30, 2017 16:06
Show Gist options
  • Save slycrel/5a372a7f7fa8c0f94f063e0bc7e45b2f to your computer and use it in GitHub Desktop.
Save slycrel/5a372a7f7fa8c0f94f063e0bc7e45b2f to your computer and use it in GitHub Desktop.
git versioning script for XCode
# ---------------------------- IMPORTANT ----------------------------
# You must set GITHash to something like 'Set by build script' in the file
# file '<Project Name>-Info.plist' in the 'Supporting Files' group
# -------------------------------------------------------------------
#
# Get the version number from the tag in git and the number of commits as the build number
#
appVersion=$(git describe --tags --abbrev=0)
appBuild=$(git rev-list HEAD --count)
gitHash=$(git rev-parse --short HEAD)
echo "From GIT Version = $appVersion Build = $appBuild"
#
# Set the version info in plist file
#
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $appVersion" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :GITHash $gitHash" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
echo "Updated ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment