setup-ruby icon indicating copy to clipboard operation
setup-ruby copied to clipboard

Only perform bundler actions / don't install Ruby

Open steveh opened this issue 2 years ago • 4 comments

We run actions with a custom Docker image that already contains Ruby and Bundler.

The recommendation is to use this action to cache gems with Bundler, but I don't want it to also install Ruby.

Can we set something like ruby_version: none to skip that part?

steveh avatar Mar 29 '23 07:03 steveh

Or maybe it will be possible to set ruby_version: system instead?

AskarZinurov avatar May 29 '23 11:05 AskarZinurov

I'm not clear how actions work inside Docker images, but I suppose they do?

PR welcome. It is not completely trivial, because e.g. the Ruby version should still be part of the cached key and we need to know the Bundler major version.

eregon avatar May 29 '23 13:05 eregon

@eregon yep, seems you are right, for case in issue description, it is much clearer just run bundle install to separate bundler path and then use https://github.com/actions/cache directly. Smth like:

jobs:
  specs:
    runs-on: ubuntu-latest
    container: ruby:2.4.10-stretch
    services:
      redis:
        image: redis:6.2-alpine
        ports:
          - "6379:6379"
      postgres:
        image: postgres:11-bullseye
        ports:
          - "5432:5432"
    env:
      RAILS_ENV: "test"
      BUNDLE_PATH: "/opt/ruby-gemset"
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Cache gemset
        id: gemset-cache
        uses: actions/cache@v3
        with:
          path: /opt/ruby-gemset
          key: ${{ runner.os }}-${{ hashFiles('Gemfile.lock') }}
      - name: Install ruby gems
        run: bundle install --jobs 8
      - name: Create database config file
        run: cp config/database.yml.example config/database.yml
      - name: Run tests
        run: |
          bin/rake db:setup
          bin/rspec

AskarZinurov avatar May 29 '23 16:05 AskarZinurov

It is much clearer just run bundle install to separate bundler path and then use https://github.com/actions/cache directly.

The linked recommendation explicitly says not to do that:

Caching gems with Bundler correctly is not trivial and just using actions/cache is not enough.

Instead, it is recommended to use ruby/setup-ruby's bundler-cache: true option whenever possible:

steveh avatar Aug 21 '23 08:08 steveh