Skip to content

Instantly share code, notes, and snippets.

@Kjuly
Created February 22, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kjuly/1450f2b01a9f5f901dc9 to your computer and use it in GitHub Desktop.
Save Kjuly/1450f2b01a9f5f901dc9 to your computer and use it in GitHub Desktop.
Xcode run script for version, whenever build a new version, can choose to increase bundle version, update build date & git latest commit hash.
#!/bin/bash
#
# Xcode run script for version, whenever build a new version,
# can choose to increase bundle version, update build date
# & git latest commit hash.
#
#
# Usage:
#
# Copy this file under the root folder of the project, and make sure it's executable:
#
# $ chmod +x ky_xcode_runscript_for_version.sh
#
# Update project settings:
#
# Xcode Project -> Choose Target -> Build Phases -> Add Run Script Phase -> Add content:
#
# ./ky_xcode_runscript_for_version.sh
#
#
infoPlist=$SRCROOT/$INFOPLIST_FILE
PlistBuddy="/usr/libexec/PlistBuddy"
# Bundle Version
#
# Increase bundle version every time when build the project.
#
#CFBundleVersion=`$PlistBuddy -c "Print CFBundleVersion" $infoPlist`
#CFBundleVersion=$(($CFBundleVersion + 1))
#$PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" $infoPlist
#
# Build Date
#
#CFBuildDate=$(date +%Y%m%d%H%M%S)
CFBuildDate=$(date -u +"%a %b %d %T GMT %Y")
/usr/libexec/PlistBuddy -c "Set :CFBuildDate $CFBuildDate" $infoPlist
#
# git commit hash
#
cd $PROJECT_DIR
# BUILD_VERSION=`/usr/local/bin/git rev-parse --short HEAD`
BUILD_VERSION=`git rev-parse --short=6 HEAD`
cd "$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app"
RELEASE_VERSION=$($PlistBuddy -c "Print CFBundleShortVersionString" $infoPlist)
# 4 here is the index of version part in |PreferenceSpecifiers| array
$PlistBuddy -c "Set :PreferenceSpecifiers:4:DefaultValue $RELEASE_VERSION ($BUILD_VERSION)" Settings.bundle/Root.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment