Skip to content

Instantly share code, notes, and snippets.

@ebaker355
Created October 8, 2012 23:00
Show Gist options
  • Save ebaker355/3855497 to your computer and use it in GitHub Desktop.
Save ebaker355/3855497 to your computer and use it in GitHub Desktop.
Increment Xcode project build number
#!/usr/bin/ruby
# Call via a run script build phase:
#
# ${SRCROOT}/IncrementBuildNumber.rb
#
require 'fileutils'
require 'pathname'
project_path = Pathname.new(ENV['SOURCE_ROOT'])
project_name = ENV['PROJECT_NAME']
plist_file = project_path + project_name + "#{project_name}-Info.plist"
unless File.exists?(plist_file)
puts "cannot find project info.plist file at path: #{plist_file}"
exit 1
end
v = `/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "#{plist_file}" 2>/dev/null`
v.strip!
if v.empty?
puts "\"#{plist_file}\" does not contain key: \"CFBunleVersion\""
exit 2
end
v_parts = v.split('.')
unless v_parts.count == 4
puts "\"#{v}\" is not in expected format: 0.0.0.0"
exit 3
end
major = v_parts[0]
minor = v_parts[1]
revision = v_parts[2]
build = Integer("#{v_parts[3]}")
build += 1
`/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion #{major}.#{minor}.#{revision}.#{build.to_s}\" \"#{plist_file}\"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment