Skip to content

Instantly share code, notes, and snippets.

@jourdein
Last active December 15, 2015 03:49
Show Gist options
  • Save jourdein/5196772 to your computer and use it in GitHub Desktop.
Save jourdein/5196772 to your computer and use it in GitHub Desktop.
Build number based on Git revision and incremented build number (the last number). The number separated by decimal. i.e. 121.5432
#!/bin/bash
git=/usr/local/git/bin/git
touch "${PROJECT_DIR}/${INFOPLIST_FILE}"
gitBuildNumber=`$git log --oneline | wc -l`
echo "#define BUILD_VERSION $gitBuildNumber" > NST/NST-InfoPlist.h
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
majorVersion=$gitBuildNumber
#`echo "scale=0; $buildNumber / 1" | bc`
floatingPartAsInteger=`echo "$buildNumber % 1" | bc`
multiplication=`echo "10^length($floatingPartAsInteger)" | bc`
incrementedBuildNumber=`echo "($floatingPartAsInteger * $multiplication / 1) + 1" | bc`
buildNumber=`echo "scale=length($incrementedBuildNumber); $majorVersion + ($incrementedBuildNumber / 10^length($incrementedBuildNumber))" | bc`
# http://semver.org/
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment