Permalink
Browse files

Merge pull request #5 from drh-stanford/patch_tag

Patch tag
  • Loading branch information...
2 parents d04d0d8 + 0a682b0 commit 250977316e3bf2079f1a660e03e28ee98256ddc0 @jondot committed Oct 9, 2013
Showing with 413 additions and 125 deletions.
  1. +1 −0 .gitignore
  2. +4 −3 Gemfile
  3. +19 −11 Gemfile.lock
  4. +46 −5 README.md
  5. +9 −8 Rakefile
  6. +1 −1 VERSION
  7. +97 −16 lib/bumper/version.rb
  8. +22 −6 lib/version_bumper.rb
  9. +7 −5 test/helper.rb
  10. +154 −15 test/test_version_bumper.rb
  11. +53 −55 version_bumper.gemspec
View
@@ -40,3 +40,4 @@ pkg
#
# For vim:
*.swp
+.rvmrc
View
@@ -7,7 +7,8 @@ source "http://rubygems.org"
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "minitest", ">= 0"
- gem "bundler", "~> 1.0.0"
- gem "jeweler", "~> 1.5.2"
- gem "rcov", ">= 0"
+ gem "bundler", "~> 1.0"
+ gem "jeweler", "~> 1.5"
+ gem "simplecov-rcov"
+ gem "rdoc", ">= 2.4.2"
end
View
@@ -2,22 +2,30 @@ GEM
remote: http://rubygems.org/
specs:
git (1.2.5)
- jeweler (1.5.2)
- bundler (~> 1.0.0)
+ jeweler (1.8.4)
+ bundler (~> 1.0)
git (>= 1.2.5)
rake
- minitest (2.0.2)
- rake (0.8.7)
- rcov (0.9.9)
- rcov (0.9.9-java)
+ rdoc
+ json (1.8.0)
+ minitest (5.0.6)
+ multi_json (1.7.7)
+ rake (10.1.0)
+ rdoc (4.0.1)
+ json (~> 1.4)
+ simplecov (0.7.1)
+ multi_json (~> 1.0)
+ simplecov-html (~> 0.7.1)
+ simplecov-html (0.7.1)
+ simplecov-rcov (0.2.3)
+ simplecov (>= 0.4.1)
PLATFORMS
- java
ruby
- x86-mingw32
DEPENDENCIES
- bundler (~> 1.0.0)
- jeweler (~> 1.5.2)
+ bundler (~> 1.0)
+ jeweler (~> 1.5)
minitest
- rcov
+ rdoc (>= 2.4.2)
+ simplecov-rcov
View
@@ -18,23 +18,63 @@ First lets agree that version looks like this: major.minor.revision.build
In your `Rakefile` `require 'version_bumper'` and you're done. If you're in rails, `gem 'version_bumper'` to your `Gemfile` in addition.
$ rake -T
- rake bump:build # bump build
rake bump:init # write a blank version
rake bump:major # bump major
rake bump:minor # bump minor
- rake bump:revision # bump revision
-
+ rake bump:patch # bump patch or bump patch[tag]
+ rake bump:build # bump build
$ rake bump:init
version: 0.0.0.0
- $ rake bump:revision
+ $ rake bump:build
+ version: 0.0.0.1
+ $ rake bump:patch
version: 0.0.1.0
+ $ rake bump:minor
+ version: 0.1.0.0
$ rake bump:major
version: 1.0.0.0
+
You can optionally use `bumper_file 'version.txt'` in your rake file to switch from the default `VERSION` file name.
Use `bumper_version` anywhere you need access to the current version in your rake script.
+Pre-release versioning
+----------------------
+
+You can append a hyphen tag to the *patch* version, e.g., 1.0.0-alpha, 1.0.0-beta, 1.0.0-beta2, 1.0.0-gamma, 1.0.0-rc, 1.0.0-rc2, etc.
+
+Or you can prepend a tag to the *build* version, e.g., 1.0.0.alpha1, 1.0.0.beta1, 1.0.0.rc3, etc.
+
+ $ rake bump:init
+ version: 0.0.0.0
+ $ rake bump:minor
+ version: 0.1.0.0
+ $ rake bump:patch[beta]
+ version: 0.1.1-beta.0
+ $ rake bump:patch[beta]
+ version: 0.1.1-beta2.0
+ $ rake bump:build
+ version: 0.1.1-beta2.1
+ $ rake bump:patch[rc]
+ version: 0.1.1-rc.0
+ $ rake bump:patch[rc]
+ version: 0.1.1-rc2.0
+ $ rake bump:patch
+ version: 0.1.1.0
+ $ rake bump:patch
+ version: 0.1.2.0
+ $ rake bump:minor
+ version: 0.2.0.0
+ $ rake bump:build[beta]
+ version: 0.2.0.beta1
+ $ rake bump:build
+ version: 0.2.0.beta2
+ $ rake bump:build[rc]
+ version: 0.2.0.rc1
+ $ rake bump:patch[alpha]
+ version: 0.2.1-alpha.0
+
Contributing to version_bumper
------------------------------
@@ -50,7 +90,8 @@ Commiters
---------
jondot (Dotan Nahum)
splattael (Peter Suschlik)
-derickbailey (Derick Bailey)
+derickbailey (Derick Bailey)
+drh-stanford (Darren Hardy)
Copyright
View
@@ -9,10 +9,13 @@ rescue Bundler::BundlerError => e
end
require 'rake'
+BUNDLE_VERSION = File.exist?('VERSION') ? File.read('VERSION').strip : ""
+
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "version_bumper"
+ gem.version = BUNDLE_VERSION
gem.homepage = "http://github.com/jondot/version_bumper"
gem.license = "MIT"
gem.summary = %Q{Rake task to bump your versions}
@@ -35,21 +38,19 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
+Rake::TestTask.new(:rcov) do |test|
+ ENV['COVERAGE'] = 'true'
+ test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
task :default => :test
-require 'rake/rdoctask'
-Rake::RDocTask.new do |rdoc|
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
-
+require 'rdoc/task'
+RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "version_bumper #{version}"
+ rdoc.title = "version_bumper #{BUNDLE_VERSION}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
View
@@ -1 +1 @@
-0.3.0
+0.4.1.pre2
View
@@ -1,45 +1,126 @@
module Bumper
class Version
- [:major, :minor, :revision, :build].each do |part|
- define_method part do
+ [:major, :minor, :patch, :build].each do |part|
+ define_method part do
@v[part]
end
+ define_method "#{part}=" do |arg|
+ @v[part] = arg
+ end
+
define_method "bump_#{part}" do
bump(part)
end
end
- def initialize(v)
+
+ def initialize(v = '0.0.0.0')
@v = {}
- if v =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
+ if v =~ /^(\d+)\.(\d+)$/ # 0.0
+ @v[:major] = $1.to_i
+ @v[:minor] = $2.to_i
+ elsif v =~ /^(\d+)\.(\d+)\.(\d+)$/ # 0.0.0
+ @v[:major] = $1.to_i
+ @v[:minor] = $2.to_i
+ @v[:patch] = $3.to_i
+ elsif v =~ /^(\d+)\.(\d+)\.(\d+)-([A-Za-z\d]+)$/ # 0.0.0-alpha
@v[:major] = $1.to_i
@v[:minor] = $2.to_i
- @v[:revision] = $3.to_i
- @v[:build] = $4
+ @v[:patch] = $3.to_i
+ @v[:patch_tag]= $4.empty?? nil : $4.to_s
+ elsif v =~ /^(\d+)\.(\d+)\.(\d+)\.([A-Za-z]*\d+)$/ # 0.0.0.a0
+ @v[:major] = $1.to_i
+ @v[:minor] = $2.to_i
+ @v[:patch] = $3.to_i
+ @v[:build] = $4.to_s
+ elsif v =~ /^(\d+)\.(\d+)\.(\d+)-([A-Za-z\d]+)\.([A-Za-z]*\d+)$/ # 0.0.0-alpha.0
+ @v[:major] = $1.to_i
+ @v[:minor] = $2.to_i
+ @v[:patch] = $3.to_i
+ @v[:patch_tag]= $4.empty?? nil : $4.to_s
+ @v[:build] = $5.to_s
+ else
+ raise ArgumentError, "Invalid version format major.minor[.patch[-tag[.[tag]build]]]: #{v}"
+ end
+ end
+
+ def patch_tag
+ @v[:patch_tag]
+ end
+
+ def patch_tag= tag
+ @v[:patch_tag] = (tag.nil? or tag.empty?) ? nil : tag.to_s
+ end
+
+ # patch tags go from alpha, alpha2, alpha3, etc.
+ def bump_patch_tag tag
+ @v[:build] = '0' unless build.nil?
+ if patch_tag.nil?
+ @v[:patch] = patch.succ
+ return @v[:patch_tag] = tag
+ elsif patch_tag.start_with? tag
+ # ensure tag ends with number
+ if patch_tag !~ %r{\d+$}
+ @v[:patch_tag] = patch_tag + '1' # required for succ to work
+ end
+ # increment this tag
+ @v[:patch_tag] = patch_tag.succ
+ else
+ @v[:patch_tag] = tag # replace tag
end
end
def bump(part)
- version = @v[part] = @v[part].succ
-
- return version if part == :build
- @v[:build] = '0' if @v[:build]
- return version if part == :revision
- @v[:revision] = 0
- return version if part == :minor
+ if part == :build
+ if build.nil?
+ @v[part] = '1'
+ elsif build =~ /^([^\d]+)(\d+)$/
+ @v[part] = $1 + ($2.to_i + 1).to_s
+ else
+ @v[part] = build.succ
+ end
+ return @v[part]
+ end
+ @v[:build] = '0' unless build.nil?
+ if part == :patch and not @v[:patch_tag].nil?
+ @v[:patch_tag] = nil # just drop the tag
+ return patch
+ end
+ @v[:patch_tag] = nil
+ return (@v[part] = patch.succ) if part == :patch
+ @v[:patch] = 0
+ return (@v[part] = minor.succ) if part == :minor
@v[:minor] = 0
-
- version
+ return (@v[part] = major.succ)
end
def to_s
- [major, minor, revision, build].compact.join('.')
+ if patch.nil?
+ [major, minor]
+ else
+ if patch_tag.nil?
+ [major, minor, patch, build]
+ else
+ [major, minor, [patch, patch_tag].join('-'), build]
+ end
+ end.select {|x| not x.nil?}.join('.')
end
def write(f)
File.open(f,'w'){ |h| h.write(self.to_s) }
end
+
+ # @deprecated Use patch
+ def revision
+ patch
+ end
+
+ # @deprecated Use bump_patch
+ def bump_revision
+ bump_patch
+ end
+
end
end
View
@@ -31,20 +31,36 @@ def bumper_version
persist!
end
- desc "bump revision"
- task :revision do
- bumper_version.bump_revision
+ desc "bump patch or bump patch[tag]"
+ task :patch, :tag do |t, args|
+ if args[:tag] and not args[:tag].empty?
+ bumper_version.bump_patch_tag args[:tag]
+ else
+ bumper_version.bump_patch
+ end
persist!
end
- desc "bump build"
- task :build do
- bumper_version.bump_build
+ desc "bump build or bump build[tag]"
+ task :build, :tag do |t, args|
+ if args[:tag] and not args[:tag].empty?
+ bumper_version.build = args[:tag] =~ /\d+$/ ? args[:tag] : (args[:tag] + '1')
+ else
+ bumper_version.bump_build
+ end
persist!
end
def persist!
bumper_version.write(@vfile)
puts "version: #{bumper_version}"
end
+
+ # @deprecated Use :patch
+ desc "bump revision"
+ task :revision do
+ bumper_version.bump_patch
+ persist!
+ end
+
end
View
@@ -7,13 +7,15 @@
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
-require 'minitest/unit'
+
+if ENV["COVERAGE"]
+ require 'simplecov'
+ SimpleCov.start
+end
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'version_bumper'
-class MiniTest::Unit::TestCase
-end
-
-MiniTest::Unit.autorun
+require 'minitest'
+MiniTest.autorun
Oops, something went wrong.

0 comments on commit 2509773

Please sign in to comment.