Skip to content

Commit

Permalink
Merge pull request #5 from luizfonseca/feat/ruby-3-support
Browse files Browse the repository at this point in the history
feat!: Ruby 3+ support
  • Loading branch information
luizfonseca authored May 3, 2024
2 parents ddb52f7 + d6b7eec commit b97561a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM ruby:2.6.5-alpine
RUN apk add --no-cache --update build-base linux-headers git
FROM ruby:3.3.1-slim-bookworm

LABEL com.github.actions.name="Rubocop Code Checks"
LABEL com.github.actions.description="Lint your Ruby code in parallel to your builds"
Expand All @@ -8,5 +7,11 @@ LABEL com.github.actions.color="red"

LABEL maintainer="Luiz Fonseca <[email protected]>"

RUN gem install rubocop -v 1.63.4
RUN gem install rubocop-rspec -v 2.29.2
RUN gem install rubocop-performance -v 1.21.0
RUN gem install rubocop-rails -v 2.24.1

COPY lib /action/lib

ENTRYPOINT ["/action/lib/entrypoint.sh"]
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,41 @@

- [Github Action: Rubocop](#github-action-rubocop)
- [How it works](#how-it-works)
- [Supported Ruby versions](#supported-ruby-versions)
- [Configuration](#configuration)
- [Instructions](#instructions)

Lint your Ruby code in parallel to your builds.


## How it works
- A Dockerfile with the following gems runs a `rubocop` check on your codebase using:
- rubocop -v 1.63.4
- rubocop-rspec -v 2.29.2
- rubocop-performance -v 1.21.0
- rubocop-rails -v 2.24.1
- Errors are then reported per-line on the PR's checks tab.

- Ruby 2.6.5
- Rubocop + Rubocop Performance

Versions are fixed to avoid breaking changes on the gems. If you want to update the versions, you can do so by changing the Dockerfile in the repository and *opening a PR* to update the action.

## Configuration
In order to run all the checks, you need to have a `.rubocop.yml` file in your repository. You can generate one by running `rubocop --auto-gen-config` on your project's root. This is optional, but it is recommended to have one to customize the checks to your project's needs.

In case no configuration is found, the action will use the default configuration file provided by the gems. For more information, check the [rubocop documentation](https://docs.rubocop.org/rubocop/configuration.html).

You can also customize the rubocop extensions that will run by adding the following to your `.rubocop.yml` file:

```yaml
require:
- rubocop-rspec
- rubocop-performance
- rubocop-rails
```
## Supported Ruby versions
- Ruby 3+ (older versions are supported on *<=1.5.6 versions of this action*)
![](screenshots/annotations.png)
Expand All @@ -34,8 +60,7 @@ jobs:
- uses: actions/checkout@v1
- name: Rubocop checks
uses: luizfonseca/github-actions-rubocop@1.5.6
uses: luizfonseca/github-actions-rubocop@2.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
7 changes: 0 additions & 7 deletions lib/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#!/bin/sh

set -e

gem install rubocop -v 0.80.1
gem install rubocop-rspec -v 1.38.1
gem install rubocop-performance -v 1.5.2
gem install rubocop-rails -v 2.4.2

ruby /action/lib/index.rb
8 changes: 4 additions & 4 deletions lib/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
require 'json'
require 'time'

@GITHUB_SHA = ENV['GITHUB_SHA']
@GITHUB_EVENT_PATH = ENV['GITHUB_EVENT_PATH']
@GITHUB_TOKEN = ENV['GITHUB_TOKEN']
@GITHUB_WORKSPACE = ENV['GITHUB_WORKSPACE']
@GITHUB_SHA = ENV['GITHUB_SHA'] or raise 'GITHUB_SHA env var is not set'
@GITHUB_EVENT_PATH = ENV['GITHUB_EVENT_PATH'] or raise 'GITHUB_EVENT_PATH env var is not set'
@GITHUB_TOKEN = ENV['GITHUB_TOKEN'] or raise 'GITHUB_TOKEN env var is not set'
@GITHUB_WORKSPACE = ENV['GITHUB_WORKSPACE'] or raise 'GITHUB_WORKSPACE env var is not set'

@event = JSON.parse(File.read(ENV['GITHUB_EVENT_PATH']))
@repository = @event['repository']
Expand Down

0 comments on commit b97561a

Please sign in to comment.