Skip to content

Instantly share code, notes, and snippets.

@tomisacat
Created November 23, 2016 10:48
Show Gist options
  • Save tomisacat/21f5d4eba343573be9c8600db156befa to your computer and use it in GitHub Desktop.
Save tomisacat/21f5d4eba343573be9c8600db156befa to your computer and use it in GitHub Desktop.
Bump build number of Xcode project automatically
#!/bin/sh
# bump_build_number_per_build.sh
# @desc Automaticvally create build number depend on current time.
# @usage
# 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"
# Year
YEAR=`date | awk '{print $6}'`
# Month
MONTH=`date | awk '{print $2}'`
case "$MONTH" in
'Jan' | [Jj][Aa][Na])
MONTHNUMBER=01
;;
'Feb' |[Ff][Ee][Bb])
MONTHNUMBER=02
;;
'Mar' |[Mm][Aa][Rr])
MONTHNUMBER=03
;;
'Apr' |[Aa][Pp][Rr])
MONTHNUMBER=04
;;
'May' |[Mm][Aa][Yy])
MONTHNUMBER=05
;;
'Jun' |[Jj][Uu][Nn])
MONTHNUMBER=06
;;
'Jul' |[Jj][Uu][Ll])
MONTHNUMBER=07
;;
'Aug' |[Aa][Uu][Gg])
MONTHNUMBER=08
;;
'Sep' |[Ss][Ee][Pp])
MONTHNUMBER=09
;;
'Oct' |[Oo][Cc][Tt])
MONTHNUMBER=10
;;
'Nov' |[Nn][Oo][Vv])
MONTHNUMBER=11
;;
'Dec' |[Dd][Ee][Cc])
MONTHNUMBER=12
;;
esac
echo "month $MONTHNUMBER"
# Date
DATE=`date | awk '{print $3}'`
if [[ DATE -lt 10 ]]; then
DATE=0$DATE
fi
TIME=`date | awk '{print $4}'`
TIMEARRAY=$(echo $TIME | tr ":" "\n")
TIMENUMBER=""
for component in $TIMEARRAY
do
TIMENUMBER=$TIMENUMBER$component
done
buildNumber=$YEAR$MONTHNUMBER$DATE$TIMENUMBER
echo "Final Build number is $buildNumber"
## Write buildNumber to the property list
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
@tomisacat
Copy link
Author

Automatically bump build version when executing build operation.

usage

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"

result

It will automatically modify the buildNumber property of info.Plist file like 20160802105320 if current time is Wed Aug 3 10:53:20 CST 2016.

reference

  1. reference code.
  2. A stackoverflow question.

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