From 5681001c90d1df16815633f7805fcc5c88ed9f8c Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Tue, 7 Dec 2010 08:55:05 -0800 Subject: [PATCH] Change the edge-gem versioning scheme. Rather than incrementing an index each time we push, we now impose an indexing based on the repo structure. The version of the prerelease gem is defined to be the number of commits since the stable branch (precisely, the number of commits in `git log stable..master --first-parent`). This means that when someone `rake install`s Haml from a Git repo, the gem is installed with the proper version number. --- Rakefile | 66 ++++++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/Rakefile b/Rakefile index 83c41f95..01cab7bd 100644 --- a/Rakefile +++ b/Rakefile @@ -43,8 +43,12 @@ END # before we load the gemspec. desc "Build all the packages." task :package => [:revision_file, :submodules, :permissions] do + version = get_version + File.open(scope('VERSION'), 'w') {|f| f.puts(version)} load scope('haml.gemspec') Gem::Builder.new(HAML_GEMSPEC).build + sh %{git checkout VERSION} + pkg = "#{HAML_GEMSPEC.name}-#{HAML_GEMSPEC.version}" mkdir_p "pkg" verbose(true) {mv "#{pkg}.gem", "pkg/#{pkg}.gem"} @@ -83,7 +87,7 @@ at_exit { File.delete(scope('REVISION')) rescue nil } desc "Install Haml as a gem. Use SUDO=1 to install with sudo." task :install => [:package] do gem = RUBY_PLATFORM =~ /java/ ? 'jgem' : 'gem' - sh %{#{'sudo ' if ENV["SUDO"]}#{gem} install --no-ri pkg/haml-#{File.read(scope('VERSION')).strip}} + sh %{#{'sudo ' if ENV["SUDO"]}#{gem} install --no-ri pkg/haml-#{get_version}} end desc "Release a new Haml package to Rubyforge." @@ -137,57 +141,29 @@ task :release_edge do ensure_git_cleanup do puts "#{'=' * 50} Running rake release_edge" - sh %{git checkout edge-gem} - sh %{git reset --hard origin/edge-gem} - sh %{git merge origin/master} - - unless edge_version = bump_edge_version - puts "master is already a prerelease version, no use building an edge gem" - next - end - - File.open(scope('EDGE_GEM_VERSION'), 'w') {|f| f.puts(edge_version)} - sh %{git commit -m "Bump edge gem version to #{edge_version}." EDGE_GEM_VERSION} - sh %{git push origin edge-gem} - - # Package the edge gem with the proper version - File.open(scope('VERSION'), 'w') {|f| f.puts(edge_version)} + sh %{git checkout master} + sh %{git reset --hard origin/master} sh %{rake package} - sh %{git checkout VERSION} - - sh %{rubyforge add_release haml haml "Bleeding Edge (v#{edge_version})" pkg/haml-#{edge_version}.gem} - sh %{gem push pkg/haml-#{edge_version}.gem} + version = get_edge_version + sh %{rubyforge add_release haml haml "Bleeding Edge (v#{version})" pkg/haml-#{version}.gem} + sh %{gem push pkg/haml-#{version}.gem} end end -# Reads the master version and the edge gem version, -# bump the latter, and return it. -# -# Returns nil if the current master version is already a non-alpha prerelease. -def bump_edge_version +# Get the version string. If this is being installed from Git, +# this includes the proper prerelease version. +def get_version + written_version = File.read(scope('VERSION').strip) + return written_version unless File.exist?(scope('.git')) + # Get the current master branch version - version = File.read(scope('VERSION')).strip.split('.') + version = written_version.split('.') version.map! {|n| n =~ /^[0-9]+$/ ? n.to_i : n} - unless version.size == 5 # prerelease - raise "master version #{version.join('.')} is not a prerelease version" - end + return written_version unless version.size == 5 && version[3] == "alpha" # prerelease - # Bump the edge gem version - edge_version = File.read(scope('EDGE_GEM_VERSION')).strip.split('.') - edge_version.map! {|n| n =~ /^[0-9]+$/ ? n.to_i : n} - - if version[3] != "alpha" - return - elsif edge_version[0..2] != version[0..2] - # A new master branch version was released, reset the edge gem version - edge_version[0..2] = version[0..2] - edge_version[4] = 1 - else - # Just bump the teeny version - edge_version[4] += 1 - end - - edge_version.join('.') + return written_version if (commit_count = `git log --pretty=oneline --first-parent stable.. | wc -l`).empty? + version[4] = commit_count.strip + version.join('.') end task :watch_for_update do