How do you cache Ruby gems on Github Actions CI? There are actually 2 ways of doing it with ruby/setup-ruby or actions/cache.

How to start CI build faster by loading Ruby gems from cache on Github Actions? You can start running your tests for a Ruby on Rails project quicker if you manage to set up all dependencies in a short amount of time. Caching can be helpful with that. Ruby gems needed for your project can be cached by Github Actions and thanks to that they can be loaded much faster when you run a new CI build.

You will learn how to configure Github Actions using:

  • actions/cache — it’s a popular solution to cache Ruby gems.
  • ruby/setup-ruby — it’s a solution to install a specific Ruby version and cache Ruby gems with bundler. Two features in one action.

Actions/cache — Just Cache Dependencies

Actions/cache is a popular solution that can be used to save data into the cache and restore it during the next CI build. It’s often used for Ruby on Rails projects that also use actions/setup-ruby for managing the Ruby version on Github Actions.

Let’s look at the Github Actions caching config example using actions/cache.

## .github/workflows/main.yml
name: Main
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: actions/cache@v2
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-gems-

      - name: Bundle install
        env:
          RAILS_ENV: test
        run: |
          bundle config path vendor/bundle
          bundle install --jobs 4 --retry 3

#ruby #testing #tech #github #ruby on rails #cache #tests

Caching Ruby Gems on Github Actions Using ruby/setup-ruby or actions/cache
3.25 GEEK