Skip to content

Commit

Permalink
Strip back pipeline to Rubocop linting only (#562)
Browse files Browse the repository at this point in the history
* Only lint Rubocop for now (and only modified files)

deleted files are excluded

* Scope action for PRs

* Disable tests for now

* Run command in one line

* Fix RuboCop command

* Further improve linting setup

* Simplify linter setup

* Print changed ruby files

* Fix further errors and improve workflow file

* Change random Rails files to see effects

* Fix spaces in changed files

* Include target branch lookup

* Remove unnecessary ${{}} syntax

* Fetch target branch

* Improve commit retrieval

* Redo whole workflow

* Revert dummy changes in Rails files

* Use checkout@v4 (instead of @V3)

* Explicitly set fail level & force excluding files

See command line flags here:
https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags

* Add more events to trigger workflow

See the docs here:
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request

* Add printout to display RuboCop version used
  • Loading branch information
Splines committed Jan 6, 2024
1 parent 6157bbe commit 22771e0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 161 deletions.
112 changes: 35 additions & 77 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,45 @@
on: [push]
name: Linting

# Trigger each time HEAD branch is updated in a pull request
# see https://github.com/orgs/community/discussions/26366
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

jobs:

# Resources:
# number [1] being most important
# [1] https://github.com/actions/checkout/issues/520#issuecomment-1167205721
# [2] https://robertfaldo.medium.com/commands-to-run-rubocop-and-specs-you-changed-in-your-branch-e6d2f2e4110b
# [3] https://community.atlassian.com/t5/Bitbucket-questions/Git-diff-show-different-files-than-PR-Pull-Request/qaq-p/2331786
rubocop:
name: RuboCop
runs-on: ubuntu-latest
name: A job to check rubocop linter errors
steps:
- uses: actions/checkout@v2
- name: 'Checkout PR branch (with test merge-commit)'
uses: actions/checkout@v4
with:
fetch-depth: 2 # to also fetch parent of PR

# Adapted from this great comment [1]. Git diff adapted from [2].
# "|| test $? = 1;" is used to ignore the exit code of grep when no files
# are found matching the pattern. For the "three dots" ... syntax, see [3].
- name: Get changed files
run: |
files=$(git diff --name-only --diff-filter=ACMR -r HEAD^1...HEAD | grep '\.rb$' || test $? = 1;)
printf "🎴 Changed ruby files: \n$files"
echo "CHANGED_FILES=$(echo ${files} | xargs)" >> $GITHUB_ENV
- name: Set up Ruby 3
if: env.CHANGED_FILES != ''
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.4
- name: Install gems # usual step to install the gems.
bundler-cache: true

- name: Run RuboCop
if: env.CHANGED_FILES != ''
run: |
bin/bundle config path vendor/bundle
bin/bundle config set without 'default doc job cable storage ujs test db'
bin/bundle install --jobs 4 --retry 3
- name: Linter count
id: hello
uses: henrixapp/[email protected]
with:
name: Rubocop
command: bin/bundle exec rubocop app config lib spec
total_regexp: \d+ offenses detected
errors_regexp: \d+ offenses detected
warnings_regexp: \d+ offenses detected
compare_branch: mampf-next
mode: changed
include: .rb
eslint:
runs-on: ubuntu-latest
name: A job to check eslint linter errors
steps:
- uses: actions/checkout@v2
- name: Linter count
id: hello
uses: henrixapp/[email protected]
with:
name: EsLint
command: npx eslint
total_regexp: \d+ problems
errors_regexp: \d+ errors
warnings_regexp: \d+ warnings
compare_branch: mampf-next
mode: changed
include: .js
coffee:
runs-on: ubuntu-latest
name: A job to check coffee linter errors
steps:
- uses: actions/checkout@v2
- name: Linter count
id: hello
uses: henrixapp/[email protected]
with:
name: Coffee
command: npx coffeelint
total_regexp: \d+ errors
errors_regexp: \d+ errors
warnings_regexp: \d+ warnings
compare_branch: mampf-next
mode: changed
include: .coffee
# erblint:
# runs-on: ubuntu-latest
# name: A job to check erblint linter errors
# steps:
# - uses: actions/checkout@v2
# - name: Set up Ruby 2.7
# uses: ruby/setup-ruby@v1
# with:
# ruby-version: 2.7
# - name: Install gems # usual step to install the gems.
# run: |
# bin/bundle config path vendor/bundle
# bin/bundle config set without 'default doc job cable storage ujs test db'
# bin/bundle install --jobs 4 --retry 3
# - name: Linter count
# id: hello
# uses: henrixapp/[email protected]
# with:
# name: Erblint
# command: bin/bundle exec erblint .
# total_regexp: \d+ error(s)
# errors_regexp: \d+ error(s)
# warnings_regexp: \d+ error(s)
# compare_branch: mampf-next
echo "🚨 Running RuboCop version: $(bundle info rubocop | head -1)"
bundle exec rubocop --format github --fail-level 'convention' --force-exclusion -- $CHANGED_FILES
84 changes: 0 additions & 84 deletions .github/workflows/tests.yml

This file was deleted.

0 comments on commit 22771e0

Please sign in to comment.