Skip to content

Commit

Permalink
Move format-release to tool and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nurse committed Oct 22, 2019
1 parent 0407530 commit d736511
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 224 deletions.
197 changes: 0 additions & 197 deletions bin/format-release

This file was deleted.

46 changes: 19 additions & 27 deletions tool/format-release
@@ -1,23 +1,11 @@
#!/usr/bin/env ruby
#
# Tool to update w.r-l.o files on release
#
# This receives `make dist`'s output, and prints
#
# * links and digests of tarballs for releate article
# * patch for below data files
# * _data/branches.yml
# * _data/downloads.yml
# * _data/releases.yml
#
# To apply the patch, `patch -p1 < patch.txt`
# https://rubygems.org/gems/diffy
require "diffy"

Diffy::Diff.default_options.merge!(
include_diff_info: true,
context: 1,
)
WWW = Dir.pwd # workdir of https://github.com/ruby/www.ruby-lang.org

class Tarball
attr_reader :version, :sha256
Expand Down Expand Up @@ -49,7 +37,6 @@ class Tarball
SHA1: #{@sha1}
SHA256: #{@sha256}
SHA512: #{@sha512}
eom
end

Expand All @@ -58,10 +45,10 @@ eom
# SHA1: 21f62c369661a2ab1b521fd2fa8191a4273e12a1
# SHA256: 97cea8aa63dfa250ba6902b658a7aa066daf817b22f82b7ee28f44aec7c2e394
# SHA512: 1e2042324821bb4e110af7067f52891606dcfc71e640c194ab1c117f0b941550e0b3ac36ad3511214ac80c536b9e5cfaf8789eec74cf56971a832ea8fc4e6d94
def self.parse(io)
def self.parse(wwwdir, file)
ary = []
ver = nil
io.read.scan(/^\* .*(?:\n .*)*/) do |unit|
File.read(file).scan(/^\* .*(?:\n .*)*/) do |unit|
path, size, sha1, sha256, sha512 = unit.lines.map(&:chomp)
path.slice!(0, 2)
size = size[/\d+/].to_i
Expand All @@ -80,22 +67,22 @@ eom
ary.each do |tarball|
puts tarball.to_md
end
update_branches_yml(ver, xy)
update_downloads_yml(ver, xy)
update_releases_yml(ver, xy, ary)
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)
def self.update_branches_yml(ver, xy, wwwdir)
filename = "_data/branches.yml"
orig_data = File.read(File.join(WWW, filename))
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/, " date: #{Time.now.year}-12-25\n")
node.sub!(/^ date:\n/, " status: #{Time.now.year}-12-25\n")
end
node
end
Expand All @@ -122,9 +109,9 @@ eom
end
end

def self.update_downloads_yml(ver, xy)
def self.update_downloads_yml(ver, xy, wwwdir)
filename = "_data/downloads.yml"
orig_data = File.read(File.join(WWW, filename))
orig_data = File.read(File.join(wwwdir, filename))
data = orig_data.dup

if /^preview:\n\n(?: .*\n)* - #{Regexp.escape(xy)}\./ =~ data
Expand All @@ -149,9 +136,9 @@ eom
end
end

def self.update_releases_yml(ver, xy, ary)
def self.update_releases_yml(ver, xy, ary, wwwdir)
filename = "_data/releases.yml"
orig_data = File.read(File.join(WWW, filename))
orig_data = File.read(File.join(wwwdir, filename))
data = orig_data.dup

date = Time.now
Expand Down Expand Up @@ -200,6 +187,11 @@ eom
end

def main
Tarball.parse(ARGF)
if ARGV.size != 2
STDERR.puts "usage: format-release <dir-of-w.r-l.o> <output-of-make-snapshot>"
exit
end
Tarball.parse(ARGV[0], ARGV[1])
end

main

0 comments on commit d736511

Please sign in to comment.