Fix Unprocessable Entity (RuntimeError) RuntimeError (#18)
fixes #16 fixes #17 Also updates the docs and moves to a smaller ruby image.
This commit is contained in:
parent
c3f0a167d0
commit
9f15426bbf
@ -1,4 +1,6 @@
|
||||
FROM ruby:2.6
|
||||
FROM ruby:2.6.5-alpine
|
||||
|
||||
RUN apk add --update build-base git
|
||||
|
||||
LABEL com.github.actions.name="Rubocop Linter"
|
||||
LABEL com.github.actions.description="Lint your Ruby code"
|
||||
@ -8,4 +10,6 @@ LABEL com.github.actions.color="red"
|
||||
LABEL maintainer="Andrew Mason <andrewmcodes@protonmail.com>"
|
||||
|
||||
COPY lib /action/lib
|
||||
RUN gem install bundler
|
||||
|
||||
ENTRYPOINT ["/action/lib/entrypoint.sh"]
|
||||
|
||||
30
README.md
30
README.md
@ -2,9 +2,11 @@
|
||||
|
||||
# Rubocop Linter Action
|
||||
|
||||

|
||||

|
||||
|
||||
GitHub Action to run Rubocop against your code.
|
||||
GitHub Action to run Rubocop against your code and create annotations in the UI.
|
||||
|
||||
**NOTE: 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.**
|
||||
|
||||
## Usage
|
||||
|
||||
@ -12,7 +14,7 @@ Add the following to your GitHub action workflow:
|
||||
|
||||
```yaml
|
||||
- name: Rubocop Linter
|
||||
uses: andrewmcodes/rubocop-linter-action@v0.1.2
|
||||
uses: andrewmcodes/rubocop-linter-action@v0.2.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
@ -20,27 +22,23 @@ Add the following to your GitHub action workflow:
|
||||
## Example Workflow
|
||||
|
||||
```yaml
|
||||
name: Ruby
|
||||
name: Rubocop
|
||||
|
||||
on: [push]
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Ruby 2.6
|
||||
uses: actions/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6.x
|
||||
- name: add PostgreSQL dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y postgresql-client libpq-dev
|
||||
- name: Rubocop Linter
|
||||
uses: andrewmcodes/rubocop-linter-action@v0.1.2
|
||||
uses: andrewmcodes/rubocop-linter-action@v0.2.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
|
||||
set -e
|
||||
|
||||
gem install rubocop rubocop-performance rubocop-rails
|
||||
gem install rubocop rubocop-performance rubocop-rails rubocop-minitest rubocop-rspec
|
||||
|
||||
ruby /action/lib/index.rb
|
||||
|
||||
52
lib/index.rb
52
lib/index.rb
@ -11,9 +11,8 @@ require 'time'
|
||||
@repository = @event["repository"]
|
||||
@owner = @repository["owner"]["login"]
|
||||
@repo = @repository["name"]
|
||||
|
||||
@conclusion = "success"
|
||||
@check_name = "Rubocop"
|
||||
|
||||
@headers = {
|
||||
"Content-Type": 'application/json',
|
||||
"Accept": 'application/vnd.github.antiope-preview+json',
|
||||
@ -46,8 +45,6 @@ end
|
||||
def update_check(id, conclusion, output)
|
||||
body = {
|
||||
"name" => @check_name,
|
||||
"head_sha" => @GITHUB_SHA,
|
||||
"status" => 'completed',
|
||||
"completed_at" => Time.now.iso8601,
|
||||
"conclusion" => conclusion,
|
||||
"output" => output
|
||||
@ -56,7 +53,6 @@ def update_check(id, conclusion, output)
|
||||
http = Net::HTTP.new('api.github.com', 443)
|
||||
http.use_ssl = true
|
||||
path = "/repos/#{@owner}/#{@repo}/check-runs/#{id}"
|
||||
|
||||
resp = http.patch(path, body.to_json, @headers)
|
||||
|
||||
if resp.code.to_i >= 300
|
||||
@ -73,13 +69,25 @@ end
|
||||
}
|
||||
|
||||
def run_rubocop
|
||||
annotations = []
|
||||
annotations = annotation_messages
|
||||
|
||||
output = {
|
||||
"title": @check_name,
|
||||
"summary": "#{annotations.size} offense(s) found",
|
||||
"annotations" => annotations
|
||||
}
|
||||
|
||||
return { "output" => output, "conclusion" => @conclusion }
|
||||
end
|
||||
|
||||
def annotation_messages
|
||||
errors = nil
|
||||
count = 0
|
||||
annotation_list = []
|
||||
|
||||
Dir.chdir(@GITHUB_WORKSPACE) {
|
||||
errors = JSON.parse(`rubocop --format json`)
|
||||
}
|
||||
conclusion = "success"
|
||||
count = 0
|
||||
|
||||
errors["files"].each do |file|
|
||||
path = file["path"]
|
||||
@ -92,27 +100,22 @@ def run_rubocop
|
||||
annotation_level = @annotation_levels[severity]
|
||||
count = count + 1
|
||||
|
||||
return annotation_list if count == 48
|
||||
|
||||
if annotation_level == "failure"
|
||||
conclusion = "failure"
|
||||
@conclusion = "failure"
|
||||
end
|
||||
|
||||
annotations.push({
|
||||
"path" => path,
|
||||
"start_line" => location["start_line"],
|
||||
"end_line" => location["start_line"],
|
||||
"annotation_level": annotation_level,
|
||||
"message" => message
|
||||
})
|
||||
annotation_list.push({
|
||||
"path" => path,
|
||||
"start_line" => location["start_line"],
|
||||
"end_line" => location["start_line"],
|
||||
"annotation_level": annotation_level,
|
||||
"message" => message
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
output = {
|
||||
"title": @check_name,
|
||||
"summary": "#{count} offense(s) found",
|
||||
"annotations" => annotations
|
||||
}
|
||||
|
||||
return { "output" => output, "conclusion" => conclusion }
|
||||
return annotation_list
|
||||
end
|
||||
|
||||
def run
|
||||
@ -121,7 +124,6 @@ def run
|
||||
results = run_rubocop()
|
||||
conclusion = results["conclusion"]
|
||||
output = results["output"]
|
||||
|
||||
update_check(id, conclusion, output)
|
||||
rescue
|
||||
update_check(id, "failure", nil)
|
||||
|
||||
Reference in New Issue
Block a user