Created
February 21, 2014 08:29
-
-
Save gpr/9130680 to your computer and use it in GitHub Desktop.
Manage Rails application version number with rake tasks (includes git-flow support)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/application.rb | |
require File.expand_path('../boot', __FILE__) | |
require 'rails/all' | |
Bundler.require(:default, Rails.env) | |
module App | |
class Application < Rails::Application | |
def self.version | |
"SPM-v#{VERSION}" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/version.rake | |
# Version number management tasks | |
version_file = '../../../config/initializers/version' | |
require File.expand_path(version_file, __FILE__) | |
task :release_major do | |
desc "Prepare a major release" | |
puts "Create git-flow release branch" | |
VERSION_MAJOR += 1 | |
`git flow release start "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"` | |
puts 'Bump VERSION_MAJOR' | |
version_filename = File.expand_path("#{version_file}"+'.rb', __FILE__) | |
text = File.open(version_filename).read | |
text.gsub!(/VERSION_MAJOR = (\d+)/, "VERSION_MAJOR = #{VERSION_MAJOR}") | |
File.open(version_filename, "w") {|file| file.puts text} | |
end | |
task :release_minor do | |
desc "Prepare a minor release" | |
puts "Create git-flow release branch" | |
VERSION_MINOR += 1 | |
`git flow release start "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"` | |
puts 'Bump VERSION_MINOR' | |
version_filename = File.expand_path("#{version_file}"+'.rb', __FILE__) | |
text = File.open(version_filename).read | |
text.gsub!(/VERSION_MINOR = (\d+)/, "VERSION_MINOR = #{VERSION_MINOR}") | |
File.open(version_filename, "w") {|file| file.puts text} | |
end | |
task :release_hotfix do | |
desc "Prepare a hotfix release" | |
puts "Create git-flow hotfix branch" | |
VERSION_PATCH += 1 | |
`git flow hotfix start "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"` | |
puts 'Bump VERSION_PATCH' | |
version_filename = File.expand_path("#{version_file}"+'.rb', __FILE__) | |
text = File.open(version_filename).read | |
text.gsub!(/VERSION_PATCH = (\d+)/, "VERSION_PATCH = #{VERSION_PATCH}") | |
File.open(version_filename, "w") {|file| file.puts text} | |
end | |
task :version do | |
desc "Print current version" | |
puts App::Application.version | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/version.rb | |
VERSION_MAJOR = 0 | |
VERSION_MINOR = 1 | |
VERSION_PATCH = 0 | |
if Rails.env.development? | |
VERSION = `git describe --tags --always --dirty` | |
else | |
VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment