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支持)的主要内容,如果未能解决你的问题,请参考以下文章

如何仅列出属于我的 Rails 应用程序的 Rake 任务(没有不可维护的 grep 语句)?

如何编写 Rake 任务以将数据导入 Rails 应用程序?

如何在 kubernetes cron 作业中启动 rails rake 任务

rake 任务中的 Rails 异常通知器

部署 Rails 应用程序时无法检测到 rake 任务

Rails Guide -- Ruby on Rake