|
| 1 | +versions = ARGV.fetch(0).split(',').map(&:strip) |
| 2 | +versions.each do |engine_version| |
| 3 | + engine_input, version = engine_version.split('-', 2) |
| 4 | + |
| 5 | + if engine_input == 'windows' |
| 6 | + require_relative 'generate-windows-versions' |
| 7 | + exit |
| 8 | + end |
| 9 | + |
| 10 | + MATCH = case engine_input |
| 11 | + when 'ruby', 'jruby' |
| 12 | + /^\d+\.\d+\./ |
| 13 | + when 'truffleruby' |
| 14 | + /^\d+\./ |
| 15 | + end |
| 16 | + |
| 17 | + raise unless version[MATCH] |
| 18 | + |
| 19 | + engines = [engine_input] |
| 20 | + engines << 'truffleruby+graalvm' if engine_input == 'truffleruby' |
| 21 | + |
| 22 | + engines.each do |engine| |
| 23 | + puts engine |
| 24 | + |
| 25 | + # Update ruby-builder-versions.json |
| 26 | + file = "#{__dir__}/ruby-builder-versions.json" |
| 27 | + lines = File.readlines(file, chomp: true) |
| 28 | + |
| 29 | + from = lines.index { |line| line.include?(%{"#{engine}": [}) } |
| 30 | + raise "Could not find start of #{engine}" unless from |
| 31 | + to = from |
| 32 | + to += 1 until lines[to].include?(']') |
| 33 | + |
| 34 | + from += 1 # [ |
| 35 | + to -= 2 # head, ] |
| 36 | + |
| 37 | + puts lines[from..to] |
| 38 | + |
| 39 | + release_line = lines[from..to].find { |line| |
| 40 | + v = line[/"([^"]+)"/, 1] and v[MATCH] == version[MATCH] |
| 41 | + } |
| 42 | + |
| 43 | + if release_line |
| 44 | + append = " #{version.inspect}," |
| 45 | + release_line << append unless release_line.end_with?(append) |
| 46 | + else |
| 47 | + lines.insert to+1, " #{version.inspect}," |
| 48 | + end |
| 49 | + |
| 50 | + File.write(file, lines.join("\n") + "\n") |
| 51 | + |
| 52 | + # Update README.md |
| 53 | + file = "#{__dir__}/README.md" |
| 54 | + lines = File.readlines(file) |
| 55 | + engine_line = lines.find { |line| line.start_with?("| `#{engine}`") } |
| 56 | + engine_line.sub!(/(.+ (?:-|until)) (\d+(?:\.\d+)+)/) do |
| 57 | + if Gem::Version.new(version) > Gem::Version.new($2) |
| 58 | + "#{$1} #{version}" |
| 59 | + else |
| 60 | + $& |
| 61 | + end |
| 62 | + end |
| 63 | + File.write(file, lines.join) |
| 64 | + end |
| 65 | +end |
0 commit comments