Skip to content

Commit

Permalink
Migrate from Travis to GHA (ruby-grape#61)
Browse files Browse the repository at this point in the history
* Add GHA

* Get building

* Remove Ruby 2.6

* Remove Ruby 2.7 too

* Add lint job and remove travis config

* Fix rubocop config and autocorrect

* Fix tests

* Update rubucop_todo.yml

* Use newer ruby for rubocop

* More rubocop fixes

* Add danger workflow

* Update badges and rename workflow from ruby to test

* Update CHANGELOG
  • Loading branch information
mscrivo authored Jul 6, 2023
1 parent ca79820 commit 407afcb
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 92 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: danger
on: pull_request

jobs:
danger:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
rubygems: latest
- name: Run Danger
run: |
# the token is public, has public_repo scope and belongs to the grape-bot user owned by @dblock, this is ok
TOKEN=$(echo -n Z2hwX2lYb0dPNXNyejYzOFJyaTV3QUxUdkNiS1dtblFwZTFuRXpmMwo= | base64 --decode)
DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: test

on: [push, pull_request]

permissions:
contents: read

jobs:
lint:
name: RuboCop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
rubygems: latest

- name: Run RuboCop
run: bundle exec rubocop

test:
env:
GRAPE_ENTITY: 0.8.0

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby-version: ['3.0', '3.1', '3.2']

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run tests
run: bundle exec rake spec
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
/spec/reports/
/tmp/
.ruby-gemset
.ruby-version
.ruby-version
/.idea
13 changes: 1 addition & 12 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
AllCops:
NewCops: enable
Exclude:
- vendor/**/*
TargetRubyVersion:
2.7

inherit_from: .rubocop_todo.yml

Metrics/BlockLength:
Exclude:
- spec/**/*

Metrics/LineLength:
Exclude:
- spec/**/*

Metrics/MethodLength:
Exclude:
- spec/**/*

Naming/FileName:
Enabled: false

Expand Down
84 changes: 71 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,106 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-06-29 22:12:50 UTC using RuboCop version 0.86.0.
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 5000`
# on 2023-07-06 17:02:48 UTC using RuboCop version 1.42.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: Include.
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'grape-swagger-entity.gemspec'

# Offense count: 3
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/grape-swagger/entities/response_model_spec.rb'
- 'spec/support/shared_contexts/inheritance_api.rb'
- 'spec/support/shared_contexts/this_api.rb'

# Offense count: 1
# Configuration parameters: AllowComments, AllowEmptyLambdas.
Lint/EmptyBlock:
Exclude:
- 'spec/grape-swagger/entity/attribute_parser_spec.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods.
# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
Lint/RedundantSafeNavigation:
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'

# Offense count: 4
# Configuration parameters: IgnoredMethods.
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Max: 30
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'

# Offense count: 13
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
# AllowedMethods: refine
Metrics/BlockLength:
Exclude:
- '**/*.gemspec'
- 'spec/grape-swagger/entities/response_model_spec.rb'
- 'spec/grape-swagger/entity/attribute_parser_spec.rb'
- 'spec/grape-swagger/entity/parser_spec.rb'
- 'spec/support/shared_contexts/this_api.rb'

# Offense count: 1
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Max: 111
Exclude:
- 'lib/grape-swagger/entity/parser.rb'

# Offense count: 2
# Configuration parameters: IgnoredMethods.
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, Max.
Metrics/CyclomaticComplexity:
Max: 11
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'

# Offense count: 5
# Configuration parameters: CountComments, ExcludedMethods.
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
Metrics/MethodLength:
Max: 25
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'

# Offense count: 2
# Configuration parameters: IgnoredMethods.
# Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, Max.
Metrics/PerceivedComplexity:
Max: 12
Exclude:
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
Naming/VariableNumber:
Exclude:
- 'spec/grape-swagger/entities/response_model_spec.rb'

# Offense count: 4
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/grape-swagger/entity.rb'
- 'lib/grape-swagger/entity/attribute_parser.rb'
- 'lib/grape-swagger/entity/parser.rb'

# Offense count: 4
Style/OpenStructUse:
Exclude:
- 'spec/grape-swagger/entities/response_model_spec.rb'
- 'spec/support/shared_contexts/this_api.rb'
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#### Fixes

* [#61](https://github.com/ruby-grape/grape-swagger-entity/pull/61): Migrate from Travis to GHA for CI - [@mscrivo](https://github.com/mscrivo).
* Your contribution here.

### 0.5.1 (June 30, 2020)
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ group :development, :test do
gem 'rack-test'
gem 'rake'
gem 'rdoc'
gem 'rspec', '~> 3.9'
gem 'rubocop', '~> 0.85'
gem 'rspec'
gem 'rubocop'
end

gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger.git'

group :test do
gem 'grape-entity', ENV.fetch('GRAPE_ENTITY', '0.6.1')
gem 'ruby-grape-danger', '~> 0.1.1', require: false
gem 'ruby-grape-danger', '~> 0.2.0', require: false
gem 'simplecov', require: false
end
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# GrapeSwagger::Entity [![Build Status](https://travis-ci.org/ruby-grape/grape-swagger-entity.svg)](https://travis-ci.org/ruby-grape/grape-swagger-entity)
# GrapeSwagger::Entity

[![Gem Version](https://badge.fury.io/rb/grape-swagger-entity.svg)](https://badge.fury.io/rb/grape-swagger-entity)
[![Build Status](https://github.com/ruby-grape/grape-swagger-entity/workflows/test/badge.svg?branch=master)](https://github.com/ruby-grape/grape-swagger-entity/actions)

A simple grape-swagger adapter to allow parse representers as response model

Expand Down
1 change: 1 addition & 0 deletions grape-swagger-entity.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.4'
s.add_runtime_dependency 'grape-entity', '>= 0.6.0'
s.add_runtime_dependency 'grape-swagger', '>= 1.2.0'
s.metadata['rubygems_mfa_required'] = 'true'
end
2 changes: 1 addition & 1 deletion lib/grape-swagger/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ module Entity
end
end

GrapeSwagger.model_parsers.register(::GrapeSwagger::Entity::Parser, ::Grape::Entity)
GrapeSwagger.model_parsers.register(GrapeSwagger::Entity::Parser, Grape::Entity)
4 changes: 2 additions & 2 deletions lib/grape-swagger/entity/attribute_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def call(entity_options)
add_attribute_sample(param, documentation, :default)
add_attribute_sample(param, documentation, :example)

if (values = documentation[:values])
param[:enum] = values if values.is_a?(Array)
if (values = documentation[:values]) && values.is_a?(Array)
param[:enum] = values
end

if documentation[:is_array]
Expand Down
4 changes: 1 addition & 3 deletions lib/grape-swagger/entity/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
module GrapeSwagger
module Entity
class Parser
attr_reader :model
attr_reader :endpoint
attr_reader :attribute_parser
attr_reader :model, :endpoint, :attribute_parser

def initialize(model, endpoint)
@model = model
Expand Down
Loading

0 comments on commit 407afcb

Please sign in to comment.