Install using cache action and actions/setup-ruby action.

Note, if you use ruby/setup-ruby instead, you get caching already. With the approach here, you get more control over cache and how Bundler runs, if that matters to you.

actions - cache

Based on example.

  • main.yml
      steps:
        - name: Checkout 🛎️
          uses: actions/checkout@v2
    
        - name: Set up Ruby 💎
          uses: actions/setup-ruby@v1
          with:
            ruby-version: '2.7'
    
        - name: Get cached gems
          uses: actions/cache@v2
          with:
            path: vendor/bundle
            key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
            restore-keys: |
              ${{ runner.os }}-gems-
    
        - name: Install dependencies 🔧
          run: |
            bundle config set path vendor/bundle
            bundle install --jobs 4 --retry 3
    
        - name: Run
          run: bundle exec ruby hello.rb