Search code examples
github-actionsrubocop

RuboCop - [AllCops -> Exclude] not working in GitHub Actions


The RuboCop AllCops->Exclude rule does not work using GitHub Actions.

It seems to go into a recursive loop

I have a simple GEM that is using RuboCop with a basic configuration.

AllCops:
  TargetRubyVersion: 2.7
  NewCops: enable

Style/StringLiterals:
  Enabled: true
  EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
  Enabled: true
  EnforcedStyle: double_quotes

Layout/LineLength:
  Max: 120

I need to disable cop rules in two folders.

AllCops:
  TargetRubyVersion: 2.7
  NewCops: enable
  Exclude:
    - ".builders/**/*"
    - "spec/samples/**/*"

WORKS :) Run Rubocop locally with excluded files:

enter image description here

Using GitHub Actions

WORKS :) Run RuboCop without AllCops->Exclude

GHA k_director/runs/4909797149

enter image description here

FAILS :( Run RuboCop sing AllCops->Exclude

GHA k_director/runs/4909833222

I cancelled the workflow at nearly 8 minutes

enter image description here

This action takes it seems to go into a deep tree traversal and locks up my GitHub Actions.

Here is some of the errors 1800 lines into the log

enter image description here

GitHub Action workflow for RuboCop

name: Build Application

on:
  push:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest
    name: Ruby ${{ matrix.ruby }}
    strategy:
      matrix:
        ruby: ['2.7.1']

    steps:
    - uses: actions/checkout@v2
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{ matrix.ruby }}
        bundler-cache: true

    - name: Run rubocop
      run: bundle exec rubocop


Solution

  • I first tried to the venders directory into the exclusions.

    AllCops:
      Exclude:
        - 'vendor/**/*'
    

    I found the answer here: How to Setup RuboCop in GitHub Actions

    This worked for me, but @AndyWait pointed me to a section in the documentation and my current working solution is to add the following, which will merge my new exclusions with the exclusions that are in the rubocop->default.yml

    inherit_mode:
      merge:
        - Exclude
    

    Additionally, configuration is inherited from `.rubocop.yml' files further up the folder hierarchy, aka parent folders.

    If you want to avoid those configuration files being included when rubocop runs, then pass in the specific .rubocop.yml file that is needed for configuration and let it reference other files as needed using the inherit_from: ../.some_other_rubocop.yml option.

    rubocop --config .rubocop.yml