| 1 |
require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? |
| 2 |
require 'puppetlabs_spec_helper/rake_tasks' |
| 3 |
require 'puppet-syntax/tasks/puppet-syntax' |
| 4 |
require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? |
| 5 |
require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? |
| 6 |
require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? |
| 7 |
|
| 8 |
def changelog_user |
| 9 |
return unless Rake.application.top_level_tasks.include? "changelog" |
| 10 |
returnVal = nil || JSON.load(File.read('metadata.json'))['author'] |
| 11 |
raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil? |
| 12 |
puts "GitHubChangelogGenerator user:#{returnVal}" |
| 13 |
returnVal |
| 14 |
end |
| 15 |
|
| 16 |
def changelog_project |
| 17 |
return unless Rake.application.top_level_tasks.include? "changelog" |
| 18 |
|
| 19 |
returnVal = nil |
| 20 |
returnVal ||= begin |
| 21 |
metadata_source = JSON.load(File.read('metadata.json'))['source'] |
| 22 |
metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z}) |
| 23 |
|
| 24 |
metadata_source_match && metadata_source_match[1] |
| 25 |
end |
| 26 |
|
| 27 |
raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil? |
| 28 |
|
| 29 |
puts "GitHubChangelogGenerator project:#{returnVal}" |
| 30 |
returnVal |
| 31 |
end |
| 32 |
|
| 33 |
def changelog_future_release |
| 34 |
return unless Rake.application.top_level_tasks.include? "changelog" |
| 35 |
returnVal = "%s" % JSON.load(File.read('metadata.json'))['version'] |
| 36 |
raise "unable to find the future_release (version) in metadata.json" if returnVal.nil? |
| 37 |
puts "GitHubChangelogGenerator future_release:#{returnVal}" |
| 38 |
returnVal |
| 39 |
end |
| 40 |
|
| 41 |
PuppetLint.configuration.send('disable_relative') |
| 42 |
|
| 43 |
if Bundler.rubygems.find_name('github_changelog_generator').any? |
| 44 |
GitHubChangelogGenerator::RakeTask.new :changelog do |config| |
| 45 |
raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil? |
| 46 |
config.user = "#{changelog_user}" |
| 47 |
config.project = "#{changelog_project}" |
| 48 |
config.future_release = "#{changelog_future_release}" |
| 49 |
config.exclude_labels = ['maintenance'] |
| 50 |
config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org)." |
| 51 |
config.add_pr_wo_labels = true |
| 52 |
config.issues = false |
| 53 |
config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM" |
| 54 |
config.configure_sections = { |
| 55 |
"Changed" => { |
| 56 |
"prefix" => "### Changed", |
| 57 |
"labels" => ["backwards-incompatible"], |
| 58 |
}, |
| 59 |
"Added" => { |
| 60 |
"prefix" => "### Added", |
| 61 |
"labels" => ["feature", "enhancement"], |
| 62 |
}, |
| 63 |
"Fixed" => { |
| 64 |
"prefix" => "### Fixed", |
| 65 |
"labels" => ["bugfix"], |
| 66 |
}, |
| 67 |
} |
| 68 |
end |
| 69 |
else |
| 70 |
desc 'Generate a Changelog from GitHub' |
| 71 |
task :changelog do |
| 72 |
raise <<EOM |
| 73 |
The changelog tasks depends on unreleased features of the github_changelog_generator gem. |
| 74 |
Please manually add it to your .sync.yml for now, and run `pdk update`: |
| 75 |
--- |
| 76 |
Gemfile: |
| 77 |
optional: |
| 78 |
':development': |
| 79 |
- gem: 'github_changelog_generator' |
| 80 |
git: 'https://github.com/skywinder/github-changelog-generator' |
| 81 |
ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' |
| 82 |
condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')" |
| 83 |
EOM |
| 84 |
end |
| 85 |
end |
| 86 |
|
| 87 |
desc "verify that commit messages match CONTRIBUTING.md requirements" |
| 88 |
task(:commits) do |
| 89 |
# This rake task looks at the summary from every commit from this branch not |
| 90 |
# in the branch targeted for a PR. |
| 91 |
commit_range = 'HEAD^..HEAD' |
| 92 |
puts "Checking commits #{commit_range}" |
| 93 |
%x{git log --no-merges --pretty=%s #{commit_range}}.each_line do |commit_summary| |
| 94 |
# This regex tests for the currently supported commit summary tokens. |
| 95 |
# The exception tries to explain it in more full. |
| 96 |
if /^\((maint|packaging|doc|docs|modules-\d+)\)|revert/i.match(commit_summary).nil? |
| 97 |
raise "\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n" \ |
| 98 |
"\n\t\t#{commit_summary}\n" \ |
| 99 |
"\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n" \ |
| 100 |
"\t\t(MODULES-<digits>) # this is most common and should be a ticket at tickets.puppet.com\n" \ |
| 101 |
"\t\t(docs)\n" \ |
| 102 |
"\t\t(docs)(DOCUMENT-<digits>)\n" \ |
| 103 |
"\t\t(packaging)\n" |
| 104 |
"\t\t(maint)\n" \ |
| 105 |
"\n\tThis test for the commit summary is case-insensitive.\n\n\n" |
| 106 |
else |
| 107 |
puts "#{commit_summary}" |
| 108 |
end |
| 109 |
puts "...passed" |
| 110 |
end |
| 111 |
end |