Upgrade to Pro — share decks privately, control downloads, hide ads and more …

各所に分散しがちなRubyのバージョンを上手に管理する / use-dot-ruby-version

各所に分散しがちなRubyのバージョンを上手に管理する / use-dot-ruby-version

社内LT会で発表した資料。

toshimaru

March 17, 2025
Tweet

More Decks by toshimaru

Other Decks in Technology

Transcript

  1. CI # .github/workflows/setup-ruby.yml name: My workflow on: [push, pull_request] jobs:

    test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: '3.4'
  2. GitHub Action: setup-ruby ruby-versionを明示的に指定せずとも、ruby/setup-ruby は.ruby-versionからRubyバージョンを自動で設定してくれる。 inputs: ruby-version: description: | Engine

    and version to use, see the syntax in the README. Reads from .ruby-version, .tool-versions or mise.toml if unset. default: 'default' see. https:/ /github.com/ruby/setup-ruby/blob/master/action.yml
  3. TIPS: Rails 7.1 でDockerfileが自動生成されるようになった 下記のようなDockerfileが生成される。 # Make sure RUBY_VERSION matches

    the Ruby version in .ruby-version ARG RUBY_VERSION=3.4.2 FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base (定義が重複してしまうものの)RUBY_VERSIONのデフォルト値として、.ruby-versionと同じバージョンを指定しておくと、いちいちRUBY_VERSIONを指定しなくて楽。
  4. Gemfile 実は、Bundlerに.ruby-versionからRubyバージョンを指定する機能があったりする。 If you wish to derive your Ruby version

    from a version file (i.e. .ruby-version), you can use the file option instead. ruby file: ".ruby-version" ref. Bundler: Ruby Directive see also. GemfileでのRubyバージョン指定を.ruby-versionから読む - koicの日記
  5. END