I\'m using Xcode 4 in combination with Git and would like to increment the CFBundleVersion in Info.plist on each build. The value for the key CFBundleVersion should be updat
This works perfectly for me
#!/usr/bin/ruby
require 'rubygems'
begin
require 'Plist'
rescue LoadError => e
puts "You need to install the 'Plist' gem: [sudo] gem install plist"
exit 1
end
raise "Must be run from Xcode" unless ENV['XCODE_VERSION_ACTUAL']
GIT = "/usr/bin/env git"
PRODUCT_PLIST = File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH'])
HASH = `#{GIT} log -1 --pretty=format:%h`
BUNDLE_VERSION = "CFBundleVersion"
if File.file?(PRODUCT_PLIST) and HASH
# update product plist
`/usr/bin/plutil -convert xml1 \"#{PRODUCT_PLIST}\"`
info = Plist::parse_xml(PRODUCT_PLIST)
if info
info[BUNDLE_VERSION] = HASH
info["GCGitCommitHash"] = HASH
info.save_plist(PRODUCT_PLIST)
end
`/usr/bin/plutil -convert binary1 \"#{PRODUCT_PLIST}\"`
# log
puts "updated #{BUNDLE_VERSION} to #{HASH}"
puts "HEAD: #{HASH}"
end