Here's a little shell script to increment a build number automatically with each build.
It assumes the following about your versions in info.plist:
- Your product version is CFBundleShortVersionString in info.plist
eg 1.0.0
- Your build number is appended to your product version in CFBundleVersion
eg 1.0.0.133
Step by step:
- Enter some default values in info.plist
Bundle versions string, short: 0.1.0 (CFBundleShortVersionString)
Bundle version: 0.1.0.1 (CFBundleVersion)
- Select your Target in Xcode
- Add a new run script build phase:
Project -> New Build Phase -> New Run Script Build Phase
- Paste the script below into the script box
- Build your project
version=$(sed -n '
/^[[:blank:]]*CFBundleShortVersionString<\/key>$/ {
N
s/^[[:blank:]]*CFBundleShortVersionString<\/key>\n[[:blank:]]*\(.*\)<\/string>/\1/
p
}' info.plist)
build=$(sed -n '
/^[[:blank:]]*CFBundleVersion<\/key>$/ {
N
s/^[[:blank:]]*CFBundleVersion<\/key>\n[[:blank:]]*.*\.\(.*\)<\/string>/\1/
p
}' info.plist)
build=$(($build +1))
cp Info.plist 'Backup of Info.plist'
sed '
/^[[:blank:]]*CFBundleVersion<\/key>$/ {
N
s/\(\).*\(<\/string>\)/\1'"$version\.$build"'\2/
P
D
}' 'Backup of info.plist' > Info.plist
Each time you build using that target the build number will be incremented. A backup of your info.plist is made (just in case).
You could easily extend this script to commit files to your subversion repository.
The script uses multi-line sed and I'm no sed magician. If you're looking for a sed tutorial try
here.