Skip to content

Commit

Permalink
add gemcutter, simplify changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Conway committed Nov 2, 2009
1 parent 5043937 commit 44d989b
Showing 1 changed file with 49 additions and 33 deletions.
82 changes: 49 additions & 33 deletions Rakefile
Expand Up @@ -20,63 +20,79 @@ begin
s.add_dependency 'httparty'
s.add_dependency 'rails'
end
Jeweler::RubyforgeTasks.new
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end

desc 'Test the rubber plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Default: run unit tests.'
task :default => :test

task :changelog do

changelog_file = 'CHANGELOG'
entries = ""

# Get a list of current tags
tags = `git tag -l`.split

out_file = ENV['OUTPUT'] || 'CHANGELOG'
if out_file.size > 0
entries = File.read(out_file)
# If we already have a changelog, make the last tag be the
# last one in the changelog, and the next one be the one
# following that in the tag list
if File.exist?(changelog_file)
entries = File.read(changelog_file)
head = entries.split.first
if head =~ /\d\.\d\.\d/
last_tag = "v#{head}"
idx = tags.index(last_tag)
current_tag = tags[idx + 1] rescue nil
current_tag = tags[idx + 1]
end
else
entries = ""
out_file=$stdout
end

last_tag = ENV['LAST_TAG'] || last_tag || tags[-2]
current_tag = ENV['CURRENT_TAG'] || current_tag || tags[-1]
# Figure out last/current tags and do some validation
last_tag ||= tags[-2]
current_tag ||= tags[-1]

if last_tag.nil? && current_tag.nil?
puts "Cannot generate a changelog without first tagging your repository"
puts "Tags should be in the form vN.N.N"
exit
end

if last_tag == current_tag
puts "Nothing to do for equal revisions: #{last_tag}..#{current_tag}"
exit
end



# Generate changelog from repo
log=`git log --pretty='format:%s <%h> [%cn]' #{last_tag}..#{current_tag}`

# Strip out maintenance entries
log = log.to_a.delete_if {|l| l =~ /^Regenerated gemspec/ || l =~ /^Version bump/ || l =~ /^Updated changelog/ }

out = File.open(out_file, 'w')

out.puts current_tag.gsub(/^v/, '')
out.puts "-----"
out.puts "\n"
out.puts log
out.puts "\n"
out.puts entries

if out_file != $stdout
sh "git ci -m'Updated changelog' #{out_file}"
sh "git push #{out_file}"
# Write out changelog file
File.open(changelog_file, 'w') do |out|
out.puts current_tag.gsub(/^v/, '')
out.puts "-----"
out.puts "\n"
out.puts log
out.puts "\n"
out.puts entries
end
end

desc 'Test the rubber plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
# Commit and push
sh "git ci -m'Updated changelog' #{changelog_file}"
sh "git push"
end

desc 'Default: run unit tests.'
task :default => :test

task :my_release => ['version:bump:patch', 'release', 'changelog', 'gemcutter:release'] do
end

0 comments on commit 44d989b

Please sign in to comment.