ruby 使用rake任务管理Rails应用程序版本号(包括git-flow支持)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 使用rake任务管理Rails应用程序版本号(包括git-flow支持)相关的知识,希望对你有一定的参考价值。

# 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
# 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
# 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

以上是关于ruby 使用rake任务管理Rails应用程序版本号(包括git-flow支持)的主要内容,如果未能解决你的问题,请参考以下文章

如何在 ruby​​ on rails 的亚马逊 aws 服务器中使用 gem 执行 rake 任务?

ruby Rails中自定义rake任务

在 rake 任务中使用 rails logger,rails 5

rake db rake 任务不工作 Ruby 2.4.0 & Rails 5.0.1

整理Ruby相关的各种概念(rvm, gem, bundle, rake, rails等)

Ruby on Rails:运行 rake 命令时出现错误消息