Rails以外のgemをバージョンアップして、Dependabotを入れた

現在、フィヨルドブートキャンブ内にて、@Sakiさん主催の「パーフェクト Ruby on Rails輪読会」が行われています。 こちらの本、大変参考になりますが、なんだか難しいし、もう少し深掘りがしたい!と思いまして、このブログに予習・復習した内容を簡単に載せていきたいなと考えています。

9-2-1

ライブラリは新機能追加、バグ修正など日々更新されていくので、アプリで使っているgemの定期的なアップデートが必要。
Dependabotを導入しておくことで、bundle updateされたgemのPRが自動生成される。
ということで、自作アプリのNursePicksに導入してみる。

Railsでは、導入前に手動でbundle updateすることを推奨しているので、フィヨルドブートキャンプのメンターでもある伊藤さんのありがたい記事を参考に、ひとまずgemのバージョンアップをしていく。


はじめに、テストが通るか否かと、Simplecovでカバレッジも確認。
94%とそこそこの水準で書き漏れがないことも確認。

それではgemのバージョンアップ。
bundle outdatedというコマンドで、現バージョンと最新バージョンの差分を確認できる。

Gem                     Current         Latest          Requested  Groups
actioncable             6.1.6           7.0.4
actionmailbox           6.1.6           7.0.4
actionmailer            6.1.6           7.0.4
actionpack              6.1.6           7.0.4
actiontext              6.1.6           7.0.4
actionview              6.1.6           7.0.4
activejob               6.1.6           7.0.4
activemodel             6.1.6           7.0.4
activerecord            6.1.6           7.0.4
activestorage           6.1.6           7.0.4
activesupport           6.1.6           7.0.4
addressable             2.8.0           2.8.1
bootsnap                1.11.1          1.15.0          >= 1.4.4   default
brakeman                5.3.1           5.4.0           >= 0       development, test
buftok                  0.2.0           0.3.0
bullet                  7.0.2           7.0.4           >= 0       development
capybara                3.37.1 d08e88d  3.38.0 5c86747  >= 0       test
dotenv                  2.7.6           2.8.1
dotenv-rails            2.7.6           2.8.1           >= 0       default
erubi                   1.10.0          1.11.0
faraday                 1.10.0          2.7.1
faraday-http-cache      2.3.0           2.4.1
faraday-net_http        1.0.1           3.0.2
faraday-retry           1.0.3           2.0.0
http                    4.4.1           5.1.0
http_parser.rb          0.6.0           0.8.0
i18n                    1.10.0          1.12.0
jwt                     2.3.0           2.5.0
meta-tags               2.16.0          2.18.0          >= 0       default
metainspector           5.12.1          5.13.1          >= 0       default
minitest                5.15.0          5.16.3
msgpack                 1.5.1           1.6.0
multipart-post          2.1.1           2.2.3
oauth                   0.5.10          1.1.0
oauth2                  1.4.9           2.0.9
omniauth-google-oauth2  1.0.1           1.1.1           >= 0       default
omniauth-oauth2         1.7.2           1.8.0
parser                  3.1.2.0         3.1.3.0
pg                      1.3.5           1.4.5           ~> 1.1     default
public_suffix           4.0.7           5.0.0
puma                    5.6.4           6.0.0           ~> 5.0     default
rack                    2.2.3           3.0.1
rack-mini-profiler      2.3.4           3.0.0           ~> 2.0     development
rack-protection         2.2.0           3.0.4
rack-proxy              0.7.2           0.7.4
rack-test               1.1.0           2.0.2
rails                   6.1.6           7.0.4           ~> 6.1.6   default
railties                6.1.6           7.0.4
rb-fsevent              0.11.1          0.11.2
regexp_parser           2.4.0           2.6.1
rspec-core              3.11.0          3.12.0
rspec-expectations      3.11.0          3.12.0
rspec-mocks             3.11.1          3.12.0
rspec-rails             5.1.2           6.0.1           >= 0       development, test
rspec-support           3.11.0          3.12.0
rubocop                 1.29.1          1.39.0
rubocop-ast             1.18.0          1.23.0
rubocop-fjord           0.2.0           0.2.2           >= 0       development
rubocop-performance     1.14.0          1.15.1
rubocop-rails           2.14.2          2.17.3          >= 0       development
rubocop-rspec           2.11.1          2.15.0          >= 0       development
selenium-webdriver      4.5.0           4.6.1
spring                  4.0.0           4.1.0           >= 0       development
sprockets               4.0.3           4.1.1
temple                  0.8.2           0.9.1
tilt                    2.0.10          2.0.11
tzinfo                  2.0.4           2.0.5
unicode-display_width   2.1.0           2.3.0
zeitwerk                2.5.4           2.6.6

