Skip to content

Instantly share code, notes, and snippets.

@ryantenney
Created October 7, 2012 19:23
Show Gist options
  • Save ryantenney/3849307 to your computer and use it in GitHub Desktop.
Save ryantenney/3849307 to your computer and use it in GitHub Desktop.
# 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