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