Last active
February 5, 2018 14:45
-
-
Save imkevinxu/7a4fe9f258edec42eee9 to your computer and use it in GitHub Desktop.
Xcode build phase script to increment the build number on every build or every commit
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
if [ -z "${PROJECT_DIR}" ]; then | |
PROJECT_DIR=`pwd` | |
fi | |
if [ -z "${PREFIX}" ]; then | |
PREFIX="" | |
fi | |
SVN_DIR="${PROJECT_DIR}/.svn" | |
GIT_DIR="${PROJECT_DIR}/.git" | |
if [ -d "${GIT_DIR}" ]; then | |
if [ -z "${GIT_BRANCH}" ]; then | |
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` | |
fi | |
BUILD_NUMBER=`xcrun git rev-list ${GIT_BRANCH} | wc -l | tr -d ' '` | |
BUILD_HASH=`xcrun git rev-parse --short --verify ${GIT_BRANCH} | tr -d ' '` | |
elif [ -d "${SVN_DIR}" ]; then | |
BUILD_NUMBER=`xcrun svnversion -nc "${PROJECT_DIR}" | sed -e 's/^[^:]*://;s/[A-Za-z]//' | tr -d ' '` | |
BUILD_HASH="${BUILD_NUMBER}" | |
else | |
BUILD_NUMBER="1" | |
BUILD_HASH="1" | |
fi | |
OLD_BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}") | |
if [ "${BUILD_NUMBER}" != "${OLD_BUILD_NUMBER}" ]; then | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "${PROJECT_DIR}/${INFOPLIST_FILE}" | |
fi |
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
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}") | |
buildNumber=$(($buildNumber + 1)) | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot of Xcode configuration