-
Notifications
You must be signed in to change notification settings - Fork 4
/
changelog.rake
36 lines (33 loc) · 1.38 KB
/
changelog.rake
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
# frozen_string_literal: true
require_relative 'release_tool_utils'
namespace :changelog do
desc 'replaces "Unreleased Changes"" in the CHANGELOG with a version and date'
idempotent_task :version do
puts 'TASK START: changelog:version'
changelog = File.open('CHANGELOG.md', 'r', encoding: 'UTF-8', &:read)
changelog = changelog.lines.to_a
unless changelog.first.include? 'Unreleased Changes'
warn('The first line of changelog must match "Unreleased Changes"')
exit(1)
end
changelog[0] = "#{$VERSION} (#{Time.now.strftime('%Y-%m-%d')})\n"
changelog = changelog.join
File.open('CHANGELOG.md', 'w', encoding: 'UTF-8') { |f| f.write(changelog) }
sh('git add CHANGELOG.md')
puts 'TASK END: changelog:version'
end
desc 'inserts an "Unreleased Changes" section at the top of the CHANGELOG'
idempotent_task :unreleased_changes do
puts 'TASK START: changelog:unreleased_changes'
lines = []
lines << "Unreleased Changes\n"
lines << "------------------\n"
lines << "\n"
changelog = File.open('CHANGELOG.md', 'r', encoding: 'UTF-8', &:read)
changelog = lines.join + changelog
File.open('CHANGELOG.md', 'w', encoding: 'UTF-8') { |f| f.write(changelog) }
sh('git add CHANGELOG.md')
sh("git commit -m 'Added next release section to the changelog. [ci skip]'")
puts 'TASK END: changelog:unreleased_changes'
end
end