Skip to content

Instantly share code, notes, and snippets.

@digitalpardoe
Last active October 4, 2015 13:28
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 digitalpardoe/2644629 to your computer and use it in GitHub Desktop.
Save digitalpardoe/2644629 to your computer and use it in GitHub Desktop.
Automatic Build Number In Xcode
#!/bin/bash
#
# Automatically sets the build number for a target in Xcode based
# on either the Subversion revision or Git hash depending on the
# version control system being used
#
# Simply add this script as a 'Run Script' build phase for any
# target in your project
#
git status
if [ "$?" -eq "0" ]
then
git svn info
if [ "$?" -eq "0" ]
then
buildNumber=$(git svn info | grep Revision | awk '{print $2}')
else
buildNumber=$(git rev-parse HEAD | cut -c -10)
fi
elif [ -d ".svn" ]
then
buildNumber=$(svn info | grep Revision | awk '{print $2}')
else
buildNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" Source/Application-Info.plist)
fi
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" Source/Application-Info.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment