Rubocop is a linter and code formatter for ruby, it enforces to follow the ruby style guide to improve readability and maintainability of the code https://rubystyle.guide/.
To enforce this across an organisation one of the best way is to add this as a mandatory step for merging the PRs which can be done using Github Actions.
This can be achieved by using this library
The problem I was facing that this GitHub action was taking around 6-7 min for each commit. This is because the libraries runs rubocop on all files even if we have selected filter_mode as ‘added’.
As I found the root cause, the solution was simple, to run rubocop only on the changed files instead of entire repo.
This script list all the ruby files that are changed according to the main branch and we run rubocop on these files only. This reduces the execution time by 3 fold.
Here is the action that executes this script.