Last active
December 18, 2015 02:39
-
-
Save sendoa/5712368 to your computer and use it in GitHub Desktop.
This script will auto-increment your Xcode project's build number for every build (debug & release). It will also increment the third position of a semantic formatted version string only for release builds: Examples:
Build number: from 123 to 124
Version string: from 1.2.5 to 1.2.6
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
# This script will auto-increment your Xcode project's build number for every build (debug & release). | |
# It will also increment the third position of a semantic formatted version string only for release builds | |
# | |
# Examples: | |
# Buil number (CFBundleVersion): from 123 to 124 | |
# Version string (CFBundleShortVersionString): from 1.2.5 to 1.2.6 | |
# | |
# 1. Select your Target in Xcode | |
# 2. Select "Build Phases" Tab | |
# 3. Select "Add Build Phase" -> "Add Run Script" | |
# 4. Paste code below into the "Run Script" section | |
# 5. Ensure your starting version number (CFBundleShortVersionString) is in semantic versioning format (e.g. 1.0.0) | |
# 6. Ensure your starting build number (CFBundleVersion) is an integer number (e.g. 1) | |
#!/bin/bash | |
# Get project info | |
buildPlist="${PROJECT_DIR}/${INFOPLIST_FILE}" | |
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist") | |
versionString=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$buildPlist") | |
# Increment build number for every build | |
if [ "$CONFIGURATION" == "Debug" ] || [ "$CONFIGURATION" == "Release" ]; then | |
# Increment the buildNumber (A.K.A CFBundleVersion) | |
buildNumber=$(($buildNumber + 1)) | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$buildPlist" | |
fi | |
# Increment version string only for release builds | |
if [ "$CONFIGURATION" == "Release" ]; then | |
#Increment the version string (A.K.A. CFBundleShortVersionString) | |
newSubversion=`echo $versionString| awk -F "." '{print $3}'` | |
newSubversion=$(($newSubversion + 1)) | |
newVersionString=`echo $versionString| awk -F "." '{print $1 "." $2 ".'$newSubversion'" }'` | |
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $newVersionString" "$buildPlist" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
newSubversion=
echo $versionString| awk -F "." '{print $3}'
is "`" simbol legual ?