Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save CodeEagle/60407b75a6eb1bf7285e to your computer and use it in GitHub Desktop.
Save CodeEagle/60407b75a6eb1bf7285e to your computer and use it in GitHub Desktop.
Xcode Team Adding Build Number Shell Script
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
currentUser="$USER"
cretePlist() {
cat > build.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>$currentUser</key>
<string>1</string>
<key>users</key>
<string>$currentUser</string>
</dict>
</plist>
EOF
}
[ -f ${PROJECT_DIR}/build.plist ] && echo "Found build.plist" || cretePlist
users=$(/usr/libexec/PlistBuddy -c "Print users" "${PROJECT_DIR}/build.plist")
mybuild=$(/usr/libexec/PlistBuddy -c "Print $currentUser" "${PROJECT_DIR}/build.plist")
alreadyIn=0
if [[ $users == *"$currentUser"* ]]
then
alreadyIn=1
fi
if [ ${alreadyIn} -eq 0 ];
then
users="$users|$currentUser"
build=1
/usr/libexec/PlistBuddy -c "Set :users $users" "${PROJECT_DIR}/build.plist"
/usr/libexec/PlistBuddy -c "Add :$currentUser string $build" "${PROJECT_DIR}/build.plist"
else
mybuild=$(($mybuild + 1))
/usr/libexec/PlistBuddy -c "Set :$currentUser $mybuild" "${PROJECT_DIR}/build.plist"
fi
# only update build number on release mode
if [ "${CONFIGURATION=}" == "Debug" ]; then
echo "not change build number in debug, only in archive mode for submit"
else
IFS='|' read -ra ADDR <<< "$users"
totalBuild=0
for i in "${ADDR[@]}"; do
memberbuild=$(/usr/libexec/PlistBuddy -c "Print $i" "${PROJECT_DIR}/build.plist")
totalBuild=$(($totalBuild + $memberbuild))
done
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $totalBuild" "${PROJECT_DIR}/${INFOPLIST_FILE}"
fi
@CodeEagle
Copy link
Author

Important!!!!!!!!

When you copy and paste this code to you run script
You need to add some fix

    cretePlist() {
  cat > build.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
      <key>$currentUser</key>
      <string>1</string>
      <key>users</key>
      <string>$currentUser</string>
</dict>
</plist>
EOF
}

You need to remove whitespace before the Second EOF!!!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment