Skip to content

Instantly share code, notes, and snippets.

@Lascorbe
Last active December 18, 2015 02:39
Show Gist options
  • Save Lascorbe/5712601 to your computer and use it in GitHub Desktop.
Save Lascorbe/5712601 to your computer and use it in GitHub Desktop.
Auto-increment your Xcode project's build number
# 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 1.2.1235 to 1.2.1236
# 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)
# Requeriments: https://github.com/nomad/shenzhen by @mattt
#!/bin/bash
# Get project info
PROJDIR="."
ICON_DIR="@${PROJDIR}/Icon.png"
buildPlist="@${PROJECT_DIR}/${INFOPLIST_FILE}"
appBundleID=$(/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "$buildPlist")
appName=$(/usr/libexec/PlistBuddy -c "Print CFBundleDisplayName" "$buildPlist")
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)
newbuildNumber=`echo $buildNumber| awk -F "." '{print $3}'`
newbuildNumber=$(($newbuildNumber + 1))
newBuildNumberString=`echo $versionString| awk -F "." '{print $1 "." $2 ".'$newbuildNumber'" }'`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $newBuildNumberString" "$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"
# Compile && Archive
ipa build -c "$CONFIGURATION"
# Upload IPA
echo Uploading IPA...
json=$(curl -s -i "https://api.appsendr.com/v1/app/new" -X POST \
-F "identifier=@${appBundleID}" \
-F "app_data=@${appName}.ipa" \
-F "icon=@${ICON_DIR}")
IPA_URL=$(echo $json | grep -o 'http[s]*:[^"}]*')
echo $IPA_URL | pbcopy
echo $IPA_URL copied to clipboard!
# Cleaning up
rm -rf ${PROJDIR}/build/
rm ${PROJDIR}/${APPLICATION_NAME}.ipa
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment