-
Notifications
You must be signed in to change notification settings - Fork 22
/
Rakefile
67 lines (54 loc) · 1.66 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'bundler'
Bundler::GemHelper.install_tasks
task :my_release => ['changelog', 'release'] do
end
task :changelog do
helper = Bundler::GemHelper.new(Dir.pwd)
version = "v#{helper.gemspec.version}"
changelog_file = 'CHANGELOG'
entries = ""
# Get a list of current tags
tags = `git tag -l`.split
tags = tags.sort_by {|t| t[1..-1].split(".").collect {|s| s.to_i } }
newest_tag = tags[-1]
if version == newest_tag
puts "You need to update version, same as most recent tag: #{version}"
exit
end
# 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
newest_changelog_version = nil
if File.exist?(changelog_file)
entries = File.read(changelog_file)
head = entries.split.first
if head =~ /\d\.\d\.\d/
newest_changelog_version = "v#{head}"
if version == newest_changelog_version
puts "You need to update version, same as most recent changelog: #{version}"
exit
end
end
end
# Generate changelog from repo
log=`git log --pretty='format:%s <%h> [%cn]' #{newest_tag}..HEAD`
# Strip out maintenance entries
log = log.lines.to_a.delete_if do |l|
l =~ /^Regenerated? gemspec/ ||
l =~ /^version bump/i ||
l =~ /^Updated changelog/ ||
l =~ /^Merged? branch/
end
# Write out changelog file
File.open(changelog_file, 'w') do |out|
out.puts version.gsub(/^v/, '')
out.puts "-----"
out.puts "\n"
out.puts log
out.puts "\n"
out.puts entries
end
# Commit and push
sh "git commit -m'Updated changelog' #{changelog_file}"
sh "git push"
end