Last active
November 10, 2016 05:29
-
-
Save tpae/f3f7caf5a135b2c90505c807aca406ab to your computer and use it in GitHub Desktop.
Bumping version on a podspec when using CocoaPods
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
meh