Posts Tagged ‘rake’

rake task to generate CHANGELOG file (for git repositories)

generate (or update) a CHANGELOG file for git repositories (shamelessly copied from manveru/ramaze).

desc 'update changelog'
task :changelog do
  File.open('CHANGELOG', 'w+') do |changelog|
    `git log -z --abbrev-commit`.split("\0").each do |commit|
      next if commit =~ /^Merge: \d*/
      ref, author, time, _, title, _, message = commit.split("\n", 7)
      ref = ref[/commit ([0-9a-f]+)/, 1]
      author = author[/Author: (.*)/, 1].strip
      time = Time.parse(time[/Date: (.*)/, 1]).utc
      title.strip!

      changelog.puts "[#{ref} | #{time}] #{author}"
      changelog.puts '', " * #{title}"
      changelog.puts '', message.rstrip if message
      changelog.puts
    end
  end
end

strip whitespace using rake

This snippet is taken from the wonderful webrat library

desc 'Removes trailing whitespace'
task :whitespace do
  sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
end

calling rake tasks with parameters

namespace :backup do

task :dump_dynamic_tables => :environment do

ENV[TABLES] = 'users'
Rake::Task['db:fixtures:export_for_tables'].invoke

end

end