Created
March 27, 2013 19:36
-
-
Save aschober/5257338 to your computer and use it in GitHub Desktop.
XCode script to automatically create Version and Build values from Git repo description. Based on multiple sources.
This file contains 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 | |
# 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}/Info" | |
# Get git tag and hash in the FulLVersion | |
FULL_VERSION=$(git --work-tree="${PROJECT_DIR}/" describe --dirty | sed -e 's/^v//' -e 's/g//') | |
# Use the latest tag for short version (You'll have to make sure that all your tags are of the format 0.0, | |
# this is to satisfy Apple's rule that short version be three integers separated by dots) | |
SHORT_VERSION=$(git --work-tree="${PROJECT_DIR}/" describe | awk '{split($0,a,"-"); print a[1]}') | |
VERSION=$(git --work-tree="${PROJECT_DIR}/" describe | awk '{split($0,a,"-"); print a[1] "." a[2]}') | |
# Check to see if the tag starts with with "ver", and remove if so. | |
if [[ "${VERSION}" == ver* ]]; then | |
SHORT_VERSION="${SHORT_VERSION#*ver}" | |
VERSION="${VERSION#*ver}" | |
defaults write $INFO_PLIST CFBundleShortVersionString $SHORT_VERSION | |
defaults write $INFO_PLIST CFBundleVersion $VERSION | |
defaults write $INFO_PLIST FullVersion $FULL_VERSION | |
echo "CFBundleVersion: ${VERSION}" | |
echo "CFBundleShortVersionString: ${SHORT_VERSION}" | |
echo "FullVersion: ${FULL_VERSION}" | |
else | |
echo "ERROR: DID NOT FIND 'ver*' in Git Tag! Make sure tag exists! e.g. ver0.1" | |
exit 2 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment