Repository: buildr Updated Branches: refs/heads/master 45a462bee -> 569578ba4
BUILDR-703 release: allow THIS_VERSION to be defined in another file Allow for a file named version.rb to be placed next to the Buildfile. This file should contain the version number of the project. Project: http://git-wip-us.apache.org/repos/asf/buildr/repo Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/569578ba Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/569578ba Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/569578ba Branch: refs/heads/master Commit: 569578ba47703e6cb9b8ee14194d257ce9843ee4 Parents: 45a462b Author: Antoine Toulme <[email protected]> Authored: Mon May 2 23:15:34 2016 -0700 Committer: Antoine Toulme <[email protected]> Committed: Mon May 2 23:15:34 2016 -0700 ---------------------------------------------------------------------- CHANGELOG | 1 + doc/releasing.textile | 14 ++++++++++++++ lib/buildr/core/build.rb | 31 +++++++++++++++++++++---------- spec/core/build_spec.rb | 10 ++++++++++ 4 files changed, 46 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/buildr/blob/569578ba/CHANGELOG ---------------------------------------------------------------------- diff --git a/CHANGELOG b/CHANGELOG index 262e406..e0e76f3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ * Added: Travis badge to README.rdoc * Added: BUILDR-577 Allow remote repo to be added with http basic auth support. Submitted by Michael Guymon. * Fixed: BUILDR-207 remove 'Skipping tests' messages +* Added: BUILDR-703 release: allow THIS_VERSION to be defined in another file 1.4.25 (2016-04-18) http://git-wip-us.apache.org/repos/asf/buildr/blob/569578ba/doc/releasing.textile ---------------------------------------------------------------------- diff --git a/doc/releasing.textile b/doc/releasing.textile index 6c6f551..c7cab0f 100644 --- a/doc/releasing.textile +++ b/doc/releasing.textile @@ -113,6 +113,20 @@ end The environment variable @NEXT_VERSION@ has precedence over Release.next_version. +h3(#alternate_version_file). Using an alternate version file + +To avoid dealing with conflicts over the Buildfile, you can store the version inside version.rb next to it. + +version.rb: +{% highlight ruby %} +THIS_VERSION = "1.0.0-rc1" +{% endhighlight %} + +Your Buildfile should import version.rb like so: +{% highlight ruby %} +require File.join(File.dirname(__FILE__), 'version.rb') +{% endhighlight %} + h2(#custom_tag_and_msg). How to specify my own tag name and commit message? As explained earlier, Buildr will create two new commits and a new tag in the version control system. Similarly to @Release.next_version@, the commit message and the tag name can be customized with @Release.message@ and @Release.tag_name@. Both could be strings or procs that would receive the released version @THIS_VERSION@ without @-SNAPSHOT@. http://git-wip-us.apache.org/repos/asf/buildr/blob/569578ba/lib/buildr/core/build.rb ---------------------------------------------------------------------- diff --git a/lib/buildr/core/build.rb b/lib/buildr/core/build.rb index 8f7ff29..6e2a4ee 100644 --- a/lib/buildr/core/build.rb +++ b/lib/buildr/core/build.rb @@ -353,7 +353,7 @@ module Buildr #:nodoc: # Extract the current version number from the buildfile. # Raise an error if not found. def extract_version - buildfile = File.read(Buildr.application.buildfile.to_s) + buildfile = File.read(version_file) buildfile.scan(THIS_VERSION_PATTERN)[0][2] rescue fail 'Looking for THIS_VERSION = "..." in your Buildfile, none found' @@ -373,6 +373,17 @@ module Buildr #:nodoc: # the initial value of THIS_VERSION attr_accessor :this_version + + # :call-seq: + # version_file() + # Provides the file containing the version of the project. + # If the project contains a version.rb file next to the Buildr build file, + # it is used. Otherwise, always use the buildfile. + def version_file + version_rb_file = File.dirname(Buildr.application.buildfile.to_s) + '/version.rb' + return version_rb_file if File.exists?(version_rb_file) + return Buildr.application.buildfile.to_s + end # :call-seq: # with_release_candidate_version() { |filename| ... } @@ -390,7 +401,7 @@ module Buildr #:nodoc: # THIS_VERSION = 1.1.0 # for the release buildfile. def with_release_candidate_version - release_candidate_buildfile = Buildr.application.buildfile.to_s + '.next' + release_candidate_buildfile = version_file + '.next' release_candidate_buildfile_contents = change_version { |version| version.gsub(/-SNAPSHOT$/, "") @@ -398,7 +409,7 @@ module Buildr #:nodoc: File.open(release_candidate_buildfile, 'w') { |file| file.write release_candidate_buildfile_contents } begin yield release_candidate_buildfile - mv release_candidate_buildfile, Buildr.application.buildfile.to_s + mv release_candidate_buildfile, version_file ensure rm release_candidate_buildfile rescue nil end @@ -415,7 +426,7 @@ module Buildr #:nodoc: def change_version current_version = extract_version new_version = yield(current_version) - buildfile = File.read(Buildr.application.buildfile.to_s) + buildfile = File.read(version_file) buildfile.gsub(THIS_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{new_version}"}) } end @@ -451,7 +462,7 @@ module Buildr #:nodoc: buildfile = change_version { |version| # THIS_VERSION minus SNAPSHOT resolve_next_version(this_version) # THIS_VERSION } - File.open(Buildr.application.buildfile.to_s, 'w') { |file| file.write buildfile } + File.open(version_file, 'w') { |file| file.write buildfile } end # Return the message to use to commit the buildfile with the next version @@ -498,7 +509,7 @@ module Buildr #:nodoc: def tag_release(tag) unless this_version == extract_version info "Committing buildfile with version number #{extract_version}" - Hg.commit File.basename(Buildr.application.buildfile.to_s), message + Hg.commit File.basename(version_file), message Hg.push if Hg.remote end info "Tagging release #{tag}" @@ -510,7 +521,7 @@ module Buildr #:nodoc: def update_version_to_next super info "Current version is now #{extract_version}" - Hg.commit File.basename(Buildr.application.buildfile.to_s), message + Hg.commit File.basename(version_file), message Hg.push if Hg.remote end end @@ -546,7 +557,7 @@ module Buildr #:nodoc: def tag_release(tag) unless this_version == extract_version info "Committing buildfile with version number #{extract_version}" - Git.commit File.basename(Buildr.application.buildfile.to_s), message + Git.commit File.basename(version_file), message Git.push if Git.remote end info "Tagging release #{tag}" @@ -559,7 +570,7 @@ module Buildr #:nodoc: def update_version_to_next super info "Current version is now #{extract_version}" - Git.commit File.basename(Buildr.application.buildfile.to_s), message + Git.commit File.basename(version_file), message Git.push if Git.remote end end @@ -588,7 +599,7 @@ module Buildr #:nodoc: def update_version_to_next super info "Current version is now #{extract_version}" - Svn.commit Buildr.application.buildfile.to_s, message + Svn.commit version_file, message end end http://git-wip-us.apache.org/repos/asf/buildr/blob/569578ba/spec/core/build_spec.rb ---------------------------------------------------------------------- diff --git a/spec/core/build_spec.rb b/spec/core/build_spec.rb index afeb005..2e3162a 100644 --- a/spec/core/build_spec.rb +++ b/spec/core/build_spec.rb @@ -678,6 +678,16 @@ shared_examples_for 'a release process' do write 'buildfile', 'define foo' lambda { @release.extract_version }.should raise_error('Looking for THIS_VERSION = "..." in your Buildfile, none found') end + + it 'should use version.rb instead of buildfile, if present' do + write 'version.rb', "VERSION_NUMBER = '1.0.0-SNAPSHOT'" + @release.extract_version.should == '1.0.0-SNAPSHOT' + end + + it 'should complain if there is a version.rb file, but it contains no version number' do + write 'version.rb', "#SOMETHING SOMETHING" + lambda { @release.extract_version }.should raise_error('Looking for THIS_VERSION = "..." in your Buildfile, none found') + end end describe '#with_release_candidate_version' do
