# Copyright (C) 2013, Eric Wong and all contributors # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) require 'tempfile' include Rake::DSL gendocs = %w(NEWS NEWS.atom.xml) task rsync_docs: gendocs do dest = ENV["RSYNC_DEST"] || "yahns.yhbt.net:/srv/yahns/" top = %w(INSTALL HACKING README COPYING) # git-set-file-times is distributed with rsync, # Also available at: http://yhbt.net/git-set-file-times # on Debian systems: /usr/share/doc/rsync/scripts/git-set-file-times.gz sh("git", "set-file-times", "Documentation", "examples", *top) do_gzip = lambda do |txt| gz = "#{txt}.gz" tmp = "#{gz}.#$$" sh("gzip --rsyncable -9 < #{txt} > #{tmp}") st = File.stat(txt) File.utime(st.atime, st.mtime, tmp) # make nginx gzip_static happy File.rename(tmp, gz) gz end files = `git ls-files Documentation/*.txt`.split(/\n/) files.concat(top) files.concat(gendocs) gzfiles = files.map { |txt| do_gzip.call(txt) } files.concat(gzfiles) sh("rsync --chmod=Fugo=r -av #{files.join(' ')} #{dest}") examples = `git ls-files examples`.split(/\n/) gzex = examples.map { |txt| do_gzip.call(txt) } examples.concat(gzex) sh("rsync --chmod=Fugo=r -av #{examples.join(' ')} #{dest}/examples/") end def tags timefmt = '%Y-%m-%dT%H:%M:%SZ' @tags ||= `git tag -l`.split(/\n/).map do |tag| if %r{\Av[\d\.]+} =~ tag header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3) header = header.split(/\n/) tagger = header.grep(/\Atagger /).first body ||= "initial" time = Time.at(tagger.split(/ /)[-2].to_i).utc { time_obj: time, time: time.strftime(timefmt), tagger_name: %r{^tagger ([^<]+)}.match(tagger)[1].strip, tagger_email: %r{<([^>]+)>}.match(tagger)[1].strip, id: `git rev-parse refs/tags/#{tag}`.chomp!, tag: tag, subject: subject, body: body, } end end.compact.sort { |a,b| b[:time] <=> a[:time] } end url_base = 'http://yahns.yhbt.net' cgit_url = 'http://yhbt.net/yahns.git' git_url = 'git://yhbt.net/yahns.git' since = "v0.0.2" desc 'prints news as an Atom feed' task "NEWS.atom.xml" do require 'nokogiri' new_tags = tags[0,10] time = nil str = Nokogiri::XML::Builder.new do feed :xmlns => "http://www.w3.org/2005/Atom" do id! "#{url_base}/NEWS.atom.xml" title "yahns news" subtitle "sleepy, multi-threaded, non-blocking Ruby application server" link! :rel => 'alternate', :type => 'text/plain', :href => "#{url_base}/NEWS" updated(new_tags.empty? ? "1970-01-01T00:00:00Z" : new_tags.first[:time]) new_tags.each do |tag| time ||= tag[:time_obj] entry do title tag[:subject] updated tag[:time] published tag[:time] author { name tag[:tagger_name] email tag[:tagger_email] } url = "#{cgit_url}/tag/?id=#{tag[:tag]}" link! :rel => "alternate", :type => "text/html", :href =>url id! url message_only = tag[:body].split(/\n.+\(\d+\):\n {6}/).first.strip content({:type =>:text}, message_only) content(:type =>:xhtml) { pre tag[:body] } end end end end.to_xml fp = Tempfile.new("NEWS.atom.xml", ".") fp.sync = true fp.write(str) fp.chmod 0644 File.utime(time, time, fp.path) if time File.rename(fp.path, "NEWS.atom.xml") fp.close! end desc 'prints news as a text file' task "NEWS" do fp = Tempfile.new("NEWS", ".") fp.sync = true time = nil tags.each do |tag| time ||= tag[:time_obj] line = tag[:subject] + " / " + tag[:time].gsub(/T.*/, '') fp.puts line fp.puts("-" * line.length) fp.puts fp.puts tag[:body] #.gsub(/^/m, " ").gsub(/[ \t]+$/m, "") fp.puts end fp.write("Unreleased\n\n") unless fp.size > 0 fp.puts "COPYRIGHT" fp.puts "---------" bdfl = 'Eric Wong ' fp.puts "Copyright (C) 2013, #{bdfl} and all contributors" fp.puts "License: GPLv3 or later (http://www.gnu.org/licenses/gpl-3.0.txt)" fp.chmod 0644 File.utime(time, time, fp.path) if time File.rename(fp.path, "NEWS") fp.close! end