Skip to content

drernie/rake-versioning

 
 

Repository files navigation

Rake Versioning

Description

Rake Versioning is a simple wrapper around the concept of version-numbering schemes. It is forked from the “Version” gem as that name caused numerous complications in my environment.

Features

  • Rake::RakeVersioning provides tasks for simple version bumping

  • Rake Versioning smartly handles several versioning schemes, abstracting the details

Examples

Screencast

For a quick introduction to the original gem, watch the screencast[blip.tv/file/get/Tkadom-ATLRUGSteveTousetPresentingRake Versioning277.mov] of a presentation at the Atlanta Ruby Users’ Group.

Rake Tasks

Rake Versioning comes with a task that lets you manage version numbering automatically. Place the following in a Rakefile:

require 'rake/rake-versioning'
Rake::RakeVersioning.new

You’re all set up.

$ rake version:create VERSION=0.1.0 # => 0.1.0

Now ‘rake -T version` will tell you what all you can do.

$ version [master *$%]$ rake -T version
rake version                    # Print the current version number (0.1.0)
rake version:bump               # Bump to 0.1.1
rake version:bump:major         # Bump to 1.0.0
rake version:bump:minor         # Bump to 0.2.0
rake version:bump:pre           # Bump to 0.1.1a
rake version:bump:pre:major     # Bump to 1.0.0a
rake version:bump:pre:minor     # Bump to 0.2.0a
rake version:bump:pre:revision  # Bump to 0.1.1a
rake version:bump:revision      # Bump to 0.1.1
rake version:create             # Creates a version file with an optional VERSION parameter

$ rake version                      # => 0.1.0
$ rake version:bump                 # => 0.1.1
$ rake version:bump:minor           # => 0.2.0
$ rake version:bump:revision        # => 0.2.1
$ rake version:bump:pre             # => 0.2.2a
$ rake version:bump                 # => 0.2.2
$ rake version:bump:major           # => 1.0.0
$ rake version:bump:minor           # => 1.1.0
$ cat VERSION                       # => 1.1.0

The RakeVersioning task can automatically manage git tagging for you, too.

Rake::RakeVersioning.new do |task|
  task.with_git_tag = true
end

And if you want the RakeVersioning task to automatically emit updated gemspecs on version-bumps, use the with_gemspec flag.

spec = Gem::Specification.new do |s|
  ...
end

Rake::RakeVersioning.new do |task|
  task.with_gemspec = spec
end

Rake Versioning can also be used with a .yml VERSION file. See Version.to_hash or Hash.to_version for details.

Library Versioning

Rake Versioning lets you automatically keep an in-class VERSION constant in sync with the contents of the version file on disk. Version also provides a class-level current method which lets you get the current version without setting a class-level constant.

require 'version'

RakeVersioning::Version.current # => 1.0.1

class Foo
  is_versioned
end

Foo::VERSION # => 1.0.1

The Version.current and Class::is_versioned methods both take a filename parameter if you use a different location for the VERSION file. See the Version.current rdoc for details.

Manipulation in Code

All the above functionality is performed behind-the-scenes by the Rake Versioning library. It’s simple to use, but there’s not much point beyond doing the legwork for the Rake task and class versioning.

v = "1.2.0".to_version
v.to_s                       # => 1.2.0
v.bump!                      # => 1.2.1
v.bump!(:major)              # => 2.0.0
v.bump!(:minor, false, true) # => 2.1
v.major = 3                  # => 3.0
v.to_a                       # => ['3', '0']

Install

In your Gemfile add:

group :development do
  gem 'rake-versioning', github: 'drernie/rake-versioning'
end

About

Simple version-numbering encoding and helper methods

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%