Skip to content

Commit

Permalink
Simplify new-versions.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 24, 2023
1 parent 8aa012b commit d60780f
Showing 1 changed file with 34 additions and 40 deletions.
74 changes: 34 additions & 40 deletions new-versions.rb
Expand Up @@ -3,66 +3,60 @@

versions.each do |engine_version|
puts engine_version
engine_input, version = engine_version.split('-', 2)
engine, version = engine_version.split('-', 2)
p [engine, version]

if engine_input == 'windows'
if engine == 'windows'
require_relative 'generate-windows-versions'
exit
end

match = case engine_input
match = case engine
when 'ruby', 'jruby'
/^\d+\.\d+\./
when 'truffleruby'
when 'truffleruby', 'truffleruby+graalvm'
/^\d+\./
end

raise engine_version unless version[match]

engines = [engine_input]
engines << 'truffleruby+graalvm' if engine_input == 'truffleruby'
# Update ruby-builder-versions.json
file = "#{__dir__}/ruby-builder-versions.json"
lines = File.readlines(file, chomp: true)

engines.each do |engine|
puts engine
from = lines.index { |line| line.include?(%{"#{engine}": [}) }
raise "Could not find start of #{engine}" unless from
to = from
to += 1 until lines[to].include?(']')

# Update ruby-builder-versions.json
file = "#{__dir__}/ruby-builder-versions.json"
lines = File.readlines(file, chomp: true)
from += 1 # [
to -= 2 # head, ]

from = lines.index { |line| line.include?(%{"#{engine}": [}) }
raise "Could not find start of #{engine}" unless from
to = from
to += 1 until lines[to].include?(']')
puts lines[from..to]

from += 1 # [
to -= 2 # head, ]
release_line = lines[from..to].find { |line|
v = line[/"([^"]+)"/, 1] and v[match] == version[match]
}

puts lines[from..to]
if release_line
append = " #{version.inspect},"
release_line << append unless release_line.end_with?(append)
else
lines.insert to+1, " #{version.inspect},"
end

release_line = lines[from..to].find { |line|
v = line[/"([^"]+)"/, 1] and v[match] == version[match]
}
File.write(file, lines.join("\n") + "\n")

if release_line
append = " #{version.inspect},"
release_line << append unless release_line.end_with?(append)
# Update README.md
file = "#{__dir__}/README.md"
lines = File.readlines(file)
engine_line = lines.find { |line| line.start_with?("| `#{engine}`") }
engine_line.sub!(/(.+ (?:-|until)) (\d+(?:\.\d+)+(?:-\w+)?)/) do
if Gem::Version.new(version) > Gem::Version.new($2)
"#{$1} #{version}"
else
lines.insert to+1, " #{version.inspect},"
end

File.write(file, lines.join("\n") + "\n")

# Update README.md
file = "#{__dir__}/README.md"
lines = File.readlines(file)
engine_line = lines.find { |line| line.start_with?("| `#{engine}`") }
engine_line.sub!(/(.+ (?:-|until)) (\d+(?:\.\d+)+(?:-\w+)?)/) do
if Gem::Version.new(version) > Gem::Version.new($2)
"#{$1} #{version}"
else
$&
end
$&
end
File.write(file, lines.join)
end
File.write(file, lines.join)
end

0 comments on commit d60780f

Please sign in to comment.