Skip to content

Instantly share code, notes, and snippets.

@tpae
Last active November 10, 2016 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpae/f3f7caf5a135b2c90505c807aca406ab to your computer and use it in GitHub Desktop.
Save tpae/f3f7caf5a135b2c90505c807aca406ab to your computer and use it in GitHub Desktop.
Bumping version on a podspec when using CocoaPods
task default: %w[version]
version_sizes = ["major", "minor", "patch"]
task :version, [:version_size] do |t, args|
args.with_defaults(:version_size => "patch")
version_size = args.version_size
unless version_sizes.include?(version_size)
fail "invalid version size, please use: major, minor, or patch"
end
version_size_index = version_sizes.index(version_size)
# get current podspec, parse current version
podspec_path = Rake::FileList["*.podspec"].to_s()
podspec_content = File.read(podspec_path)
current_version = podspec_content.match(/\.version\s+=\s+['"](.+)['"]$/)[1]
current_version_arr = current_version.split(".").map! { |x|
x.to_i()
}
# up the version based on version_size
current_version_arr[version_size_index] += 1
# get new version
new_version = current_version_arr.join(".")
# replace version string
unless podspec_content.gsub!(/(\.version\s+=\s+)['"](.+)['"]$/, "\\1\"#{new_version}\"")
raise "Unable to up the version"
end
# write file
File.open(podspec_path, 'w') { |f| f << podspec_content }
print(new_version)
end
@strusewych
Copy link

meh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment