Skip to content

Commit 3b36c5a

Browse files
authored
Try support Ruby 4.0 (#758)
resolve #721 Once the CI for this PR passes and is merged, add ruby ​​4.0 CI to the master branch protection rule.
1 parent 4ec1c2b commit 3b36c5a

8 files changed

Lines changed: 143 additions & 18 deletions

File tree

.github/workflows/deploy-doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2020
- uses: ruby/setup-ruby@19a43a6a2428d455dbd1b85344698725179c9d8c # v1.289.0
2121
with:
22-
ruby-version: '3.4.8'
22+
ruby-version: '4.0'
2323
- run: bundle install
2424
- name: Setup Pages
2525
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: ruby/setup-ruby@19a43a6a2428d455dbd1b85344698725179c9d8c # v1.289.0
2424
with:
2525
bundler-cache: true
26-
ruby-version: 3.4.8
26+
ruby-version: '4.0'
2727
- name: Update version file with the release version
2828
run: |
2929
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- '3.2'
1919
- '3.3'
2020
- '3.4'
21+
- '4.0'
2122
name: Ruby v${{ matrix.ruby }}
2223
steps:
2324
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ source 'https://rubygems.org'
44
gemspec
55

66
group :development, :test do
7+
gem 'irb', '~> 1.15.0'
78
gem 'rack', '~> 3.1' # for yard server
89
gem 'rackup', '~> 2.1' # for yard server
910
gem 'rbs', '~> 3.10.0'
11+
gem 'redcarpet', '~> 3.6.0'
1012
gem 'rubocop', '~> 1.85.0', require: false
1113
gem 'steep', '~> 1.10.0'
1214
gem 'webrick', '~> 1.9.1'

Gemfile.lock

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ PATH
88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
activesupport (8.0.2)
11+
activesupport (8.1.2)
1212
base64
13-
benchmark (>= 0.3)
1413
bigdecimal
1514
concurrent-ruby (~> 1.0, >= 1.3.1)
1615
connection_pool (>= 2.2.5)
1716
drb
1817
i18n (>= 1.6, < 2)
18+
json
1919
logger (>= 1.4.2)
2020
minitest (>= 5.1)
2121
securerandom (>= 0.3)
@@ -25,22 +25,27 @@ GEM
2525
public_suffix (>= 2.0.2, < 7.0)
2626
ast (2.4.3)
2727
base64 (0.2.0)
28-
benchmark (0.4.0)
2928
bigdecimal (3.3.1)
3029
concurrent-ruby (1.3.5)
3130
connection_pool (2.5.2)
3231
crack (1.0.1)
3332
bigdecimal
3433
rexml
3534
csv (3.3.4)
35+
date (3.5.1)
3636
diff-lcs (1.6.2)
3737
drb (2.2.1)
38-
ffi (1.17.2-arm64-darwin)
39-
ffi (1.17.2-x86_64-linux-gnu)
38+
erb (6.0.1)
39+
ffi (1.17.2)
4040
fileutils (1.7.3)
4141
hashdiff (1.2.1)
4242
i18n (1.14.7)
4343
concurrent-ruby (~> 1.0)
44+
io-console (0.8.2)
45+
irb (1.15.3)
46+
pp (>= 0.6.0)
47+
rdoc (>= 4.0.0)
48+
reline (>= 0.4.2)
4449
json (2.18.1)
4550
json-schema (4.3.1)
4651
addressable (>= 2.8)
@@ -52,14 +57,21 @@ GEM
5257
logger (1.7.0)
5358
mcp (0.8.0)
5459
json-schema (>= 4.1)
55-
minitest (5.25.5)
60+
minitest (6.0.1)
61+
prism (~> 1.5)
5662
multipart-post (2.4.1)
5763
mutex_m (0.3.0)
5864
parallel (1.27.0)
5965
parser (3.3.10.2)
6066
ast (~> 2.4.1)
6167
racc
68+
pp (0.6.3)
69+
prettyprint
70+
prettyprint (0.2.0)
6271
prism (1.9.0)
72+
psych (5.3.1)
73+
date
74+
stringio
6375
public_suffix (6.0.2)
6476
racc (1.8.1)
6577
rack (3.2.5)
@@ -73,7 +85,14 @@ GEM
7385
rbs (3.10.3)
7486
logger
7587
tsort
88+
rdoc (7.2.0)
89+
erb
90+
psych (>= 4.0.0)
91+
tsort
92+
redcarpet (3.6.1)
7693
regexp_parser (2.11.3)
94+
reline (0.6.3)
95+
io-console (~> 0.5)
7796
rexml (3.4.4)
7897
rspec (3.13.2)
7998
rspec-core (~> 3.13.0)
@@ -122,6 +141,7 @@ GEM
122141
strscan (>= 1.0.0)
123142
terminal-table (>= 2, < 5)
124143
uri (>= 0.12.0)
144+
stringio (3.2.0)
125145
strscan (3.1.3)
126146
terminal-table (4.0.0)
127147
unicode-display_width (>= 1.1.1, < 4)
@@ -142,14 +162,17 @@ GEM
142162
PLATFORMS
143163
arm64-darwin-21
144164
arm64-darwin-22
165+
arm64-darwin-24
145166
x86_64-linux
146167

147168
DEPENDENCIES
169+
irb (~> 1.15.0)
148170
line-bot-api!
149171
rack (~> 3.1)
150172
rackup (~> 2.1)
151173
rake (~> 13.0)
152174
rbs (~> 3.10.0)
175+
redcarpet (~> 3.6.0)
153176
rspec (~> 3.13.0)
154177
rubocop (~> 1.85.0)
155178
steep (~> 1.10.0)

Rakefile

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ RSpec::Core::RakeTask.new(:spec)
55

66
task default: :spec
77

8+
# To avoid double "bundle exec" calls, e.g. bundle exec ... in bundle exec rake ...
9+
def bundle_exec(command)
10+
Bundler.with_unbundled_env do
11+
sh "bundle exec #{command}"
12+
end
13+
end
14+
815
# We don't want to push tags to source control when releasing the gem
916
Rake::Task["release"].clear
1017

@@ -24,17 +31,19 @@ task :test_normal, [:skip_tag] do |_, args|
2431
rspec_opts = []
2532
rspec_opts << "--tag '~#{skip_tag}'" if skip_tag
2633

27-
sh "bundle exec rspec --exclude-pattern 'spec/line/bot/line_bot_api_gem_spec.rb,spec/line/bot/line_bot_gem_spec.rb' #{rspec_opts.join(' ')}"
34+
bundle_exec(
35+
"rspec --exclude-pattern 'spec/line/bot/line_bot_api_gem_spec.rb,spec/line/bot/line_bot_gem_spec.rb' #{rspec_opts.join(' ')}"
36+
)
2837
end
2938

3039
desc "Test line-bot-api gem spec"
3140
task :test_line_bot_api do
32-
sh "bundle exec rspec --pattern 'spec/line/bot/line_bot_api_gem_spec.rb'"
41+
bundle_exec("rspec --pattern 'spec/line/bot/line_bot_api_gem_spec.rb'")
3342
end
3443

3544
desc "Test line/bot gem(?) spec"
3645
task :test_line_bot do
37-
sh "bundle exec rspec --pattern 'spec/line/bot/line_bot_gem_spec.rb'"
46+
bundle_exec("rspec --pattern 'spec/line/bot/line_bot_gem_spec.rb'")
3847
end
3948

4049
desc "Run all tests in separate processes"
@@ -46,18 +55,18 @@ end
4655

4756
desc "Validate comment for YARD"
4857
task :validate_yard_comment do
49-
sh "bundle exec yard stats ./lib/line/bot/v2 --fail-on-warning"
58+
bundle_exec("yard stats ./lib/line/bot/v2 --fail-on-warning")
5059
end
5160

5261
desc "RBS type check"
5362
task :rbs do
54-
sh "bundle exec rbs collection install"
55-
sh "bundle exec rbs -I sig validate"
63+
bundle_exec("rbs collection install")
64+
bundle_exec("rbs -I sig validate")
5665
end
5766

5867
desc "RBS type check (with steep)"
5968
task :rbs_steep do
60-
sh "bundle exec steep check"
69+
bundle_exec("steep check")
6170
end
6271

6372
desc "RBS type check (with test)"
@@ -86,17 +95,17 @@ end
8695

8796
desc "Run rubocop"
8897
task :rubocop do
89-
sh "bundle exec rubocop"
98+
bundle_exec("rubocop")
9099
end
91100

92101
desc "Fix rubocop errors"
93102
task :rubocop_fix do
94-
sh "bundle exec rubocop -A"
103+
bundle_exec("rubocop -A")
95104
end
96105

97106
desc "Check buildable and its contents"
98107
task :build_test do
99-
sh "bundle exec rake build"
108+
bundle_exec("rake build")
100109
sh "tar -xvf pkg/line-bot-api-*.gem"
101110

102111
puts "<<Show the contents of the gem>>"

rbs_collection.lock.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ gems:
2525
revision: 0ef449166f72c767f58f920cc36aca818fbf082f
2626
remote: https://github.com/ruby/gem_rbs_collection.git
2727
repo_dir: gems
28+
- name: dbm
29+
version: '0'
30+
source:
31+
type: stdlib
2832
- name: diff-lcs
2933
version: '1.5'
3034
source:
@@ -37,6 +41,10 @@ gems:
3741
version: '0'
3842
source:
3943
type: stdlib
44+
- name: erb
45+
version: '0'
46+
source:
47+
type: stdlib
4048
- name: hashdiff
4149
version: '1.1'
4250
source:
@@ -45,6 +53,10 @@ gems:
4553
revision: 0ef449166f72c767f58f920cc36aca818fbf082f
4654
remote: https://github.com/ruby/gem_rbs_collection.git
4755
repo_dir: gems
56+
- name: io-console
57+
version: '0'
58+
source:
59+
type: stdlib
4860
- name: json
4961
version: '0'
5062
source:
@@ -61,6 +73,26 @@ gems:
6173
version: '0'
6274
source:
6375
type: stdlib
76+
- name: pp
77+
version: '0'
78+
source:
79+
type: stdlib
80+
- name: prettyprint
81+
version: '0'
82+
source:
83+
type: stdlib
84+
- name: pstore
85+
version: '0'
86+
source:
87+
type: stdlib
88+
- name: psych
89+
version: '0'
90+
source:
91+
type: stdlib
92+
- name: rdoc
93+
version: '0'
94+
source:
95+
type: stdlib
6496
- name: socket
6597
version: '0'
6698
source:
@@ -69,6 +101,10 @@ gems:
69101
version: '0'
70102
source:
71103
type: stdlib
104+
- name: tsort
105+
version: '0'
106+
source:
107+
type: stdlib
72108
- name: uri
73109
version: '0'
74110
source:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require 'yaml'
2+
3+
RSpec.describe "GitHub Actions workflow Ruby version consistency" do
4+
let(:workflows_dir) { File.expand_path('../../.github/workflows', __dir__) }
5+
6+
let(:latest_matrix_version) do
7+
pr_workflow = YAML.safe_load(
8+
File.read(File.join(workflows_dir, 'pull_request.yml')),
9+
permitted_classes: [Symbol]
10+
)
11+
versions = pr_workflow.dig('jobs', 'build', 'strategy', 'matrix', 'ruby')
12+
expect(versions).not_to be_nil, "No ruby matrix found in pull_request.yml"
13+
versions.map(&:to_s).max_by { |v| Gem::Version.new(v) }
14+
end
15+
16+
let(:hardcoded_ruby_versions) do
17+
versions = {}
18+
19+
Dir[File.join(workflows_dir, '*.yml')].each do |file|
20+
workflow = YAML.safe_load(File.read(file), permitted_classes: [Symbol])
21+
basename = File.basename(file)
22+
23+
next unless workflow['jobs']
24+
25+
workflow['jobs'].each do |job_name, job|
26+
steps = job['steps'] || []
27+
steps.each do |step|
28+
next unless step.is_a?(Hash) && step.dig('with', 'ruby-version')
29+
30+
ruby_version = step['with']['ruby-version'].to_s
31+
next if ruby_version.include?('${{')
32+
33+
versions["#{basename} -> #{job_name}"] = ruby_version
34+
end
35+
end
36+
end
37+
38+
versions
39+
end
40+
41+
it "uses the same Ruby version as the latest in pull_request.yml matrix" do
42+
expect(hardcoded_ruby_versions).not_to(
43+
be_empty, "No hardcoded ruby-version found in workflows"
44+
)
45+
46+
mismatched = hardcoded_ruby_versions.reject { |_, v| v == latest_matrix_version }
47+
expect(mismatched).to(
48+
be_empty,
49+
"Expected all hardcoded ruby-version to be '#{latest_matrix_version}' " \
50+
"(latest in pull_request.yml matrix), but found:\n" \
51+
"#{mismatched.map { |k, v| " #{k}: #{v}" }.join("\n")}"
52+
)
53+
end
54+
end

0 commit comments

Comments
 (0)