README: note config.yml is lazily created
[local-openid.git] / Rakefile
blob3f4b240425b9678a9f8dadd1ff1b7d173f31ab44
1 # -*- encoding: binary -*-
2 autoload :Gem, 'rubygems'
4 def tags
5   timefmt = '%Y-%m-%dT%H:%M:%SZ'
6   @tags ||= `git tag -l`.split(/\n/).map do |tag|
7     if %r{\Av[\d\.]+\z} =~ tag
8       header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
9       header = header.split(/\n/)
10       tagger = header.grep(/\Atagger /).first
11       body ||= "initial"
12       {
13         :time => Time.at(tagger.split(/ /)[-2].to_i).utc.strftime(timefmt),
14         :tagger_name => %r{^tagger ([^<]+)}.match(tagger)[1].strip,
15         :tagger_email => %r{<([^>]+)>}.match(tagger)[1].strip,
16         :id => `git rev-parse refs/tags/#{tag}`.chomp!,
17         :tag => tag,
18         :subject => subject,
19         :body => body,
20       }
21     end
22   end.compact.sort { |a,b| b[:time] <=> a[:time] }
23 end
25 cgit_url = "http://git.bogomips.org/cgit/local-openid.git"
26 git_url = ENV['GIT_URL'] || 'git://git.bogomips.org/local-openid.git'
28 desc 'prints news as an Atom feed'
29 task :news_atom do
30   require 'nokogiri'
31   new_tags = tags[0,10]
32   puts(Nokogiri::XML::Builder.new do
33     feed :xmlns => "http://www.w3.org/2005/Atom" do
34       id! "http://bogomips.org/local-openid/NEWS.atom.xml"
35       title "local-openid news"
36       subtitle %q{Single User, Ephemeral OpenID Provider}
37       link! :rel => 'alternate', :type => 'text/html',
38             :href => 'http://bogomips.org/local-openid/NEWS.html'
39       updated(new_tags.empty? ? "1970-01-01T00:00:00Z" : new_tags.first[:time])
40       new_tags.each do |tag|
41         entry do
42           title tag[:subject]
43           updated tag[:time]
44           published tag[:time]
45           author {
46             name tag[:tagger_name]
47             email tag[:tagger_email]
48           }
49           url = "#{cgit_url}/tag/?id=#{tag[:tag]}"
50           link! :rel => "alternate", :type => "text/html", :href =>url
51           id! url
52           message_only = tag[:body].split(/\n.+\(\d+\):\n {6}/s).first.strip
53           content({:type =>:text}, message_only)
54           content(:type =>:xhtml) { pre tag[:body] }
55         end
56       end
57     end
58   end.to_xml)
59 end
61 desc 'prints RDoc-formatted news'
62 task :news_rdoc do
63   tags.each do |tag|
64     time = tag[:time].tr!('T', ' ').gsub!(/:\d\dZ/, ' UTC')
65     puts "=== #{tag[:tag].sub(/^v/, '')} / #{time}"
66     puts ""
68     body = tag[:body]
69     puts tag[:body].gsub(/^/sm, "  ").gsub(/[ \t]+$/sm, "")
70     puts ""
71   end
72 end
74 desc "print release changelog for Rubyforge"
75 task :release_changes do
76   version = ENV['VERSION'] or abort "VERSION= needed"
77   version = "v#{version}"
78   vtags = tags.map { |tag| tag[:tag] =~ /\Av/ and tag[:tag] }.sort
79   prev = vtags[vtags.index(version) - 1]
80   if prev
81     system('git', 'diff', '--stat', prev, version) or abort $?
82     puts ""
83     system('git', 'log', "#{prev}..#{version}") or abort $?
84   else
85     system('git', 'log', version) or abort $?
86   end
87 end
89 desc "print release notes for Rubyforge"
90 task :release_notes do
91   spec = Gem::Specification.load('local-openid.gemspec')
92   puts spec.description.strip
93   puts ""
94   puts "* #{spec.homepage}"
95   puts "* #{spec.email}"
96   puts "* #{git_url}"
98   _, _, body = `git cat-file tag v#{spec.version}`.split(/\n\n/, 3)
99   print "\nChanges:\n\n"
100   puts body
103 desc "read news article from STDIN and post to rubyforge"
104 task :publish_news do
105   require 'rubyforge'
106   IO.select([STDIN], nil, nil, 1) or abort "E: news must be read from stdin"
107   msg = STDIN.readlines
108   subject = msg.shift
109   blank = msg.shift
110   blank == "\n" or abort "no newline after subject!"
111   subject.strip!
112   body = msg.join("").strip!
114   rf = RubyForge.new.configure
115   rf.login
116   rf.post_news('qrp', subject, body)
119 desc "post to RAA"
120 task :raa_update do
121   require 'net/http'
122   require 'net/netrc'
123   rc = Net::Netrc.locate('local-openid-raa') or abort "~/.netrc not found"
124   password = rc.password
126   s = Gem::Specification.load('local-openid.gemspec')
127   desc = [ s.description.strip ]
128   desc << ""
129   desc << "* #{s.email}"
130   desc << "* #{git_url}"
131   desc << "* #{cgit_url}"
132   desc = desc.join("\n")
133   uri = URI.parse('http://raa.ruby-lang.org/regist.rhtml')
134   form = {
135     :name => s.name,
136     :short_description => s.summary,
137     :version => s.version.to_s,
138     :status => 'stable',
139     :owner => s.authors.first,
140     :email => s.email,
141     :category_major => 'Application',
142     :category_minor => 'WWW',
143     :url => s.homepage,
144     :download => 'http://rubyforge.org/frs/?group_id=5626',
145     :license => "OpenSource", # AGPLv3, specifically
146     :description_style => 'Plain',
147     :description => desc,
148     :pass => password,
149     :submit => "Update",
150   }
151   res = Net::HTTP.post_form(uri, form)
152   p res
153   puts res.body
156 desc "post to FM"
157 task :fm_update do
158   require 'tempfile'
159   require 'net/http'
160   require 'net/netrc'
161   require 'json'
162   version = ENV['VERSION'] or abort "VERSION= needed"
163   uri = URI.parse('http://freshmeat.net/projects/local-openid/releases.json')
164   rc = Net::Netrc.locate('local-openid-fm') or abort "~/.netrc not found"
165   api_token = rc.password
166   changelog = tags.find { |t| t[:tag] == "v#{version}" }[:body]
167   tmp = Tempfile.new('fm-changelog')
168   tmp.syswrite(changelog)
169   system(ENV["VISUAL"], tmp.path) or abort "#{ENV["VISUAL"]} failed: #$?"
170   changelog = File.read(tmp.path).strip
172   req = {
173     "auth_code" => api_token,
174     "release" => {
175       "tag_list" => "Stable",
176       "version" => version,
177       "changelog" => changelog,
178     },
179   }.to_json
180   Net::HTTP.start(uri.host, uri.port) do |http|
181     p http.post(uri.path, req, {'Content-Type'=>'application/json'})
182   end