|
| 1 | +desc "Runs the specs [EMPTY]" |
| 2 | +task :spec do |
| 3 | + |
| 4 | +end |
| 5 | + |
| 6 | +task :version do |
| 7 | + git_remotes = `git remote`.strip.split("\n") |
| 8 | + |
| 9 | + if git_remotes.count > 0 |
| 10 | + puts "-- fetching version number from github" |
| 11 | + sh 'git fetch' |
| 12 | + |
| 13 | + remote_version = remote_spec_version |
| 14 | + end |
| 15 | + |
| 16 | + if remote_version.nil? |
| 17 | + puts "There is no current released version. You're about to release a new Pod." |
| 18 | + version = "0.0.1" |
| 19 | + else |
| 20 | + puts "The current released version of your pod is " + |
| 21 | + remote_spec_version.to_s() |
| 22 | + version = suggested_version_number |
| 23 | + end |
| 24 | + |
| 25 | + puts "Enter the version you want to release (" + version + ") " |
| 26 | + new_version_number = $stdin.gets.strip |
| 27 | + if new_version_number == "" |
| 28 | + new_version_number = version |
| 29 | + end |
| 30 | + |
| 31 | + replace_version_number(new_version_number) |
| 32 | +end |
| 33 | + |
| 34 | +desc "Release a new version of the Pod (append repo=name to push to a private spec repo)" |
| 35 | +task :release do |
| 36 | + # Allow override of spec repo name using `repo=private` after task name |
| 37 | + repo = ENV["repo"] || "master" |
| 38 | + |
| 39 | + puts "* Running version" |
| 40 | + sh "rake version" |
| 41 | + |
| 42 | + unless ENV['SKIP_CHECKS'] |
| 43 | + if `git symbolic-ref HEAD 2>/dev/null`.strip.split('/').last != 'master' |
| 44 | + $stderr.puts "[!] You need to be on the `master' branch in order to be able to do a release." |
| 45 | + exit 1 |
| 46 | + end |
| 47 | + |
| 48 | + if `git tag`.strip.split("\n").include?(spec_version) |
| 49 | + $stderr.puts "[!] A tag for version `#{spec_version}' already exists. Change the version in the podspec" |
| 50 | + exit 1 |
| 51 | + end |
| 52 | + |
| 53 | + puts "You are about to release `#{spec_version}`, is that correct? [y/n]" |
| 54 | + exit if $stdin.gets.strip.downcase != 'y' |
| 55 | + end |
| 56 | + |
| 57 | + puts "* Running specs" |
| 58 | + sh "rake spec" |
| 59 | + |
| 60 | + puts "* Linting the podspec" |
| 61 | + sh "pod lib lint" |
| 62 | + |
| 63 | + # Then release |
| 64 | + sh "git commit #{podspec_path} CHANGELOG.md VERSION -m 'Release #{spec_version}' --allow-empty" |
| 65 | + sh "git tag -a #{spec_version} -m 'Release #{spec_version}'" |
| 66 | + sh "git push origin master" |
| 67 | + sh "git push origin --tags" |
| 68 | + if repo == "master" |
| 69 | + sh "pod trunk push #{podspec_path}" |
| 70 | + else |
| 71 | + sh "pod repo push #{repo} #{podspec_path}" |
| 72 | + end |
| 73 | +end |
| 74 | + |
| 75 | +# @return [Pod::Version] The version as reported by the Podspec. |
| 76 | +# |
| 77 | +def spec_version |
| 78 | + require 'cocoapods' |
| 79 | + spec = Pod::Specification.from_file(podspec_path) |
| 80 | + spec.version |
| 81 | +end |
| 82 | + |
| 83 | +# @return [Pod::Version] The version as reported by the Podspec from remote. |
| 84 | +# |
| 85 | +def remote_spec_version |
| 86 | + require 'cocoapods-core' |
| 87 | + |
| 88 | + if spec_file_exist_on_remote? |
| 89 | + remote_spec = eval(`git show origin/master:#{podspec_path}`) |
| 90 | + remote_spec.version |
| 91 | + else |
| 92 | + nil |
| 93 | + end |
| 94 | +end |
| 95 | + |
| 96 | +# @return [Bool] If the remote repository has a copy of the podpesc file or not. |
| 97 | +# |
| 98 | +def spec_file_exist_on_remote? |
| 99 | + test_condition = `if git rev-parse --verify --quiet origin/master:#{podspec_path} >/dev/null; |
| 100 | + then |
| 101 | + echo 'true' |
| 102 | + else |
| 103 | + echo 'false' |
| 104 | + fi` |
| 105 | + |
| 106 | + 'true' == test_condition.strip |
| 107 | +end |
| 108 | + |
| 109 | +# @return [String] The relative path of the Podspec. |
| 110 | +# |
| 111 | +def podspec_path |
| 112 | + podspecs = Dir.glob('*.podspec') |
| 113 | + if podspecs.count == 1 |
| 114 | + podspecs.first |
| 115 | + else |
| 116 | + raise "Could not select a podspec" |
| 117 | + end |
| 118 | +end |
| 119 | + |
| 120 | +# @return [String] The suggested version number based on the local and remote |
| 121 | +# version numbers. |
| 122 | +# |
| 123 | +def suggested_version_number |
| 124 | + if spec_version != remote_spec_version |
| 125 | + spec_version.to_s() |
| 126 | + else |
| 127 | + next_version(spec_version).to_s() |
| 128 | + end |
| 129 | +end |
| 130 | + |
| 131 | +# @param [Pod::Version] version |
| 132 | +# the version for which you need the next version |
| 133 | +# |
| 134 | +# @note It is computed by bumping the last component of |
| 135 | +# the version string by 1. |
| 136 | +# |
| 137 | +# @return [Pod::Version] The version that comes next after |
| 138 | +# the version supplied. |
| 139 | +# |
| 140 | +def next_version(version) |
| 141 | + version_components = version.to_s().split("."); |
| 142 | + last = (version_components.last.to_i() + 1).to_s |
| 143 | + version_components[-1] = last |
| 144 | + Pod::Version.new(version_components.join(".")) |
| 145 | +end |
| 146 | + |
| 147 | +# @param [String] new_version_number |
| 148 | +# the new version number |
| 149 | +# |
| 150 | +# @note This methods replaces the version number in the podspec file |
| 151 | +# with a new version number. |
| 152 | +# |
| 153 | +# @return void |
| 154 | +# |
| 155 | +def replace_version_number(new_version_number) |
| 156 | + File.open('VERSION', "w") { |file| file.puts new_version_number } |
| 157 | +end |
0 commit comments