為什麼要持續更新

Juanito FatasThinking about what to do.

bundle-update 可以更新所有的 Gem 至兼容的最新版本。

首先先說說...

  • 新版本修復了更多 Bugs
  • 新版本效能更好 leaky-gems
  • 維護者通常只對新版本的 Bug 感興趣
  • 預防勝於治療
  • 減少技術負債

因為你兩年才升級一次,很多 Gem 都太老了,一次全升級,每個 Gem 不兼容一點點,加起來全敗了。

語義化版本定義了一個版本命名的規範,幾乎所有的 RubyGem 都遵循這個規範。

4.2.4 - MAJOR.MINOR.PATCH

  • MAJOR 版本更新會壞,,向下不相容
  • MINOR 版本通常是發佈新功能,向下相容。
  • PATCH 版本通常是修復 Bugs,向下相容。

=>

  • rails 4.2.4 升級至 4.2.5,OK!
  • rails 4.2.4 升級至 4.3.0,Should be OK!
  • rails 4.2.4 升級至 5.0,break!

了解了語義化版本之後...

堅決拒用或是說服他!

有三種鎖定方式:

>= 2.0 表示 >= 2.0

~> 2.0 表示 >= 2.0, < 3
~> 2.0.0 表示 >= 2.0.0, < 2.1

"4.2.4" gem 版本會固定在 "4.2.4"

當有安全性發佈時,鎖定版本號讓你無法升級至已經修復的版本。

Gem 彼此之間有依賴關係,bundle update 會找到你的專案彼此兼容的版本,進行“升級”。

bundle update 不一定會更新到新版...

有可能某個 Gem 會降版,因為 bundle update 要確保所有更新的版本都兼容。

有人說...

這樣就得自己維護 Gem,時常跟進上游的更新,成本高。

鎖定版本號或是升級後,自行檢查並對代碼進行相應的修正。

$ cd project
$ git cehckout -b bundle-update-20151006
git: 'cehckout' is not a git command. See 'git --help'.

Did you mean this?
  checkout
$ git checkout -b bundle-update-20151006
$ bundle updaet
Could not find command "updaet".
$ bundle update
$ git add Gemfile.lock
$ git comit -m "Bundle update on 2015.10.06"
git: 'comit' is not a git command. See 'git --help'.

Did you mean this?
  commit
$ git commmit -m "Bundle update on 2015.10.06"
git: 'commmit' is not a git command. See 'git --help'.

Did you mean this?
  commit
$ git commit -m "Bundle update on 2015.10.06"
$ git push origin master
Go to GitHub, click "Create Pull Request"
fill in title
fill in description
click "Create Pull Request"

一次大約十分鐘,以我一個時薪 60 美元的 Developer 來說,成本大約是 10 美元!

那就是永遠不會升級啦!所以我們要自動讓電腦幫我們做這件事,省時省心省錢。

自動由服務提供 bundle update提早發現問題

可以試試看這個 GitHub 官方服務:dependantbot。或是看看 Renovate

  • 自動 bundle update 🎩
  • 更新頻率可選:1、3、5、7、14 天 ⌛
  • 符合 Git-Flow(Pull Request 可對 <customized-branch> branch 發送)🔨
  • 提供 Changelog,什麼是 Changelog? 🙋
  • 免費 🍻

你今天更新了嗎?

註1. 有足夠的測試再 bundle update

註2. 任何建議與反饋歡迎留言 :heart: :yellow_heart: :blue_heart: :green_heart: :purple_heart: