diff --git a/bin/format-release b/bin/format-release new file mode 100755 index 0000000000..7404ba2696 --- /dev/null +++ b/bin/format-release @@ -0,0 +1,197 @@ +#!/usr/bin/env ruby +# https://rubygems.org/gems/diffy +require "diffy" + +Diffy::Diff.default_options.merge!( + include_diff_info: true, + context: 1, +) + +class Tarball + attr_reader :version, :sha256 + + def initialize(path, size, sha1, sha256, sha512) + /\A\/(?:[^\/\n]*\/)*(?:ruby-(?(?\d+\.\d+)\.\d+(?:-(?:preview|rc)\d+)?)[0-9a-z.\-]+)/ =~ path \ + or raise "tarball path doesn't mach regexp" + @path = path + @size = size + @sha1 = sha1 + @sha256 = sha256 + @sha512 = sha512 + @version = ver + @xy = xy + end + + def gz?; @path.end_with?('.gz'); end + def zip?; @path.end_with?('.zip'); end + def bz2?; @path.end_with?('.bz2'); end + def xz?; @path.end_with?('.xz'); end + + def ext; @path[/(?:zip|tar\.(?:gz|bz2|xz))\z/]; end + + def to_md + < + + SIZE: #{@size} bytes + SHA1: #{@sha1} + SHA256: #{@sha256} + SHA512: #{@sha512} +eom + end + + # * /home/naruse/obj/ruby-trunk/tmp/ruby-2.6.0-preview3.tar.gz + # SIZE: 17116009 bytes + # SHA1: 21f62c369661a2ab1b521fd2fa8191a4273e12a1 + # SHA256: 97cea8aa63dfa250ba6902b658a7aa066daf817b22f82b7ee28f44aec7c2e394 + # SHA512: 1e2042324821bb4e110af7067f52891606dcfc71e640c194ab1c117f0b941550e0b3ac36ad3511214ac80c536b9e5cfaf8789eec74cf56971a832ea8fc4e6d94 + def self.parse(io, wwwdir) + ary = [] + ver = nil + io.read.scan(/^\* .*(?:\n .*)*/) do |unit| + path, size, sha1, sha256, sha512 = unit.lines.map(&:chomp) + path.slice!(0, 2) + size = size[/\d+/].to_i + sha1 = sha1[/\h{40}/] + sha256 = sha256[/\h{64}/] + sha512 = sha512[/\h{128}/] + tarball = Tarball.new(path, size, sha1, sha256, sha512) + if ver + raise "mixed versions" if tarball.version != ver + else + ver = tarball.version + end + ary << tarball + end + xy = ver[/\A\d+\.\d+/] + ary.each do |tarball| + puts tarball.to_md + end + update_branches_yml(ver, xy, wwwdir) + update_downloads_yml(ver, xy, wwwdir) + update_releases_yml(ver, xy, ary, wwwdir) + ary + end + + def self.update_branches_yml(ver, xy, wwwdir) + filename = "_data/branches.yml" + orig_data = File.read(File.join(wwwdir, filename)) + data = orig_data.dup + if data.include?("\n- name: #{xy}\n") + data.sub!(/\n- name: #{Regexp.escape(xy)}\n(?: .*\n)*/) do |node| + unless ver.include?("-") + # assume this is X.Y.0 release + node.sub!(/^ status: preview\n/, " status: normal maintenance\n") + node.sub!(/^ date:\n/, " status: #{Time.now.year}-12-25\n") + end + node + end + else + if ver.include?("-") + status = "preview" + year = nil + else + status = "normal maintenance" + year = Time.now.year + end + entry = <" + exit + end + Tarball.parse(ARGF, wwwdir) +end + +main