Class: Buildr::ReleaseTask
- Inherits:
-
Rake::Task
- Object
- Rake::Task
- Buildr::ReleaseTask
- Defined in:
- lib/core/build.rb
Constant Summary collapse
- VERSION_NUMBER_PATTERN =
/VERSION_NUMBER\s*=\s*(["'])(.*)\1/
- NEXT_VERSION_PATTERN =
/NEXT_VERSION\s*=\s*(["'])(.*)\1/
Class Method Summary collapse
Instance Method Summary collapse
- #check_status ⇒ Object
-
#initialize(*args) ⇒ ReleaseTask
constructor
A new instance of ReleaseTask.
- #svn(*args) ⇒ Object
-
#tag_repository(version) ⇒ Object
Create a tag in the SVN repository.
-
#update_next_version(version) ⇒ Object
Change the Rakefile and update the next version number to one after (NEXT_VERSION = NEXT_VERSION + 1).
-
#update_version ⇒ Object
Change the Rakefile and update the current version number to the next version number (VERSION_NUMBER = NEXT_VERSION).
- #update_version_to_snapshot(version) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ReleaseTask
Returns a new instance of ReleaseTask.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/core/build.rb', line 53 def initialize(*args) super enhance do |task| # Make sure we don't have anything uncommitted in SVN. check_status # Update current version to next version before deploying. next_ver = update_version # Run the deployment externally using the new version number # (from the modified Rakefile). sh "rake deploy" # Update the next version as well to the next increment and commit. update_next_version next_ver # Tag the repository for this release. tag_repository next_ver # Update the next version to end with -SNAPSHOT. update_version_to_snapshot next_ver end end |
Class Method Details
.svn_ignores ⇒ Object
48 49 50 |
# File 'lib/core/build.rb', line 48 def svn_ignores() @ignores = (@ignores || []).map { |pat| pat.is_a?(Regexp) ? pat : Regexp.new("^.*\s+#{Regexp.escape pat}$") } end |
Instance Method Details
#check_status ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/core/build.rb', line 72 def check_status() ignores = ReleaseTask.svn_ignores status = svn("status", "--ignore-externals", :verbose=>false). reject { |line| line =~ /^X\s/ || ignores.any? { |pat| line =~ pat } } fail "Uncommitted SVN files violate the First Principle Of Release!\n#{status}" unless status.empty? end |
#svn(*args) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/core/build.rb', line 135 def svn(*args) if Hash === args.last = args.pop else = { :verbose=>verbose } end puts ["svn", *args].join(" ") if [:verbose] Open3.popen3("svn", *args) do |stdin, stdout, stderr| stdin.close error = stderr.read fail error unless error.empty? returning(stdout.read) { |output| puts output if Rake.application..trace } end end |
#tag_repository(version) ⇒ Object
Create a tag in the SVN repository.
118 119 120 121 122 123 124 |
# File 'lib/core/build.rb', line 118 def tag_repository(version) # Copy to tag. cur_url = svn("info").scan(/URL: (.*)/)[0][0] new_url = cur_url.sub(/trunk$/, "tags/#{version}") svn "remove", new_url, "-m", "Removing old copy" rescue nil svn "copy", cur_url, new_url, "-m", "Release #{version}" end |
#update_next_version(version) ⇒ Object
Change the Rakefile and update the next version number to one after (NEXT_VERSION = NEXT_VERSION + 1). We do this to automatically increment future version number after each successful release.
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/core/build.rb', line 104 def update_next_version(version) # Update to new version number. nums = version.split(".") nums[-1] = nums[-1].to_i + 1 next_ver = nums.join(".") rakefile = File.read(Rake.application.rakefile) rakefile.gsub!(NEXT_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{next_ver}"}) } File.open(Rake.application.rakefile, "w") { |file| file.write rakefile } # Commit new version number. svn "commit", "-m", "Changed version number to #{version}", Rake.application.rakefile end |
#update_version ⇒ Object
Change the Rakefile and update the current version number to the next version number (VERSION_NUMBER = NEXT_VERSION). We need this before making a release with the next version. Return the next version.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/core/build.rb', line 83 def update_version() rakefile = File.read(Rake.application.rakefile) version = rakefile.scan(VERSION_NUMBER_PATTERN)[0][1] or fail "Looking for VERSION_NUMBER = \"...\" in your Rakefile, none found" next_ver = rakefile.scan(NEXT_VERSION_PATTERN)[0][1] or fail "Looking for NEXT_VERSION = \"...\" in your Rakefile, none found" if verbose puts "Current version: #{version}" puts "Next version: #{next_ver}" end # Switch version numbers. rakefile.gsub!(VERSION_NUMBER_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{next_ver}"}) } File.open(Rake.application.rakefile, "w") { |file| file.write rakefile } next_ver end |
#update_version_to_snapshot(version) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/core/build.rb', line 126 def update_version_to_snapshot(version) version += "-SNAPSHOT" rakefile = File.read(Rake.application.rakefile) rakefile.gsub!(VERSION_NUMBER_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{version}"}) } File.open(Rake.application.rakefile, "w") { |file| file.write rakefile } # Commit new version number. svn "commit", "-m", "Changed version number to #{version}", Rake.application.rakefile end |