Rakefile 4.0 KB

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