Last active
July 4, 2020 10:32
-
-
Save CodeEagle/60407b75a6eb1bf7285e to your computer and use it in GitHub Desktop.
Xcode Team Adding Build Number Shell Script
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Important!!!!!!!!
When you copy and paste this code to you run script
You need to add some fix
You need to remove whitespace before the Second
EOF
!!!!!!!