Add examples for nginx and unicorn
[unicorn.git] / Rakefile
blob67534f2e08c2c5fc5a3e04d6bd85010bf8973a61
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"
36 git_url = ENV['GIT_URL'] || 'git://git.bogomips.org/unicorn.git'
38 desc 'prints news as an Atom feed'
39 task :news_atom do
40   require 'nokogiri'
41   new_tags = tags[0,10]
42   puts(Nokogiri::XML::Builder.new do
43     feed :xmlns => "http://www.w3.org/2005/Atom" do
44       id! "http://unicorn.bogomips.org/NEWS.atom.xml"
45       title "Unicorn news"
46       subtitle "Rack HTTP server for Unix and fast clients"
47       link! :rel => 'alternate', :type => 'text/html',
48             :href => 'http://unicorn.bogomips.org/NEWS.html'
49       updated new_tags.first[:time]
50       new_tags.each do |tag|
51         entry do
52           title tag[:subject]
53           updated tag[:time]
54           published tag[:time]
55           author {
56             name tag[:tagger_name]
57             email tag[:tagger_email]
58           }
59           url = "#{cgit_url}/tag/?id=#{tag[:tag]}"
60           link! :rel => "alternate", :type => "text/html", :href =>url
61           id! url
62           content({:type => 'text'}, tag[:body])
63         end
64       end
65     end
66   end.to_xml)
67 end
69 desc 'prints RDoc-formatted news'
70 task :news_rdoc do
71   tags.each do |tag|
72     time = tag[:time].tr!('T', ' ').gsub!(/:\d\dZ/, ' UTC')
73     puts "=== #{tag[:tag].sub(/^v/, '')} / #{time}"
74     puts ""
76     body = tag[:body]
77     puts tag[:body].gsub(/^/sm, "  ").gsub(/[ \t]+$/sm, "")
78     puts ""
79   end
80 end
82 desc "print release changelog for Rubyforge"
83 task :release_changes do
84   version = ENV['VERSION'] or abort "VERSION= needed"
85   version = "v#{version}"
86   vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
87   prev = vtags[vtags.index(version) - 1]
88   system('git', 'diff', '--stat', prev, version) or abort $?
89   puts ""
90   system('git', 'log', "#{prev}..#{version}") or abort $?
91 end
93 desc "print release notes for Rubyforge"
94 task :release_notes do
95   require 'rubygems'
97   spec = Gem::Specification.load('unicorn.gemspec')
98   puts spec.description.strip
99   puts ""
100   puts "* #{spec.homepage}"
101   puts "* #{spec.email}"
102   puts "* #{git_url}"
104   _, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
105   print "\nChanges:\n\n"
106   puts body
109 desc "post to RAA"
110 task :raa_update do
111   require 'rubygems'
112   require 'net/http'
113   require 'net/netrc'
114   rc = Net::Netrc.locate('unicorn-raa') or abort "~/.netrc not found"
115   password = rc.password
117   s = Gem::Specification.load('unicorn.gemspec')
118   desc = [ s.description.strip ]
119   desc << ""
120   desc << "* #{s.email}"
121   desc << "* #{git_url}"
122   desc << "* #{cgit_url}"
123   desc = desc.join("\n")
124   uri = URI.parse('http://raa.ruby-lang.org/regist.rhtml')
125   form = {
126     :name => s.name,
127     :short_description => s.summary,
128     :version => s.version.to_s,
129     :status => 'stable',
130     :owner => s.authors.first,
131     :email => s.email,
132     :category_major => 'Library',
133     :category_minor => 'Web',
134     :url => s.homepage,
135     :download => "http://rubyforge.org/frs/?group_id=1306",
136     :license => "Ruby's",
137     :description_style => 'Plain',
138     :description => desc,
139     :pass => password,
140     :submit => "Update",
141   }
142   res = Net::HTTP.post_form(uri, form)
143   p res
144   puts res.body