Skip to content

Instantly share code, notes, and snippets.

@bulwinkel
Created October 9, 2018 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bulwinkel/cb19bc13581359e18c2b3bd69febcadf to your computer and use it in GitHub Desktop.
Save bulwinkel/cb19bc13581359e18c2b3bd69febcadf to your computer and use it in GitHub Desktop.
iOS Git Versioning
#!/usr/bin/env bash
# set-version-from-git.sh
# Usage: `set-version-from-git.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/
# Sets the build and version numbers in the compiled app bundle so it doesn't
# modify your version controlled info.plist
branch=${1:-'master'}
buildNumber=$(expr $(git rev-list $branch --count) - $(git rev-list HEAD..$branch --count))
echo "Updating build number to $buildNumber using branch '$branch'."
versionNumber=$(git describe --tags)
echo "Version from tag: $versionNumber"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $versionNumber" "${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"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $versionNumber" "${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