Skip to content

Instantly share code, notes, and snippets.

@inket
Last active January 2, 2016 06:29
Show Gist options
  • Save inket/8263351 to your computer and use it in GitHub Desktop.
Save inket/8263351 to your computer and use it in GitHub Desktop.
My own take of versioning with Xcode and git.
# This build script is based on http://kylefuller.co.uk/posts/versioning-with-xcode-and-git/
# Difference is that instead of having to use git to increment your app's version (git tag <version>),
# you could simply use Xcode as usual. This script would automatically create a tag for that version if it's a new one.
CURRENT_TAG=$(git describe --tags --abbrev=0)
CURRENT_VERSION=$(defaults read "${SOURCE_ROOT}/${INFOPLIST_FILE%.*}" "CFBundleShortVersionString")
# Create a tag for this version, if it doesn't exist
if [[ $CURRENT_VERSION != $CURRENT_TAG ]];
then git tag $CURRENT_VERSION;
fi
# What's new here: removes object name and replaces "-dirty" with "d"
GIT_RELEASE_VERSION=$(git describe --tags --always --dirty | sed 's/-[a-z0-9]\{8\}//g' | sed 's/-dirty/d/g')
COMMITS=$(git rev-list HEAD | wc -l)
COMMITS=$(($COMMITS))
defaults write "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*}" "CFBundleShortVersionString" "${GIT_RELEASE_VERSION#*v}"
defaults write "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*}" "CFBundleVersion" "${COMMITS}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment