reviewdog / action-rubocop

Run rubocop with reviewdog 🐶
MIT License
115 stars 75 forks source link

Cache ruby gems to speed up installation #83

Closed kleinjm closed 9 months ago

kleinjm commented 1 year ago

It takes about a minute to install the gems with extensions on my CI runs.

Would it be possible to cache the gem installation? Another thought - I use the ruby/setup-ruby@v1 to set up ruby before running review dog. Would it be possible to use the same cache as that GH action?

nyancat3 commented 1 year ago

@kleinjm How about using skip_install and use_bundler options with bundler-cache: true of setup-ruby?

name: reviewdog
on: [pull_request]
permissions:
  contents: read
  pull-requests: write
jobs:
  rubocop:
    name: runner / rubocop
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v3
      - uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true # runs 'bundle install' and caches installed gems automatically
      - name: rubocop
        uses: reviewdog/action-rubocop@v2
        with:
          rubocop_version: gemfile
          rubocop_extensions: rubocop-rails:gemfile rubocop-rspec:gemfile
          reporter: github-pr-review # Default is github-pr-check
          skip_install: true
          use_bundler: true
javierjulio commented 9 months ago

@kleinjm yes it is possible. What @nyancat3 shared has been what I've used to do that. I would welcome a PR to add an example of that in the README as I think that would be helpful.

Further, you can optimize the cache by only installing a gem group. I use this currently and works great. I noticed the Rails repository doing this.

In your Gemfile, declare a "rubocop" group.

group :development, :rubocop do
  gem 'rubocop', require: false
  gem 'rubocop-rails', require: false
  # ...
end

Then in your workflow, declare this environment variable so only that group is installed:

    env:
      BUNDLE_ONLY: rubocop