Skip to content

Instantly share code, notes, and snippets.

@humblehacker
Created September 27, 2012 16:23
Show Gist options
  • Save humblehacker/3794933 to your computer and use it in GitHub Desktop.
Save humblehacker/3794933 to your computer and use it in GitHub Desktop.
Ruby script to update version numbers in iOS projects
#!/usr/bin/env ruby
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + './../lib')
require 'gli'
require 'version'
require 'versionomy'
include GLI::App
#version Version::VERSION
desc 'Describe some switch here'
switch [:s,:switch]
desc 'Describe some flag here'
default_value 'the default'
arg_name 'The name of the argument'
flag [:f,:flagname]
desc 'Display current version info'
arg_name 'Describe arguments to bump here'
command :stat do |c|
c.action do |global_options,options,args|
puts "Release: #{`agvtool what-marketing-version -terse1`}"
puts "Build: #{`agvtool what-version -terse`}"
end
end
desc 'On significant changes. Bumps the build number.'
arg_name 'Describe arguments to bump here'
command :bump do |c|
c.action do |global_options,options,args|
puts `agvtool bump -all`
end
end
desc 'On starting a new project. Sets build number to 1 and version to 1.0'
arg_name 'Describe arguments to new here'
command :new do |c|
c.desc 'Describe a switch to new'
c.switch :s
c.desc 'Describe a flag to new'
c.default_value 'default'
c.flag :f
c.action do |global_options,options,args|
puts `agvtool new-version -all 1`
puts `agvtool new-marketing-version 1.0`
end
end
desc 'On starting a hotfix. Bumps build number and version revision number'
arg_name 'Describe arguments to hotfix here'
command :hotfix do |c|
c.action do |global_options,options,args|
puts `agvtool bump -all`
mv = `agvtool what-marketing-version -terse1`.strip
if mv == ''
mv = '1.0.1'
else
mv = Versionomy.parse(mv).bump(:tiny)
end
puts mv
puts `agvtool new-marketing-version #{mv.to_s}`
end
end
desc 'On starting a new milestone. Bumps build number and version minor number'
arg_name 'Describe arguments to minor here'
command :minor do |c|
c.action do |global_options,options,args|
puts `agvtool bump -all`
mv = `agvtool what-marketing-version -terse1`.strip
if mv == ''
mv = '1.0'
else
mv = Versionomy.parse(mv).bump(:minor).unparse(:optional_fields => [:tiny])
end
puts mv
puts `agvtool new-marketing-version #{mv}`
end
end
desc 'On starting a new major release. Bumps build number and version major number'
arg_name 'Describe arguments to major here'
command :major do |c|
c.action do |global_options,options,args|
puts `agvtool bump -all`
mv = `agvtool what-marketing-version -terse1`.strip
if mv == ''
mv = '1.0'
else
mv = Versionomy.parse(mv).bump(:major).unparse(:optional_fields => [:tiny])
end
puts mv
puts `agvtool new-marketing-version #{mv.to_s}`
end
end
pre do |global,command,options,args|
# Pre logic here
# Return true to proceed; false to abort and not call the
# chosen command
val = `agvtool what-version -terse`
if $? != 0
raise <<-'END'.gsub(/^ {6}/, "")
First, in your build settings,
- set "Versioning System" to "Apple Generic"
- set "Current Project Version" to 0
- add "CFBundleShortVersionString" to Info.plist
END
return true
end
true
end
post do |global,command,options,args|
# Post logic here
end
on_error do |exception|
puts exception
# Error logic here
# return false to skip default error handling
true
end
exit run(ARGV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment