Skip to content

Instantly share code, notes, and snippets.

@refriedchicken
Created September 2, 2010 17:33
Show Gist options
  • Save refriedchicken/562597 to your computer and use it in GitHub Desktop.
Save refriedchicken/562597 to your computer and use it in GitHub Desktop.
require(File.join(File.dirname(__FILE__), '../../../../../', "config", "boot"))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
# require 'tasks/rails'
# Gives us the ability to remove the default rake tasks before overriding
# them with our own commands
Rake::TaskManager.class_eval do
def remove_task(task_name)
@tasks.delete(task_name.to_s)
end
end
task :ci => ["ci:before", "ci:db:prepare", "ci:install_gems", "ci:db:before", "ci:run", "ci:db:after", "ci:after"]
namespace :ci do
desc "Commands to run before Cruise runs"
task :before
desc "Commands to run after Cruise runs"
task :after
desc "Install required gems"
task :install_gems do
if Rake::Task.task_defined?("gems:install")
Rake::Task["gems:install"].invoke
end
end
desc "The commands to 'build' your application"
task :run do
Rake::Task["spec"].invoke if Rake::Task.task_defined?("spec")
Rake::Task["cucumber:ok"].invoke if Rake::Task.task_defined?("cucumber:ok")
Rake::Task["ci:metrics:all"].invoke if Rake::Task.task_defined?("metrics:all")
end
desc "Runs metric_fu metrics, graphs them and saves output using CC_BUILD_ARTIFACTS (RAILS_ROOT/../metrics) path"
task :metrics do
require 'metric_fu'
MetricFu::Configuration.run do |config|
config.metrics = [:churn, :stats, :flog, :flay, :reek, :roodi]
config.graphs = [:flog, :flay, :reek, :roodi]
config.flay = { :dirs_to_flay => ['app', 'lib'] }
config.flog = { :dirs_to_flog => ['app', 'lib'] }
config.reek = { :dirs_to_reek => ['app', 'lib'] }
config.roodi = { :dirs_to_roodi => ['app', 'lib'] }
config.churn = { :start_date => "1 year ago", :minimum_churn_count => 10}
end
Rake::Task["metrics:all"].invoke
end
namespace :db do
desc "copy the database.yml file to config"
task :prepare do
# we are in vendor/plugins/integrum_ci/tasks so go up
template_database_yml = '/var/lib/hudson/templates/database.yml.template'
data = File.open(template_database_yml, 'r').read
appname = File.basename(File.dirname(RAILS_ROOT))
data = data.gsub(/APPNAME/,appname)
working_database_yml = File.join(RAILS_ROOT, "config", "database.yml")
File.open(working_database_yml, 'w') do |fp|
fp << data
end
end
desc "Commands to prepare database for cruise"
task :before do
Rake::Task["db:create:all"].invoke
if File.exist?(File.join(RAILS_ROOT, "db", "schema.rb"))
Rake::Task["db:test:load"].invoke
else
Rake::Task["db:migrate:reset"].invoke
Rake::Task["db:test:prepare"].invoke
end
end
desc "Commands to teardown database after cruise"
task :after do
begin
Rake::Task["db:drop:all"].invoke
rescue
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment