Copy & adapt rake infrastructure from swiftgen projects
This commit is contained in:
@@ -1,34 +1,56 @@
|
||||
NEW_CHANGELOG_SECTION = "## Master\n" + ['Breaking', 'Enhancements', 'Deprecations', 'Bug Fixes', 'Internal Changes'].map do |s|
|
||||
<<~MARKDOWN
|
||||
# frozen_string_literal: true
|
||||
|
||||
### #{s}
|
||||
|
||||
_None_
|
||||
MARKDOWN
|
||||
end.join
|
||||
# Used constants:
|
||||
# _none_
|
||||
|
||||
def changelog_first_section
|
||||
content = []
|
||||
section_count = 0
|
||||
File.foreach(CHANGELOG_FILE) do |line|
|
||||
section_count += 1 if line.start_with?('## ')
|
||||
break if section_count > 1
|
||||
content.append(line) if section_count == 1
|
||||
end
|
||||
content[1..].join
|
||||
end
|
||||
require_relative 'check_changelog'
|
||||
|
||||
namespace :changelog do
|
||||
# rake changelog:reset
|
||||
desc "Add a new empty section at the top of the changelog and git push it"
|
||||
desc 'Add the empty CHANGELOG entries after a new release'
|
||||
task :reset do
|
||||
header "Reset CHANGELOG"
|
||||
content = File.read(CHANGELOG_FILE)
|
||||
new_content = NEW_CHANGELOG_SECTION + "\n" + content
|
||||
File.write(CHANGELOG_FILE, new_content)
|
||||
changelog = File.read('CHANGELOG.md')
|
||||
abort('A Master entry already exists') if changelog =~ /^##\s*Master$/
|
||||
changelog.sub!(/^##[^#]/, "#{header}\\0")
|
||||
File.write('CHANGELOG.md', changelog)
|
||||
end
|
||||
|
||||
sh("git", "add", CHANGELOG_FILE)
|
||||
sh("git", "commit", "-m", "Reset CHANGELOG")
|
||||
sh("git", "push")
|
||||
def header
|
||||
<<-HEADER.gsub(/^\s*\|/, '')
|
||||
|## Master
|
||||
|
|
||||
|### Breaking
|
||||
|
|
||||
|_None_
|
||||
|
|
||||
|### Enhancements
|
||||
|
|
||||
|_None_
|
||||
|
|
||||
|### Deprecations
|
||||
|
|
||||
|_None_
|
||||
|
|
||||
|### Bug Fixes
|
||||
|
|
||||
|_None_
|
||||
|
|
||||
|### Internal Changes
|
||||
|
|
||||
|_None_
|
||||
|
|
||||
HEADER
|
||||
end
|
||||
|
||||
desc 'Check if links to issues and PRs use matching numbers between text & link'
|
||||
task :check do
|
||||
warnings = check_changelog
|
||||
if warnings.empty?
|
||||
puts "\u{2705} All entries seems OK (end with period + 2 spaces, correct links)"
|
||||
else
|
||||
puts "\u{274C} Some warnings were found:\n" + Array(warnings.map do |warning|
|
||||
" - Line #{warning[:line]}: #{warning[:message]}"
|
||||
end).join("\n")
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user