RailsはVue.jsの導入関連で6.1.6でnewしていたので、Rails関連を除くと大体がマイナーバージョンやリビジョンの更新になるっぽい。
半年前に作り始めた小規模アプリなので、bundle updateで一括バージョンアップしても良さそうだが、ここは基本に忠実に。

伊藤さんの記事には原則gemのバージョン指定はしないとあり。指定する場合はコメントを書いておくと良いとのこと。
不必要なバージョン指定を外す。

続いては、developmentとtestグループのgemを先にアップデート。
記事にある通りbundle update -g development -g testとコマンドでアップデートしてみたが、自分の環境ではtestグループのみアップデートになってしまったので、(development + testグループがあったことが起因してそうだけど、深掘りはしない)

bundle update -g development
bundle update -g test

としてアップデート。テストも問題なく通るし、ローカルでの挙動も問題なし。
再びbundle outdatedをしてみる。

Gem                     Current  Latest  Requested  Groups
actioncable             6.1.6    7.0.4
actionmailbox           6.1.6    7.0.4
actionmailer            6.1.6    7.0.4
actionpack              6.1.6    7.0.4
actiontext              6.1.6    7.0.4
actionview              6.1.6    7.0.4
activejob               6.1.6    7.0.4
activemodel             6.1.6    7.0.4
activerecord            6.1.6    7.0.4
activestorage           6.1.6    7.0.4
activesupport           6.1.6    7.0.4
bootsnap                1.11.1   1.15.0  >= 1.4.4   default
buftok                  0.2.0    0.3.0
dotenv                  2.7.6    2.8.1
dotenv-rails            2.7.6    2.8.1   >= 0       default
faraday                 1.10.0   2.7.1
faraday-http-cache      2.3.0    2.4.1
faraday-net_http        1.0.1    3.0.2
faraday-retry           1.0.3    2.0.0
http                    4.4.1    5.1.0
http_parser.rb          0.6.0    0.8.0
jwt                     2.3.0    2.5.0
meta-tags               2.16.0   2.18.0  >= 0       default
metainspector           5.12.1   5.13.1  >= 0       default
msgpack                 1.5.1    1.6.0
multipart-post          2.1.1    2.2.3
oauth                   0.5.10   1.1.0
oauth2                  1.4.9    2.0.9
omniauth-google-oauth2  1.0.1    1.1.1   >= 0       default
omniauth-oauth2         1.7.2    1.8.0
pg                      1.3.5    1.4.5   ~> 1.1     default
puma                    5.6.4    6.0.0   ~> 5.0     default
rack                    2.2.4    3.0.1
rack-protection         2.2.0    3.0.4
rack-proxy              0.7.2    0.7.4
rails                   6.1.6    7.0.4   ~> 6.1.6   default
railties                6.1.6    7.0.4
sprockets               4.0.3    4.1.1
temple                  0.8.2    0.9.1

気になるのはoauth2が1.4.9→2.0.9くらい。
一応CHANGELOGを確認。Rubyの対応バージョンを変えたとかでした。

ということでbundle updateを実行 テストも通り、bundle outdatedをしても、残りはRails関連のgemだけでスッキリ。

Gem             Current  Latest  Requested  Groups
actioncable     6.1.7    7.0.4
actionmailbox   6.1.7    7.0.4
actionmailer    6.1.7    7.0.4
actionpack      6.1.7    7.0.4
actiontext      6.1.7    7.0.4
actionview      6.1.7    7.0.4
activejob       6.1.7    7.0.4
activemodel     6.1.7    7.0.4
activerecord    6.1.7    7.0.4
activestorage   6.1.7    7.0.4
activesupport   6.1.7    7.0.4
buftok          0.2.0    0.3.0
http            4.4.1    5.1.0
http_parser.rb  0.6.0    0.8.0
puma            5.6.5    6.0.0   ~> 5.0     default
rack            2.2.4    3.0.1
rails           6.1.7    7.0.4   ~> 6.1.6   default
railties        6.1.7    7.0.4
temple          0.8.2    0.9.1

ここからはDependabotを導入していく。
Railsで学習した形でyamlファイルを作ろうと思ったが、オプションに変更があったりなどで、GitHubのDocsGitHub の Dependabot version updates で依存ライブラリを継続的に更新するという参考記事から学ぶ。
後者の記事はGithub上の動作を写真付きで載せてくれているので分かりやすかった。

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: 'bundler'
    directory: '/'
    schedule:
      interval: "weekly"
      day: "monday"
      time: "06:00"
      timezone: "Asia/Tokyo"

これにてDependabotの導入が完了。毎週月曜日に通知が来ることになった。

導入後は早速Railsのバージョンを上げてみようとの提案が…

次はRails7に上げてWebpackerを剥がせるとよさそう。