簡體   English   中英

使用Ruby腳本中的.rvmrc文件

[英]Use a .rvmrc file from a Ruby script

背景

首先,這個問題有一些背景知識:Ruby on Rails最近有一些安全問題。 因此,我們需要在項目上更新Rails版本。 如果您有幾個,那么如果您手動進行操作,那很快就會變老...所以我想我可以為此創建一個Thor任務。

現在效果很好! 但! 在安裝新版本的rails時,我需要尊重每個項目的.rvmrc文件。 我希望該腳本能盡快被開源,但是我想解決不首先尊重.rvmrc文件的問題。

因此,我需要一種在更改目錄以更新Rails版本時使用正確的RVM紅寶石版本/寶石集的方法。

如何做到這一點? 能否以某種方式從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上的腳本

我的腳本的github回購-進行中!

基本上檢查這個項目https://github.com/versapay/bundler-auto-update

嘗試將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編寫腳本的更多詳細信息。

盲目升級Rails不是一個好主意。 至少運行您的測試套件,以確保沒有任何問題。 之后,您仍然想對應用程序進行一些質量檢查,以確保您沒有破壞所有事情。

然后,您怎么知道您要更新的當前分支實際上是主要的開發分支? 您是否不想創建“修補程序”分支並將其應用於生產開發分支?

但是,假設您確實設法升級了所有應用程序,但它們仍未部署到生產環境中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM