# Copyright (C) 2013-2016 all contributors # License: GPL-3.0+ (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"] || "yhbt.net:/srv/yhbt/yahns/" top = %w(INSTALL HACKING README COPYING) # git-set-file-times is distributed with rsync, # Also available at: https://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) make = ENV['MAKE'] || 'make' sh(%Q(#{make} -C Documentation)) 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) files.concat(%w(yahns yahns-rackup yahns_config).map! { |x| "Documentation/#{x}.txt" }) 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 desc 'prints news as an Atom feed' task "NEWS.atom.xml" do # gem install 'olddoc', 'olddoc prepare' has no API besides the # command-line. This requires olddoc 1.1 or later. system('olddoc', 'prepare') or abort "olddoc prepare failed #$?" end desc 'prints news as a text file' task 'NEWS' => 'NEWS.atom.xml'