action-rubocop
action-rubocop copied to clipboard
Takes too long
Is it normal that it takes so long if I just add the yml to the workflow?
name: Review Dog
on:
pull_request:
branches: [develop]
jobs:
rubocop:
name: dog-pro
runs-on: ubuntu-18.04
steps:
- name: Check out code
uses: actions/checkout@v1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5.7
- run: gem install activesupport --version 6.1.4.3
- name: rubocop
uses: reviewdog/action-rubocop@v1
with:
github_token: $${{ secrets.github_token }}
rubocop_version: 0.81.0
rubocop_extensions: rubocop-rails:2.5.2
reporter: github-pr-review
fail_on_error: true
tool_name: dog-pro
I canceled it to prevent consuming too much time, I was not sure if it had been in an infinite loop.
Hi! Could you provide a log to check the problem?
Firstly I wanted to say I love this project. It's fantastic!
Is it normal that it takes so long if I just add the yml to the workflow?
@paulomcnally, I'm guessing you have quite a large codebase? We managed to work around this issue by only having RuboCop lint files that have changed in the current pull request. The entire workflow is as follows:
name: reviewdog
on: [pull_request]
jobs:
rubocop:
name: runner / rubocop
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Retrive and store changed ruby files
run: echo "INPUT_RUBOCOP_FLAGS=$(git diff --name-only --diff-filter=ACMRTUXB origin/master | grep -E "(\.rb$)" | tr '\n' ' ')" >> $GITHUB_ENV
- uses: ruby/setup-ruby@v1
if: ${{ env.INPUT_RUBOCOP_FLAGS }}
- name: Linting following files
run: echo $INPUT_RUBOCOP_FLAGS
if: ${{ env.INPUT_RUBOCOP_FLAGS }}
- name: rubocop
uses: BiggerPockets/action-rubocop@0b9fdc012b541882a0d8b74cc74ebbbab200bb30
with:
rubocop_version: gemfile
rubocop_extensions: rubocop-rails:gemfile
if: ${{ env.INPUT_RUBOCOP_FLAGS }}
The only complication was needing to fork this repo so we could stop INPUT_RUBOCOP_FLAGS
from being overwritten https://github.com/BiggerPockets/action-rubocop/commit/0b9fdc012b541882a0d8b74cc74ebbbab200bb30
I thought I'd share in case it's helpful to anyone else. It got our linting times down from about 8 minutes to around 6 seconds.
Also, if there is a better way to do this, please let me know.
We managed to work around this issue by only having RuboCop lint files that have changed in the current pull request
Seems like this should be the default behaviour, or at least a simple option to enable?
Getting a linting failure because of code not touched in a given PR is not how we would like the action to behave.
If it helps anyone else, this is very similar to the above, but does not require a fork:
name: reviewdog
on: [pull_request]
jobs:
rubocop:
name: runner / rubocop
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.6
- name: Fetch mainline branch for comparison (required for next step)
run: git fetch origin main
- name: Retrieve and store changed ruby files
id: changed-files
run: echo "CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB FETCH_HEAD | grep -E "(\.rb$)" | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Linting the following files
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.CHANGED_FILES }}
run: echo $CHANGED_FILES
- name: rubocop
uses: reviewdog/action-rubocop@v2
with:
rubocop_flags: ${{ steps.changed-files.outputs.CHANGED_FILES }}
rubocop_version: gemfile
rubocop_extensions: rubocop-rails:gemfile rubocop-rspec:gemfile rubocop-performance:gemfile
reporter: github-pr-review
Also in case it helps, we ended up creating an alternative rubocop action at https://github.com/reclaim-the-stack/rubocop-action
This one only runs on changed files by default. It also has a very clean inline commenting approach which fully deletes comments after offences are resolved. Ie. it doesn't leave any noise behind in the PR.