From 876cd39a45edabcb13dd239bf12e7fd4ff474e5e Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Wed, 28 Feb 2024 11:53:58 -0500 Subject: [PATCH] Update example to use bundler Since Rubocop has multiple gems, it's best to rely on Bundler to install them rather than not. Other popular gems like Rails use this same feature to optimize their rubocop workflows. https://github.com/rails/rails/blob/main/.github/workflows/rubocop.yml --- README.md | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1bfb3b3..1ae8817 100644 --- a/README.md +++ b/README.md @@ -100,11 +100,24 @@ Optional. Run Rubocop with bundle exec. Default: `false`. ## Example usage -You can create [RuboCop Configuration](https://docs.rubocop.org/rubocop/configuration.html) and this action uses that config too. +This action will use your [RuboCop Configuration](https://docs.rubocop.org/rubocop/configuration.html) automatically. + +In your `Gemfile`, ensure all Rubocop gems are in a named (e.g. rubocop) group: + +```ruby +group :development, :rubocop do + gem 'rubocop', require: false + gem 'rubocop-rails', require: false + # ... +end +``` + +Create the following workflow. The `BUNDLE_ONLY` environment variable will tell Bundler to only install the specified group. ```yml name: reviewdog -on: [pull_request] +on: + pull_request: permissions: contents: read pull-requests: write @@ -112,18 +125,19 @@ jobs: rubocop: name: runner / rubocop runs-on: ubuntu-latest + env: + BUNDLE_ONLY: rubocop steps: - - name: Check out code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0.0 - - name: rubocop - uses: reviewdog/action-rubocop@v2 + ruby-version: '3.3' + bundler-cache: true + - 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 ``` ## Sponsor