Created
April 3, 2014 19:38
-
-
Save CocoaBeans/9961323 to your computer and use it in GitHub Desktop.
This script automatically sets the version and short version string of an Xcode project from the Git repository containing the project. To use this script in Xcode 4, add the contents to a "Run Script" build phase for your application target.
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
#!/bin/bash -x | |
# This script automatically sets the version and short version string of | |
# an Xcode project from the Git repository containing the project. | |
# | |
# To use this script in Xcode 4, add the contents to a "Run Script" build | |
# phase for your application target. | |
set -o errexit | |
set -o nounset | |
INFO_PLIST="${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Contents/Info" | |
# Use the latest version tag for CFBundleShortVersionString. I tag releases | |
# in Git using the format v0.0.0; this assumes you're doing the same. | |
#SHORT_VERSION=$(git --git-dir="${PROJECT_DIR}/../../.git" --work-tree="${PROJECT_DIR}/../../" describe --dirty | sed -e 's/^v//' -e 's/g//') | |
# Let's add the Git commit hash for to the Info.plist in a custom key KRBuildVersion. | |
BUILD_VERSION=$(git --git-dir="${PROJECT_DIR}/../../.git" --work-tree="${PROJECT_DIR}/../../" rev-parse --short HEAD) | |
# But Apple wants this value to be a monotonically increasing integer, so | |
# instead use the number of commits on the master branch. If you like to | |
# play fast and loose with your Git history, this may cause you problems. | |
# Thanks to @amrox for pointing out the issue and fix. | |
VERSION=$(git --git-dir="${PROJECT_DIR}/../../.git" --work-tree="${PROJECT_DIR}/../../" rev-list HEAD | wc -l) | |
#defaults write "$INFO_PLIST" CFBundleShortVersionString $SHORT_VERSION | |
defaults write "$INFO_PLIST" CFBundleVersion $VERSION | |
defaults write "$INFO_PLIST" KRBuildVersion $BUILD_VERSION | |
# Set read/write permissions to defaults | |
chmod =rw "$INFO_PLIST".plist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment