1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/tool/releng/gen-mail.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

2020-12-20 13:02:30 -05:00
#!/usr/bin/env ruby
require "open-uri"
require "yaml"
lang = ARGV.shift
unless lang
abort "usage: #$1 {en,ja,release.md} | pbcopy"
2020-12-20 13:02:30 -05:00
end
# Confirm current directory is www.ruby-lang.org's working directory
def confirm_w_r_l_o_wd
File.foreach('.git/config') do |line|
return true if line.include?('git@github.com:ruby/www.ruby-lang.org.git')
end
abort "Run this script in www.ruby-lang.org's working directory"
end
confirm_w_r_l_o_wd
releases = YAML.safe_load_file('_data/releases.yml', permitted_classes: [Date])
2020-12-20 13:02:30 -05:00
case lang
when "en", "ja"
url = "https://hackmd.io/@naruse/ruby-relnote-#{lang}/download"
src = URI(url).read
else # the path of the Release note in markdown is given
src = File.read(lang)
end
2020-12-20 13:02:30 -05:00
src.gsub!(/[ \t]+$/, "")
src.sub!(/(?<!\n)\z/, "\n")
src.sub!(/^breaks: false\n/, '')
if /^\{% assign release = site.data.releases \| where: "version", "([^"]+)" \| first %\}/ =~ src
version = $1
else
abort %[#{url} doesn't include `{% assign release = site.data.releases | where: "version", "<version>" | first %}`]
end
release = releases.find{|rel|rel['version'] == version}
unless release
abort "#{version} is not found in '_data/releases.yml'"
end
src.gsub!(/^{% assign .*\n/, '')
src.gsub!(/\{\{(.*?)\}\}/) do
var = $1.strip
case var
when /\Arelease\.(.*)/
val = release.dig(*$1.split('.'))
raise "invalid variable '#{var}'" unless val
else
raise "unknown variable '#{var}'"
end
val
end
puts src