cleanup: avoid redundant error checks for fstat
[unicorn.git] / Rakefile
blob2d4386aa0722cd41f0bb4d0300f93ef30efd1233
1 # -*- encoding: binary -*-
3 # most tasks are in the GNUmakefile which offers better parallelism
5 def old_summaries
6   @old_summaries ||= File.readlines(".CHANGELOG.old").inject({}) do |hash, line|
7     version, summary = line.split(/ - /, 2)
8     hash[version] = summary
9     hash
10   end
11 end
13 def tags
14   timefmt = '%Y-%m-%dT%H:%M:%SZ'
15   @tags ||= `git tag -l`.split(/\n/).map do |tag|
16     next if tag == "v0.0.0"
17     if %r{\Av[\d\.]+\z} =~ tag
18       header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
19       header = header.split(/\n/)
20       tagger = header.grep(/\Atagger /).first
21       body ||= "initial"
22       {
23         :time => Time.at(tagger.split(/ /)[-2].to_i).utc.strftime(timefmt),
24         :tagger_name => %r{^tagger ([^<]+)}.match(tagger)[1].strip,
25         :tagger_email => %r{<([^>]+)>}.match(tagger)[1].strip,
26         :id => `git rev-parse refs/tags/#{tag}`.chomp!,
27         :tag => tag,
28         :subject => subject,
29         :body => (old = old_summaries[tag]) ? "#{old}\n#{body}" : body,
30       }
31     end
32   end.compact.sort { |a,b| b[:time] <=> a[:time] }
33 end
35 cgit_url = "http://git.bogomips.org/cgit/unicorn.git"
37 desc 'prints news as an Atom feed'
38 task :news_atom do
39   require 'nokogiri'
40   new_tags = tags[0,10]
41   puts(Nokogiri::XML::Builder.new do
42     feed :xmlns => "http://www.w3.org/2005/Atom" do
43       id! "http://unicorn.bogomips.org/NEWS.atom.xml"
44       title "Unicorn news"
45       subtitle "Rack HTTP server for Unix and fast clients"
46       link! :rel => 'alternate', :type => 'text/html',
47             :href => 'http://unicorn.bogomips.org/NEWS.html'
48       updated new_tags.first[:time]
49       new_tags.each do |tag|
50         entry do
51           title tag[:subject]
52           updated tag[:time]
53           published tag[:time]
54           author {
55             name tag[:tagger_name]
56             email tag[:tagger_email]
57           }
58           url = "#{cgit_url}/tag/?id=#{tag[:tag]}"
59           link! :rel => "alternate", :type => "text/html", :href =>url
60           id! url
61           content({:type => 'text'}, tag[:body])
62         end
63       end
64     end
65   end.to_xml)
66 end
68 desc 'prints RDoc-formatted news'
69 task :news_rdoc do
70   tags.each do |tag|
71     time = tag[:time].tr!('T', ' ').gsub!(/:\d\dZ/, ' UTC')
72     puts "=== #{tag[:tag].sub(/^v/, '')} / #{time}"
73     puts ""
75     body = tag[:body]
76     puts tag[:body].gsub(/^/sm, "  ").gsub(/[ \t]+$/sm, "")
77     puts ""
78   end
79 end
81 desc "print release changelog for Rubyforge"
82 task :release_changes do
83   version = ENV['VERSION'] or abort "VERSION= needed"
84   version = "v#{version}"
85   vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
86   prev = vtags[vtags.index(version) - 1]
87   system('git', 'diff', '--stat', prev, version) or abort $?
88   puts ""
89   system('git', 'log', "#{prev}..#{version}") or abort $?
90 end
92 desc "print release notes for Rubyforge"
93 task :release_notes do
94   require 'rubygems'
96   git_url = ENV['GIT_URL'] || 'git://git.bogomips.org/unicorn.git'
98   spec = Gem::Specification.load('unicorn.gemspec')
99   puts spec.description.strip
100   puts ""
101   puts "* #{spec.homepage}"
102   puts "* #{spec.email}"
103   puts "* #{git_url}"
105   _, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
106   print "\nChanges:\n\n"
107   puts body