背景
首先介绍一下这个问题的背景: Ruby on Rails最近存在一些安全问题。因此,我们需要更新项目中的Rails版本。如果你有几个,如果你手工做的话很快就会过时...所以我想我可以为此创建一个Thor任务。
问题
现在它工作得很好!但!在安装新版本的rails时,我需要遵守每个项目的.rvmrc文件。我希望这个脚本尽快成为OpenSourced,但我想先解决不尊重.rvmrc文件的问题。
因此,当我切换到一个目录来更新Rails版本时,我需要的是一种使用正确的RVM ruby版本/gemset的方法。
如何做到这一点呢?是否可以从Ruby脚本中以某种方式使其在Mac和Linux上工作,而不管Shell (我找到了支持zsh的答案,但是其他的Shell呢?)
快速示例代码:
#Scan the base directory down for Gemfiles
gem_files = File.join("**", "Gemfile")
Dir.glob(gem_files){|gemfile|
project_folder = File.dirname(gemfile)
puts "Found Gemfile in #{project_folder}"
Dir.chdir(project_folder) do
#TODO: Respect/load the rvmrc file in this directory
update_gem_file(project_folder) #example
run 'bundle update rails' #<--- needs to be done in the RVM gemset
end
}只是想让你知道我想做什么。
链接到githubs上的脚本
发布于 2013-02-14 22:31:51
看看这个项目:https://github.com/versapay/bundler-auto-update it:
尝试将Gemfile的每一个gem更新到其最新的补丁,然后是次要版本和主要版本。运行测试命令以确保更新成功
至于RVM,请使用以下简单的代码:
#Scan the base directory down for Gemfiles
gem_files = File.join("**", "Gemfile")
Dir.glob(gem_files){|gemfile|
project_folder = File.dirname(gemfile)
puts "Found Gemfile in #{project_folder}"
run "rvm in #{project_folder} do bundle-auto-update -c rake spec"
}您可以在https://rvm.io上找到有关使用RVM编写脚本的更多详细信息
发布于 2013-02-14 20:28:49
盲目地升级Rails不是一个好主意。至少运行你的测试套件,以确保不会出错。
但是,假设您确实升级了所有应用程序,它们仍然没有部署到生产环境中。
https://stackoverflow.com/questions/14872737
复制相似问题