about summary refs log tree commit homepage
path: root/Rakefile
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-11-07 00:27:15 +0000
committerEric Wong <normalperson@yhbt.net>2013-11-07 00:27:15 +0000
commit9dedbd699476bed21ee36e8eb479f838b25abffa (patch)
tree4d659bcf0df043b47aea292984e988984e72c53c /Rakefile
parent6fbfd207d5ccb71bd764cc890170f2042305e49e (diff)
downloadyahns-9dedbd699476bed21ee36e8eb479f838b25abffa.tar.gz
This should hopefully make it easier to share info about
new releases.
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile152
1 files changed, 114 insertions, 38 deletions
diff --git a/Rakefile b/Rakefile
index 708a0f1..899a446 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,59 +2,135 @@
 # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
 require 'tempfile'
 include Rake::DSL
-task "NEWS" do
-  latest = nil
-  fp = Tempfile.new("NEWS", ".")
-  fp.sync = true
-  `git tag -l`.split(/\n/).reverse.each do |tag|
-    %r{\Av(.+)} =~ tag or next
-    version = $1
-    header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
-    header = header.split(/\n/)
-    tagger = header.grep(/\Atagger /)[0]
-    time = Time.at(tagger.split(/ /)[-2].to_i).utc
-    latest ||= time
-    date = time.strftime("%Y-%m-%d")
-    fp.puts "# #{version} / #{date}\n\n#{subject}"
-    if body && body.strip.size > 0
-      fp.puts "\n\n#{body}"
-    end
-    fp.puts
-  end
-  fp.write("Unreleased\n\n") unless fp.size > 0
-  fp.puts "# COPYRIGHT"
-  bdfl = 'Eric Wong <normalperson@yhbt.net>'
-  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.rewind
-  assert_equal fp.read, File.read("NEWS") rescue nil
-  fp.chmod 0644
-  File.rename(fp.path, "NEWS")
-  fp.close!
-end
 
-task rsync_docs: "NEWS" do
+gendocs = %w(NEWS NEWS.atom.xml)
+task rsync_docs: gendocs do
   dest = ENV["RSYNC_DEST"] || "yahns.yhbt.net:/srv/yahns/"
-  top = %w(INSTALL HACKING NEWS README COPYING)
-  files = []
+  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)
 
-  `git ls-files Documentation/*.txt`.split(/\n/).concat(top).each do |txt|
+  do_gzip = lambda do |txt|
     gz = "#{txt}.gz"
     tmp = "#{gz}.#$$"
-    sh("gzip -9 < #{txt} > #{tmp}")
+    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)
-    files << txt
-    files << 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")
+  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 <normalperson@yhbt.net>'
+  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