Skip to content

Instantly share code, notes, and snippets.

@jcmendez
Last active August 29, 2015 13:57
Show Gist options
  • Save jcmendez/9896408 to your computer and use it in GitHub Desktop.
Save jcmendez/9896408 to your computer and use it in GitHub Desktop.
Linking git hashes and Xcode for builds
# Assumes that we 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_def="${SRCROOT}/git_version.h"
touch "${plist_def}"
# Use Xcode's copy of the Git binary
GIT=`xcrun -find git`
# Get the build hash from git
githash=`${GIT} rev-parse HEAD | cut -c1-6`
# Get the version and build numbers
versionnum=`${GIT} describe --tags | awk '{split($0,a,"-"); print a[1]}'`
buildnum=`${GIT} describe --tags | awk '{split($0,a,"-"); print a[1] "." a[2]}'`
if [[ "${githash}" == "" ]]; then
echo "No hash obtained from git"
exit 2
fi
if [[ "${versionnum}" == "" ]]; then
echo "No version number from git"
exit 2
fi
if [[ "${buildnum}" == "" ]]; then
echo "No build number from git"
exit 2
fi
echo "#define __GIT_BUILDNUM__ ${buildnum}" > "${plist_def}"
echo "#define __GIT_VERSIONNUM__ ${versionnum}" >> "${plist_def}"
echo "#define __GIT_HASH__ ${githash}" >> "${plist_def}"
echo "Updated version numbers"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment