Skip to content

Commit 3daa3bd

Browse files
authored
Fix CI on Ruby 3.0 and add Ruby 4.0 to the matrix (#411)
## Summary CI on the oldest supported Ruby breaks as soon as anything calls `Hash#to_json`, because the newest activesupport that installs there is incompatible with the latest json release. This keeps the Ruby 3.0 job green without restricting the json versions the gem allows for users, and adds Ruby 4.0 to the test matrix so the gem is exercised on the current Ruby. ## Details - activesupport 7.1 (the newest installable on Ruby 3.0) calls `JSON.generate(..., quirks_mode: true)`, which json 3.0 removed, so `{a: 1}.to_json` raises `ArgumentError: unknown keyword: quirks_mode`. activesupport 7.2.4 and 8.1.x work with json 3.1, so the Gemfile pin is limited to Ruby 3.0; the gemspec is unchanged. - Ruby 4.0 no longer ships `ostruct` as a default gem, and the specs require it, so it is added to the development group. The library already guards `OpenStruct` with `defined?`. - The latest RuboCop flags disable/enable pairs around a single statement (`Style/DirectiveScope`) and fails the rubocop job before rspec runs, so those directives become `rubocop:disable-next`. - `git` is pinned below 6 because danger 9.6 references `Git::Base`, which git 6 no longer loads eagerly. - The unreleased CHANGELOG heading is now `1.1.1 (Next)`: danger-changelog only recognizes headings containing `(Next)` or `[Unreleased]`. - Includes the Dependabot bumps of the danger-pr-comment workflows to v0.1.1 (#409, #410).
1 parent 4db6a78 commit 3daa3bd

10 files changed

Lines changed: 26 additions & 19 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ permissions:
1313

1414
jobs:
1515
rubocop:
16-
runs-on: ubuntu-latest
16+
runs-on: ubuntu-24.04 # no ubuntu-26.04 builds of Ruby 3.0/3.1 yet; revisit when ubuntu-latest moves
1717
steps:
1818
- uses: actions/checkout@v7
1919
- uses: ruby/setup-ruby@v1
@@ -24,11 +24,11 @@ jobs:
2424
run: bundle exec rubocop --parallel --format progress
2525

2626
rspec:
27-
runs-on: ubuntu-latest
27+
runs-on: ubuntu-24.04 # no ubuntu-26.04 builds of Ruby 3.0/3.1 yet; revisit when ubuntu-latest moves
2828
needs: ['rubocop']
2929
strategy:
3030
matrix:
31-
ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4']
31+
ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4', '4.0']
3232
steps:
3333
- name: Check out branch
3434
uses: actions/checkout@v7

‎.github/workflows/danger-comment.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ on:
77

88
jobs:
99
comment:
10-
uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@v0.1.0
10+
uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@v0.1.1
1111
secrets: inherit

‎.github/workflows/danger.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
danger:
9-
uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@v0.1.0
9+
uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@v0.1.1
1010
secrets: inherit
1111
with:
1212
ruby-version: '3.4'

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
### Next release
1+
### 1.1.1 (Next)
22

33
#### Fixes
44

5+
* [#411](https://github.com/ruby-grape/grape-entity/pull/411): Fix CI on Ruby 3.0 (pin `json` below 3.0, `git` below 6, newer RuboCop directives), add Ruby 4.0 to the test matrix - [@numbata](https://github.com/numbata).
56
* Your contribution here.
67

78
#### Features

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Document any external behavior in the [README](README.md).
5252

5353
#### Update Changelog
5454

55-
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.
55+
Add a line to [CHANGELOG](CHANGELOG.md) under the unreleased `(Next)` section. Make it look like every other line, including your name and link to your Github account.
5656

5757
#### Commit Changes
5858

‎Gemfile‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ gemspec
66

77
group :development, :test do
88
gem 'bundler'
9+
# activesupport 7.1 (the newest on Ruby 3.0) passes `quirks_mode:` to JSON.generate, which json 3.0 removed
10+
gem 'json', '< 3.0' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
911
gem 'maruku'
12+
gem 'ostruct' # no longer a default gem in Ruby 4.0
1013
gem 'pry' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
1114
gem 'pry-byebug' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
1215
gem 'rack-test'
1316
gem 'rake'
1417
gem 'rspec', '~> 3.9'
15-
gem 'rubocop', '~> 1.0'
18+
gem 'rubocop', '~> 1.90' # the disable-next directive needs 1.90
1619
gem 'yard'
1720
end
1821

@@ -21,6 +24,8 @@ group :test do
2124
gem 'danger', require: false
2225
gem 'danger-changelog', require: false
2326
gem 'danger-pr-comment', require: false
27+
# danger 9.6 references Git::Base, which git 6 no longer loads eagerly; drop once danger supports git 6
28+
gem 'git', '< 6'
2429
gem 'growl'
2530
gem 'guard'
2631
gem 'guard-bundler'

‎RELEASING.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Increment the version, modify [lib/grape-entity/version.rb](lib/grape-entity/ver
1919
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.5.1` to `0.5.2`).
2020
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.5.1` to `0.4.0`).
2121

22-
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
22+
Change the "(Next)" heading in [CHANGELOG.md](CHANGELOG.md) to the new version and release date.
2323

2424
```
2525
0.4.0 (2014-01-27)
@@ -52,8 +52,13 @@ Pushed grape-entity 0.4.0 to rubygems.org.
5252
Add the next release to [CHANGELOG.md](CHANGELOG.md).
5353

5454
```
55-
Next Release
56-
============
55+
### X.Y.Z (Next)
56+
57+
#### Fixes
58+
59+
* Your contribution here.
60+
61+
#### Features
5762
5863
* Your contribution here.
5964
```

‎lib/grape_entity/entity.rb‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def self.inherited(subclass)
190190
# field, typically the value is a hash with two fields, type and desc.
191191
# @option options :merge This option allows you to merge an exposed field to the root
192192
#
193-
# rubocop:disable Layout/LineLength
193+
# rubocop:disable-next Layout/LineLength
194194
def self.expose(*args, &block)
195195
options = merge_options(args.last.is_a?(Hash) ? args.pop : {})
196196

@@ -217,7 +217,6 @@ def self.expose(*args, &block)
217217
@nesting_stack ||= []
218218
args.each { |attribute| build_exposure_for_attribute(attribute, @nesting_stack, options, block) }
219219
end
220-
# rubocop:enable Layout/LineLength
221220

222221
def self.build_exposure_for_attribute(attribute, nesting_stack, options, block)
223222
exposure_list = nesting_stack.empty? ? root_exposures : nesting_stack.last.nested_exposures

‎lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def clear
3636
@exposures.clear
3737
end
3838

39-
# rubocop:disable Style/DocumentDynamicEvalDefinition
39+
# rubocop:disable-next Style/DocumentDynamicEvalDefinition
4040
%i[
4141
each
4242
to_ary to_a
@@ -56,7 +56,6 @@ def #{name}(*args, &block)
5656
end
5757
RUBY
5858
end
59-
# rubocop:enable Style/DocumentDynamicEvalDefinition
6059

6160
# Determine if we have any nesting exposures with the same name.
6261
def deep_complex_nesting?(entity)

‎spec/grape_entity/entity_spec.rb‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@
3333
end
3434

3535
it 'makes sure that :format_with as a proc cannot be used with a block' do
36-
# rubocop:disable Style/BlockDelimiters
36+
# rubocop:disable-next Style/BlockDelimiters
3737
expect {
3838
subject.expose :name, format_with: proc {} do
3939
p 'hi'
4040
end
4141
}.to raise_error ArgumentError
42-
# rubocop:enable Style/BlockDelimiters
4342
end
4443

4544
it 'makes sure unknown options are not silently ignored' do
@@ -2294,12 +2293,11 @@ class FriendEntity < Grape::Entity
22942293
end
22952294
end
22962295

2297-
# rubocop:disable Lint/EmptyBlock
2296+
# rubocop:disable-next Lint/EmptyBlock
22982297
fresh_class.class_eval do
22992298
expose :first_friend, using: EntitySpec::FriendEntity do |_user, _opts|
23002299
end
23012300
end
2302-
# rubocop:enable Lint/EmptyBlock
23032301

23042302
rep = subject.value_for(:first_friend)
23052303
expect(rep).to be_kind_of EntitySpec::FriendEntity

0 commit comments

Comments
 (0)