Created
October 8, 2012 23:00
-
-
Save ebaker355/3855497 to your computer and use it in GitHub Desktop.
Increment Xcode project build number
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
#!/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