forked from ruby-builder-bot/setup-ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnew-version.rb
More file actions
34 lines (25 loc) · 680 Bytes
/
Copy pathnew-version.rb
File metadata and controls
34 lines (25 loc) · 680 Bytes
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
engine, version = ARGV.fetch(0).split('-', 2)
MATCH = case engine
when 'ruby', 'jruby'
/^\d+\.\d+\./
when 'truffleruby'
/^\d+\./
end
raise unless version[MATCH]
file = "#{__dir__}/ruby-builder-versions.json"
lines = File.readlines(file, chomp: true)
from = lines.index { |line| line =~ /"#{engine}": \[/ }
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
release_line << " #{version.inspect},"
else
lines.insert to+1, " #{version.inspect},"
end
File.write(file, lines.join("\n") + "\n")