Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 13
- Log:
Initial import of Typo 2.6.0 sources from a downloaded Tarball.
Typo is a Ruby On Rails based blog engine.
- Author:
- adh
- Date:
- Sat Jul 22 22:25:02 +0100 2006
- Size:
- 13422 Bytes
1 | require 'rake' |
2 | require 'rake/testtask' |
3 | require 'rake/rdoctask' |
4 | require 'rake/gempackagetask' |
5 | require 'rake/contrib/rubyforgepublisher' |
6 | |
7 | PKG_VERSION = "2.6.0" |
8 | PKG_NAME = "typo" |
9 | PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" |
10 | RUBY_FORGE_PROJECT = 'typo' |
11 | RUBY_FORGE_USER = 'scottlaird' |
12 | RELEASE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" |
13 | |
14 | $VERBOSE = nil |
15 | TEST_CHANGES_SINCE = Time.now - 600 |
16 | |
17 | desc "Run all the tests on a fresh test database" |
18 | task :default => [ :test_units, :test_functional ] |
19 | |
20 | |
21 | desc 'Require application environment.' |
22 | task :environment do |
23 | unless defined? RAILS_ROOT |
24 | require File.dirname(__FILE__) + '/config/environment' |
25 | end |
26 | end |
27 | |
28 | desc "Generate API documentation, show coding stats" |
29 | task :doc => [ :appdoc, :stats ] |
30 | |
31 | |
32 | # Look up tests for recently modified sources. |
33 | def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) |
34 | FileList[source_pattern].map do |path| |
35 | if File.mtime(path) > touched_since |
36 | test = "#{test_path}/#{File.basename(path, '.rb')}_test.rb" |
37 | test if File.exists?(test) |
38 | end |
39 | end.compact |
40 | end |
41 | |
42 | desc 'Test recent changes.' |
43 | Rake::TestTask.new(:recent => [ :clone_structure_to_test ]) do |t| |
44 | since = TEST_CHANGES_SINCE |
45 | touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + |
46 | recent_tests('app/models/*.rb', 'test/unit', since) + |
47 | recent_tests('app/controllers/*.rb', 'test/functional', since) |
48 | |
49 | t.libs << 'test' |
50 | t.verbose = false |
51 | t.test_files = touched.uniq |
52 | end |
53 | task :test_recent => [ :clone_structure_to_test ] |
54 | |
55 | desc "Run the unit tests in test/unit" |
56 | Rake::TestTask.new("test_units") { |t| |
57 | t.libs << "test" |
58 | t.pattern = 'test/unit/**/*_test.rb' |
59 | t.verbose = false |
60 | } |
61 | task :test_units => [ :clone_structure_to_test ] |
62 | |
63 | desc "Run the functional tests in test/functional" |
64 | Rake::TestTask.new("test_functional") { |t| |
65 | t.libs << "test" |
66 | t.pattern = 'test/functional/**/*_test.rb' |
67 | t.verbose = false |
68 | } |
69 | task :test_functional => [ :clone_structure_to_test ] |
70 | |
71 | desc "Generate documentation for the application" |
72 | Rake::RDocTask.new("appdoc") { |rdoc| |
73 | rdoc.rdoc_dir = 'doc/app' |
74 | rdoc.title = "Rails Application Documentation" |
75 | rdoc.options << '--line-numbers --inline-source' |
76 | rdoc.rdoc_files.include('doc/README_FOR_APP') |
77 | rdoc.rdoc_files.include('app/**/*.rb') |
78 | } |
79 | |
80 | desc "Generate documentation for the Rails framework" |
81 | Rake::RDocTask.new("apidoc") { |rdoc| |
82 | rdoc.rdoc_dir = 'doc/api' |
83 | rdoc.template = "#{ENV['template']}.rb" if ENV['template'] |
84 | rdoc.title = "Rails Framework Documentation" |
85 | rdoc.options << '--line-numbers --inline-source' |
86 | rdoc.rdoc_files.include('README') |
87 | rdoc.rdoc_files.include('CHANGELOG') |
88 | rdoc.rdoc_files.include('vendor/rails/railties/CHANGELOG') |
89 | rdoc.rdoc_files.include('vendor/rails/railties/MIT-LICENSE') |
90 | rdoc.rdoc_files.include('vendor/rails/activerecord/README') |
91 | rdoc.rdoc_files.include('vendor/rails/activerecord/CHANGELOG') |
92 | rdoc.rdoc_files.include('vendor/rails/activerecord/lib/active_record/**/*.rb') |
93 | rdoc.rdoc_files.exclude('vendor/rails/activerecord/lib/active_record/vendor/*') |
94 | rdoc.rdoc_files.include('vendor/rails/actionpack/README') |
95 | rdoc.rdoc_files.include('vendor/rails/actionpack/CHANGELOG') |
96 | rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_controller/**/*.rb') |
97 | rdoc.rdoc_files.include('vendor/rails/actionpack/lib/action_view/**/*.rb') |
98 | rdoc.rdoc_files.include('vendor/rails/actionmailer/README') |
99 | rdoc.rdoc_files.include('vendor/rails/actionmailer/CHANGELOG') |
100 | rdoc.rdoc_files.include('vendor/rails/actionmailer/lib/action_mailer/base.rb') |
101 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/README') |
102 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/CHANGELOG') |
103 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service.rb') |
104 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/*.rb') |
105 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/api/*.rb') |
106 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/client/*.rb') |
107 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/container/*.rb') |
108 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/dispatcher/*.rb') |
109 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/protocol/*.rb') |
110 | rdoc.rdoc_files.include('vendor/rails/actionwebservice/lib/action_web_service/support/*.rb') |
111 | rdoc.rdoc_files.include('vendor/rails/activesupport/README') |
112 | rdoc.rdoc_files.include('vendor/rails/activesupport/CHANGELOG') |
113 | rdoc.rdoc_files.include('vendor/rails/activesupport/lib/active_support/**/*.rb') |
114 | } |
115 | |
116 | desc "Report code statistics (KLOCs, etc) from the application" |
117 | task :stats => [ :environment ] do |
118 | require 'code_statistics' |
119 | CodeStatistics.new( |
120 | ["Helpers", "app/helpers"], |
121 | ["Controllers", "app/controllers"], |
122 | ["APIs", "app/apis"], |
123 | ["Components", "components"], |
124 | ["Functionals", "test/functional"], |
125 | ["Models", "app/models"], |
126 | ["Units", "test/unit"] |
127 | ).to_s |
128 | end |
129 | |
130 | desc "Recreate the test databases from the development structure" |
131 | task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do |
132 | abcs = ActiveRecord::Base.configurations |
133 | case abcs["test"]["adapter"] |
134 | when "mysql" |
135 | ActiveRecord::Base.establish_connection(:test) |
136 | ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') |
137 | IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| |
138 | ActiveRecord::Base.connection.execute(table) |
139 | end |
140 | when "postgresql" |
141 | ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] |
142 | ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] |
143 | ENV['PGPASSWORD'] = abcs["test"]["password"] |
144 | `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}` |
145 | when "sqlite", "sqlite3" |
146 | `#{abcs[RAILS_ENV]["adapter"]} #{abcs["test"]["dbfile"]} < db/#{RAILS_ENV}_structure.sql` |
147 | else |
148 | raise "Unknown database adapter '#{abcs["test"]["adapter"]}'" |
149 | end |
150 | end |
151 | |
152 | desc "Dump the database structure to a SQL file" |
153 | task :db_structure_dump => :environment do |
154 | abcs = ActiveRecord::Base.configurations |
155 | case abcs[RAILS_ENV]["adapter"] |
156 | when "mysql" |
157 | ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) |
158 | File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } |
159 | when "postgresql" |
160 | ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"] |
161 | ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"] |
162 | ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"] |
163 | `pg_dump -U "#{abcs[RAILS_ENV]["username"]}" -s -x -f db/#{RAILS_ENV}_structure.sql #{abcs[RAILS_ENV]["database"]}` |
164 | when "sqlite", "sqlite3" |
165 | `#{abcs[RAILS_ENV]["adapter"]} #{abcs[RAILS_ENV]["dbfile"]} .schema > db/#{RAILS_ENV}_structure.sql` |
166 | else |
167 | raise "Unknown database adapter '#{abcs["test"]["adapter"]}'" |
168 | end |
169 | end |
170 | |
171 | desc "Empty the test database" |
172 | task :purge_test_database => :environment do |
173 | abcs = ActiveRecord::Base.configurations |
174 | case abcs["test"]["adapter"] |
175 | when "mysql" |
176 | ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) |
177 | ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"]) |
178 | when "postgresql" |
179 | ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] |
180 | ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] |
181 | ENV['PGPASSWORD'] = abcs["test"]["password"] |
182 | `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` |
183 | `createdb -T template0 -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` |
184 | when "sqlite","sqlite3" |
185 | File.delete(abcs["test"]["dbfile"]) if File.exist?(abcs["test"]["dbfile"]) |
186 | else |
187 | raise "Unknown database adapter '#{abcs["test"]["adapter"]}'" |
188 | end |
189 | end |
190 | |
191 | |
192 | spec = Gem::Specification.new do |s| |
193 | s.name = PKG_NAME |
194 | s.version = PKG_VERSION |
195 | s.summary = "Modern weblog engine." |
196 | s.has_rdoc = false |
197 | s.files = Dir.glob('**/*', File::FNM_DOTMATCH).reject do |f| |
198 | [ /\.$/, /sqlite$/, /\.log$/, /^pkg/, /\.svn/, /^vendor\/rails/, |
199 | /^public\/(files|xml|articles|pages|index.html)/, |
200 | /^public\/(stylesheets|javascripts|images)\/theme/, /\~$/, |
201 | /\/\._/, /\/#/ ].any? {|regex| f =~ regex } |
202 | end |
203 | s.require_path = '.' |
204 | s.author = "Tobias Luetke" |
205 | s.email = "tobi@leetsoft.com" |
206 | s.homepage = "http://typo.leetsoft.com" |
207 | s.rubyforge_project = "typo" |
208 | end |
209 | |
210 | Rake::GemPackageTask.new(spec) do |p| |
211 | p.gem_spec = spec |
212 | p.need_tar = true |
213 | p.need_zip = true |
214 | end |
215 | |
216 | desc "Migrate the database according to the migrate scripts in db/migrate (only supported on PG/MySQL). A specific version can be targetted with VERSION=x" |
217 | task :migrate => :environment do |
218 | ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/db/migrate/', ENV["VERSION"] ? ENV["VERSION"].to_i : nil) |
219 | end |
220 | |
221 | desc "Force a sweeping run of typo's static page caches (all of them!)" |
222 | task :sweep_cache => :environment do |
223 | PageCache.sweep_all |
224 | puts "Cache swept." |
225 | end |
226 | |
227 | desc "Publish the zip/tgz" |
228 | task :leetsoft_upload => [:package] do |
229 | Rake::SshFilePublisher.new("leetsoft.com", "dist/pkg", "pkg", "#{PKG_FILE_NAME}.zip").upload |
230 | Rake::SshFilePublisher.new("leetsoft.com", "dist/pkg", "pkg", "#{PKG_FILE_NAME}.tgz").upload |
231 | end |
232 | |
233 | desc "Publish the release files to RubyForge." |
234 | task :tag_svn do |
235 | system("svn cp svn://leetsoft.com/typo/trunk svn://leetsoft.com/typo/tags/release_#{PKG_VERSION.gsub(/\./,'_')} -m 'tag release #{PKG_VERSION}'") |
236 | end |
237 | |
238 | desc "Publish the release files to RubyForge." |
239 | task :rubyforge_upload => [:package] do |
240 | files = ["tgz", "zip"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" } |
241 | |
242 | if RUBY_FORGE_PROJECT then |
243 | require 'net/http' |
244 | require 'open-uri' |
245 | |
246 | project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/" |
247 | project_data = open(project_uri) { |data| data.read } |
248 | group_id = project_data[/[?&]group_id=(\d+)/, 1] |
249 | raise "Couldn't get group id" unless group_id |
250 | |
251 | # This echos password to shell which is a bit sucky |
252 | if ENV["RUBY_FORGE_PASSWORD"] |
253 | password = ENV["RUBY_FORGE_PASSWORD"] |
254 | else |
255 | print "#{RUBY_FORGE_USER}@rubyforge.org's password: " |
256 | password = STDIN.gets.chomp |
257 | end |
258 | |
259 | login_response = Net::HTTP.start("rubyforge.org", 80) do |http| |
260 | data = [ |
261 | "login=1", |
262 | "form_loginname=#{RUBY_FORGE_USER}", |
263 | "form_pw=#{password}" |
264 | ].join("&") |
265 | http.post("/account/login.php", data) |
266 | end |
267 | |
268 | cookie = login_response["set-cookie"] |
269 | raise "Login failed" unless cookie |
270 | headers = { "Cookie" => cookie } |
271 | |
272 | release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}" |
273 | release_data = open(release_uri, headers) { |data| data.read } |
274 | package_id = release_data[/[?&]package_id=(\d+)/, 1] |
275 | raise "Couldn't get package id" unless package_id |
276 | |
277 | first_file = true |
278 | release_id = "" |
279 | |
280 | files.each do |filename| |
281 | basename = File.basename(filename) |
282 | file_ext = File.extname(filename) |
283 | file_data = File.open(filename, "rb") { |file| file.read } |
284 | |
285 | puts "Releasing #{basename}..." |
286 | |
287 | release_response = Net::HTTP.start("rubyforge.org", 80) do |http| |
288 | release_date = Time.now.strftime("%Y-%m-%d %H:%M") |
289 | type_map = { |
290 | ".zip" => "3000", |
291 | ".tgz" => "3110", |
292 | ".gz" => "3110", |
293 | ".gem" => "1400" |
294 | }; type_map.default = "9999" |
295 | type = type_map[file_ext] |
296 | boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor" |
297 | |
298 | query_hash = if first_file then |
299 | { |
300 | "group_id" => group_id, |
301 | "package_id" => package_id, |
302 | "release_name" => RELEASE_NAME, |
303 | "release_date" => release_date, |
304 | "type_id" => type, |
305 | "processor_id" => "8000", # Any |
306 | "release_notes" => "", |
307 | "release_changes" => "", |
308 | "preformatted" => "1", |
309 | "submit" => "1" |
310 | } |
311 | else |
312 | { |
313 | "group_id" => group_id, |
314 | "release_id" => release_id, |
315 | "package_id" => package_id, |
316 | "step2" => "1", |
317 | "type_id" => type, |
318 | "processor_id" => "8000", # Any |
319 | "submit" => "Add This File" |
320 | } |
321 | end |
322 | |
323 | query = "?" + query_hash.map do |(name, value)| |
324 | [name, URI.encode(value)].join("=") |
325 | end.join("&") |
326 | |
327 | data = [ |
328 | "--" + boundary, |
329 | "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"", |
330 | "Content-Type: application/octet-stream", |
331 | "Content-Transfer-Encoding: binary", |
332 | "", file_data, "" |
333 | ].join("\x0D\x0A") |
334 | |
335 | release_headers = headers.merge( |
336 | "Content-Type" => "multipart/form-data; boundary=#{boundary}" |
337 | ) |
338 | |
339 | target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php" |
340 | http.post(target + query, data, release_headers) |
341 | end |
342 | |
343 | STDERR.puts "** release: #{release_response.body}" |
344 | |
345 | if first_file then |
346 | release_id = release_response.body[/release_id=(\d+)/, 1] |
347 | raise("Couldn't get release id") unless release_id |
348 | end |
349 | |
350 | first_file = false |
351 | end |
352 | end |
353 | end |
354 | |
355 | desc "Upload the package to leetsoft, rubyforge and tag the release in svn" |
356 | task :release => [:package, :rubyforge_upload, :tag_svn ] |