simplify examples for 1.0.0 API
[ruby_io_splice.git] / Rakefile
blob3f35fa3414f83e040d0962352839ccfd9493f83c
1 # -*- encoding: binary -*-
3 # most tasks are in the GNUmakefile which offers better parallelism
5 def tags
6   timefmt = '%Y-%m-%dT%H:%M:%SZ'
7   @tags ||= `git tag -l`.split(/\n/).map do |tag|
8     if %r{\Av[\d\.]+\z} =~ tag
9       header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
10       header = header.split(/\n/)
11       tagger = header.grep(/\Atagger /).first
12       body ||= "initial"
13       {
14         :time => Time.at(tagger.split(/ /)[-2].to_i).utc.strftime(timefmt),
15         :tagger_name => %r{^tagger ([^<]+)}.match(tagger)[1].strip,
16         :tagger_email => %r{<([^>]+)>}.match(tagger)[1].strip,
17         :id => `git rev-parse refs/tags/#{tag}`.chomp!,
18         :tag => tag,
19         :subject => subject,
20         :body => body,
21       }
22     end
23   end.compact.sort { |a,b| b[:time] <=> a[:time] }
24 end
26 cgit_url = "http://git.bogomips.org/cgit/ruby_io_splice.git"
27 git_url = ENV['GIT_URL'] || 'git://git.bogomips.org/ruby_io_splice.git'
28 web_url = "http://bogomips.org/ruby_io_splice/"
30 desc 'prints news as an Atom feed'
31 task :news_atom do
32   require 'nokogiri'
33   new_tags = tags[0,10]
34   puts(Nokogiri::XML::Builder.new do
35     feed :xmlns => "http://www.w3.org/2005/Atom" do
36       id! "#{web_url}NEWS.atom.xml"
37       title "Ruby io_splice news"
38       subtitle "splice and tee Linux syscalls from Ruby"
39       link! :rel => "alternate", :type => "text/html",
40             :href => "#{web_url}NEWS.html"
41       updated(new_tags.empty? ? "1970-01-01T00:00:00Z" : new_tags.first[:time])
42       new_tags.each do |tag|
43         entry do
44           title tag[:subject]
45           updated tag[:time]
46           published tag[:time]
47           author {
48             name tag[:tagger_name]
49             email tag[:tagger_email]
50           }
51           url = "#{cgit_url}/tag/?id=#{tag[:tag]}"
52           link! :rel => "alternate", :type => "text/html", :href =>url
53           id! url
54           message_only = tag[:body].split(/\n.+\(\d+\):\n {6}/s).first.strip
55           content({:type =>:text}, message_only)
56           content(:type =>:xhtml) { pre tag[:body] }
57         end
58       end
59     end
60   end.to_xml)
61 end
63 desc 'prints RDoc-formatted news'
64 task :news_rdoc do
65   tags.each do |tag|
66     time = tag[:time].tr!('T', ' ').gsub!(/:\d\dZ/, ' UTC')
67     puts "=== #{tag[:tag].sub(/^v/, '')} / #{time}"
68     puts ""
70     body = tag[:body]
71     puts tag[:body].gsub(/^/sm, "  ").gsub(/[ \t]+$/sm, "")
72     puts ""
73   end
74 end
76 desc "print release changelog for Rubyforge"
77 task :release_changes do
78   version = ENV['VERSION'] or abort "VERSION= needed"
79   version = "v#{version}"
80   vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
81   prev = vtags[vtags.index(version) - 1]
82   if prev
83     system('git', 'diff', '--stat', prev, version) or abort $?
84     puts ""
85     system('git', 'log', "#{prev}..#{version}") or abort $?
86   else
87     system('git', 'log', version) or abort $?
88   end
89 end
91 desc "print release notes for Rubyforge"
92 task :release_notes do
93   spec = Gem::Specification.load('io_splice.gemspec')
94   puts spec.description.strip
95   puts ""
96   puts "* #{spec.homepage}"
97   puts "* #{spec.email}"
98   puts "* #{git_url}"
100   _, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
101   print "\nChanges:\n\n"
102   puts body
105 desc "read news article from STDIN and post to rubyforge"
106 task :publish_news do
107   require 'rubyforge'
108   IO.select([STDIN], nil, nil, 1) or abort "E: news must be read from stdin"
109   msg = STDIN.readlines
110   subject = msg.shift
111   blank = msg.shift
112   blank == "\n" or abort "no newline after subject!"
113   subject.strip!
114   body = msg.join("").strip!
116   rf = RubyForge.new.configure
117   rf.login
118   rf.post_news('qrp', subject, body)
121 desc "post to RAA"
122 task :raa_update do
123   require 'net/http'
124   require 'net/netrc'
125   rc = Net::Netrc.locate('io_splice-raa') or abort "~/.netrc not found"
126   password = rc.password
128   s = Gem::Specification.load('io_splice.gemspec')
129   desc = [ s.description.strip ]
130   desc << ""
131   desc << "* #{s.email}"
132   desc << "* #{git_url}"
133   desc << "* #{cgit_url}"
134   desc = desc.join("\n")
135   uri = URI.parse('http://raa.ruby-lang.org/regist.rhtml')
136   form = {
137     :name => s.name,
138     :short_description => s.summary,
139     :version => s.version.to_s,
140     :status => 'experimental',
141     :owner => s.authors.first,
142     :email => s.email,
143     :category_major => 'Library',
144     :category_minor => 'System',
145     :url => s.homepage,
146     :download => 'http://rubyforge.org/frs/?group_id=5626',
147     :license => 'LGPL', # LGPLv3, actually, but RAA is ancient...
148     :description_style => 'Plain',
149     :description => desc,
150     :pass => password,
151     :submit => 'Update',
152   }
153   res = Net::HTTP.post_form(uri, form)
154   p res
155   puts res.body