Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Commit

Permalink
Configuration File (#75)
Browse files Browse the repository at this point in the history
There are too many issues with the current configuration settings. Some of the commands require special syntax, and adding more isn't scalable. With this new API, adding more changes and configurations should be very simple.

To use special configurations, you now need to create a configuration file that the action will read. See https://rubocop-linter-action.readthedocs.io/ for more information.
  • Loading branch information
andrewmcodes committed Dec 19, 2019
1 parent a13d236 commit e140072
Show file tree
Hide file tree
Showing 36 changed files with 741 additions and 340 deletions.
52 changes: 52 additions & 0 deletions .github/config/rubocop_linter_action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Description: The name of the check that will be created.
# Valid Options: A reasonably sized string.
# Default: 'Rubocop Action'
check_name: "Rubocop Results"

# Description: Version of rubocop that will be installed.
# Valid options: 'latest' or a version number like '0.75.0'.
# Default: 'latest'
rubocop_version: 'latest'

# Description: Extensions required to run your rubocop config.
# Valid options: Any rubocop extension, by default the latest gem version will be used. You can explicitly state that
# (not required) or use a version number like '1.5.1'.
# Default: nil
rubocop_extensions:
- 'rubocop-rails'
- 'rubocop-performance': '1.5.1'
- 'rubocop-minitest': 'latest'
- 'rubocop-rspec': '1.37.0'

# Description: Rubocop configuration file path relative to the workspace.
# Valid options: A valid file path inside of the workspace.
# Default: nil
# Note: This does not need to be filled out for Rubocop to still find your config.
# Resource: https://rubocop.readthedocs.io/en/stable/configuration/
rubocop_config_path: '.rubocop.yml'

# Run all cops enabled by configuration except this list.
# Valid options: list of valid cop(s) and/or departments.
# Default: nil
# Resource: https://rubocop.readthedocs.io/en/stable/cops/
rubocop_excluded_cops:
- 'Style/FrozenStringLiteralComment'

# Minimum severity for exit with error code
# Valid options: 'refactor', 'convention', 'warning', 'error', or 'fatal'.
# Default: 'warning'
# Resource: https://rubocop.readthedocs.io/en/stable/configuration/#severity
rubocop_fail_level: 'warning'

# Instead of installing gems from rubygems, we can run `bundle install` on your project,
# you would need to do this if you are using something like 'rubocop-github' or if you don't
# want to list out extensions with the `rubocop_extensions` key.
# Valid options: true || false
# Default: false
bundle: false

# The scope of code that Rubocop should lint. Use this if you only want to lint changed files. If this is not set
# or not equal to 'modified', Rubocop is run against the entire codebase.
# Valid options: 'modified'
# Default: nil
check_scope: 'modified'
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Metrics/MethodLength:
Max: 16

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ LABEL "maintainer"="Andrew Mason <andrewmcodes@protonmail.com>"
LABEL "version"="2.0.1"

COPY lib /action/lib
COPY README.md LICENSE /
COPY README.md LICENSE entrypoint.sh /

RUN gem install bundler

ENTRYPOINT ["/action/lib/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ GEM
hashdiff (1.0.0)
i18n (1.7.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.3)
jaro_winkler (1.5.4)
json (2.2.0)
method_source (0.9.2)
minitest (5.13.0)
multi_json (1.14.1)
multipart-post (2.1.1)
octokit (4.14.0)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.18.0)
parallel (1.19.1)
parser (2.6.5.0)
ast (~> 2.4.0)
pry (0.12.2)
Expand Down
136 changes: 43 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,133 +1,83 @@
<!-- Variables -->

<!-- Files -->
[changelog]: /CHANGELOG.md
[coc]: /CODE_OF_CONDUCT.md
[contributing]: /CONTRIBUTING.md
[license]: /LICENSE.md
<!-- Images -->
[image1]: /screenshots/check-overview.png
[image2]: /screenshots/file-annotation.png
[logo]: /screenshots/rubocop-linter-action.png

<!-- End Variables -->

![Rubocop Linter Action][logo]
![Linters](https://github.com/andrewmcodes/rubocop-linter-action/workflows/Linters/badge.svg)
![Tests](https://github.com/andrewmcodes/rubocop-linter-action/workflows/Test/badge.svg)
[![Changelog](https://github.com/andrewmcodes/rubocop-linter-action/workflows/Changelog/badge.svg)][changelog]
![Build](https://github.com/andrewmcodes/rubocop-linter-action/workflows/Build/badge.svg)
[![Changelog](https://github.com/andrewmcodes/rubocop-linter-action/workflows/Changelog/badge.svg)](/CHANGELOG.md)

![Version Number](https://img.shields.io/static/v1?label=Version&message=v2.0.1&color=blue)
[![Documentation Status](https://readthedocs.org/projects/rubocop-linter-action/badge/?version=latest)](https://rubocop-linter-action.readthedocs.io/en/latest/?badge=latest)
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors)

# :white_check_mark: Rubocop Linter Action

A GitHub Action to run [Rubocop](https://github.com/rubocop-hq/rubocop) against your code and create annotations in the GitHub UI.
# Rubocop Linter Action

- [:white_check_mark: Rubocop Linter Action](#whitecheckmark-rubocop-linter-action)
- [:page_facing_up: Introduction](#pagefacingup-introduction)
- [:bulb: Usage](#bulb-usage)
- [:package: Example Workflow](#package-example-workflow)
- [:moneybag: Available Inputs](#moneybag-available-inputs)
- [:warning: Gotchas](#warning-gotchas)
- [:camera_flash: Screenshots](#cameraflash-screenshots)
- [:bookmark: Changelog](#bookmark-changelog)
- [:sos: Contributing](#sos-contributing)
- [:rotating_light: Code of Conduct](#rotatinglight-code-of-conduct)
- [:copyright: License](#copyright-license)
- [:1st_place_medal: Recognition](#1stplacemedal-recognition)
- [:robot: Check Out My Other Ruby GitHub Actions](#robot-check-out-my-other-ruby-github-actions)
- [✨ Contributors](#%e2%9c%a8-contributors)
A GitHub Action to run [Rubocop](https://github.com/rubocop-hq/rubocop) against your codebase and output the results in the [GitHub Checks UI](https://developer.github.com/changes/2018-05-07-new-checks-api-public-beta/).

## :page_facing_up: Introduction
## Introduction

GitHub Actions are an amazing new tool that can dramatically improve productivity while using the GitHub platform. While it is not hard to write a custom GitHub action to run Rubocop on your codebase, this action takes that functionality one step further using the checks API. After the Rubocop Linter Action runs Rubocop against your code, it will create annotations that you can easily view, matched up with the offending code.

Since GitHub actions and the checks API are continually changing, it is possible that there will be breaking API changes that affect this action. If so, please open an issue and I will look into it as soon as I can.

## :bulb: Usage

Add the following to your GitHub action workflow to use Rubocop Linter Action:
## Usage

```yaml
- name: Rubocop Linter
uses: andrewmcodes/rubocop-linter-action@v2.0.1
with:
additional_gems: 'rubocop-rails rubocop-performance'
fail_level: 'warning'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
### Documentation

It is **highly** recommend you tie yourself to a version and do not do the following. I promise your life will be much easier. 😇
**Please view the [official documentation](https://rubocop-linter-action.readthedocs.io) for more detailed instructions**, including how to setup and use a configuration file to customize the action. Note that you can set the version for the documentation you are viewing in the bottom right.

```yml
# ❌ Danger, sometimes I break things!
uses: andrewmcodes/rubocop-linter-action@master
### Quickstart

# ✅ Much better.
uses: andrewmcodes/rubocop-linter-action@v2.0.1
```
### :package: Example Workflow
Here is an example workflow file incorporating Rubocop Linter Action:
Default usage, similar to running `gem install rubocop && rubocop` from your command line:

```yaml
name: Rubocop

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Rubocop Linter
uses: andrewmcodes/rubocop-linter-action@v2.0.1
with:
additional_gems: 'rubocop-rails rubocop-performance'
fail_level: 'warning'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Rubocop Linter Action
uses: andrewmcodes/rubocop-linter-action@v2.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
**Go [here](https://github.com/andrewmcodes/rubocop-linter-action-playground/blob/master/.github/workflows/test.yml) to see more examples!**
### :moneybag: Available Inputs
| **Input Parm Name** | **Required** | **Default Value** | **Description** | **Examples of Equivalent Local Commands** |
| ------------------- | ------------ | ----------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| bundle | false | false | If you would like to run `bundle install` on your project instead of `gem install` | `bundle install --deployment --jobs 4 --retry 3` |
| version | false | latest GA | Define a later version of rubocop if latest is not needed | `gem install rubocop -v 0.76.0` |
| additional_gems | false | | Additional Gems can be installed via one line with spaces and commands are supported like a version | `gem install rubocop-rails rubocop-performance 'rubocop-i18n:2.0.0'` |
| config_path | false | repo ./ | If the config path is another spot in the repo or not named `.rubocop.yml` | `rubocop -c .rubocop_config_test.yml` |
| exclude_cops | false | | Define a list of paths to exclude from being linted. | `rubocop --except 'Style/FrozenStringLiteralComment Style/StringLiterals'` |
| fail_level | false | 'warning' | Can define `refactor`, `convention`, `warning`, `error` and 'fatal' to cause Rubocop to error out on. | `rubocop --fail-level 'warning'` |

## :warning: Gotchas

1. Due to the GitHub Check Runs API, we can only return 50 annotations per run. See [here](https://developer.github.com/v3/checks/runs/#output-object) for more info.
2. There is a bug with the Checks API that might cause your runs to get jumbled in the UI, but they will all still run and render annotations in the diff correctly.
3. You can't use --version with multiple gems. You can specify multiple gems with version requirements using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`

## :camera_flash: Screenshots

![Rubocop Linter Checks Overview](screenshots/check-overview.png)
![Rubocop Linter File Annotation](screenshots/file-annotation.png)
### Screenshots
## :bookmark: Changelog
![Rubocop Linter Checks Overview][image1]
![Rubocop Linter File Annotation][image2]
[View our Changelog](/CHANGELOG.md)
## Community
## :sos: Contributing
### Changelog
[Contributing Guide](/CONTRIBUTING.md)
[View our Changelog][changelog]
## :rotating_light: Code of Conduct
### Contributing
[Code of Conduct](/CODE_OF_CONDUCT.md)
[Contributing Guide][contributing]
## :copyright: License
### Code of Conduct
[MIT](/LICENSE.md)
[Code of Conduct][coc]
## :1st_place_medal: Recognition
### License
This project was originally forked from [gimenete/rubocop-action](https://github.com/gimenete/rubocop-action). Many thanks to [Alberto Gimeno](https://github.com/gimenete) for creating this project.
[MIT][license]
## :robot: Check Out My Other Ruby GitHub Actions
## Other Ruby GitHub Actions
- [andrewmcodes/haml-lint-action](https://github.com/andrewmcodes/haml-lint-action).
- [andrewmcodes/standardrb-action](https://github.com/andrewmcodes/standardrb-action).
## Contributors
## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down
30 changes: 4 additions & 26 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,15 @@ name: 'Rubocop Linter Action'
description: 'A GitHub Action that lints your Ruby code with Rubocop!'
author: 'Andrew Mason <andrewmcodes@protonmail.com>'
inputs:
version:
description: 'Define a specific version of Rubocop otherwise uses latest'
action_config_path:
description: 'Define a path to your optional action config file.'
required: false
default: ''
additional_gems:
description: 'Define additional gems to install to use with rubocop'
required: false
default: 'rubocop-performance rubocop-rails rubocop-minitest rubocop-rspec'
config_path:
description: 'Define a path to a config file not in the ./ named .rubocop.yml'
required: false
default: ''
excluded_cops:
description: 'List out Cops or departments to exclude from run'
required: false
default: ''
fail_level:
description: 'Define Fail level, available values are refactor, convention, warning, error and fatal'
required: false
default: 'warning'
bundle:
description: 'Bundle your gemfile, to use a specific version or a repo of a gem'
required: false
default: false
default: '.github/config/rubocop_linter_action.yml'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.version }}
- ${{ inputs.additional_gems }}
- ${{ inputs.bundle }}
- ${{ inputs.action_config_path }}
env:
GITHUB_TOKEN: secrets.GITHUB_TOKEN
branding:
Expand Down
Loading

0 comments on commit e140072

Please sign in to comment.