Created
October 7, 2012 19:23
-
-
Save ryantenney/3849307 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Derived from: http://digitalflapjack.com/blog/2012/may/09/buildnumbers/ | |
# Assumes that you tag versions with the version number (e.g., "1.1") and then the build number is | |
# that plus the number of commits since the tag (e.g., "1.1.17") | |
echo "Updating version/build number from git..." | |
plist=${PROJECT_DIR}/${INFOPLIST_FILE} | |
desc=`git describe` | |
commits=`echo $desc | awk '{split($0,a,"-"); print a[2]}'` | |
if [[ "${commits}" == "" ]]; then | |
desc="$desc-0" | |
fi | |
# increment the build number (ie 115 to 116) | |
versionnum=`echo $desc | awk '{split($0,a,"-"); print a[1]}'` | |
revisionnum=`echo $desc | awk '{split($0,a,"-"); print a[1] "." a[2]}'` | |
lastbundleversion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}"` | |
lastrevisionnum=`echo $lastbundleversion | awk '{split($0,a,"."); print a[1] "." a[2] "." a[3]}'` | |
lastbuildnum=`echo $lastbundleversion | awk '{split($0,a,"."); print a[4]}'` | |
if [[ "${versionnum}" == "" ]]; then | |
echo "No version number from git" | |
exit 2 | |
fi | |
if [[ "${revisionnum}" == "" ]]; then | |
echo "No revision number from git" | |
exit 2 | |
fi | |
nextbuildnum=0 | |
if [[ "${lastrevisionnum}" == "${revisionnum}" ]]; then | |
nextbuildnum=$(($lastbuildnum + 1)) | |
fi | |
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $versionnum" "${plist}" | |
echo "Updated version number to $versionnum" | |
buildnum="$revisionnum.$nextbuildnum" | |
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $buildnum" "${plist}" | |
echo "Updated build number to $buildnum" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment