Skip to content

Commit e43b35f

Browse files
committed
Detect previous Ruby version in update script
Read include/ruby/version.h to compute the previous Ruby version and use it as the default FROM argument in tool/update-NEWS-github-release.rb. Add a workflow step to run the script for Ruby 4.0 in bundled_gems.yml Detect previous Ruby version in update script
1 parent 9b0a3db commit e43b35f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

tool/update-NEWS-github-release.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,20 @@ def fetch_default_gems_versions(ruby_version)
6262
map
6363
end
6464

65+
def previous_ruby_version
66+
version_h = File.join(__dir__, "..", "include", "ruby", "version.h")
67+
major = minor = nil
68+
File.foreach(version_h) do |l|
69+
major = $1.to_i if l =~ /^\s*#\s*define\s+RUBY_API_VERSION_MAJOR\s+(\d+)/
70+
minor = $1.to_i if l =~ /^\s*#\s*define\s+RUBY_API_VERSION_MINOR\s+(\d+)/
71+
end
72+
abort "Cannot detect Ruby version from #{version_h}" unless major && minor
73+
minor > 0 ? "#{major}.#{minor - 1}" : "#{major - 1}.0"
74+
end
75+
6576
# Load gem=>version map from a file or from stdgems.org if a Ruby version is given.
6677
def load_versions(arg)
67-
if arg.nil?
68-
abort "usage: #{File.basename($0)} FROM [--update]"
69-
end
78+
arg ||= previous_ruby_version
7079
if File.exist?(arg)
7180
File.readlines(arg).map(&:split).to_h
7281
elsif arg.match?(/^\d+\.\d+(?:\.\d+)?$/)

0 commit comments

Comments
 (0)