(GH-cat-9) syntax:hiera:yaml exclusions added
[puppet-modules/puppetlabs-apt.git] / Rakefile
1 # frozen_string_literal: true
2
3 require 'bundler'
4 require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any?
5 require 'puppetlabs_spec_helper/rake_tasks'
6 require 'puppet-syntax/tasks/puppet-syntax'
7 require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any?
8 require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any?
9 require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any?
10
11 def changelog_user
12   return unless Rake.application.top_level_tasks.include? "changelog"
13   returnVal = nil || JSON.load(File.read('metadata.json'))['author']
14   raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil?
15   puts "GitHubChangelogGenerator user:#{returnVal}"
16   returnVal
17 end
18
19 def changelog_project
20   return unless Rake.application.top_level_tasks.include? "changelog"
21
22   returnVal = nil
23   returnVal ||= begin
24     metadata_source = JSON.load(File.read('metadata.json'))['source']
25     metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z})
26
27     metadata_source_match && metadata_source_match[1]
28   end
29
30   raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil?
31
32   puts "GitHubChangelogGenerator project:#{returnVal}"
33   returnVal
34 end
35
36 def changelog_future_release
37   return unless Rake.application.top_level_tasks.include? "changelog"
38   returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version']
39   raise "unable to find the future_release (version) in metadata.json" if returnVal.nil?
40   puts "GitHubChangelogGenerator future_release:#{returnVal}"
41   returnVal
42 end
43
44 PuppetLint.configuration.send('disable_relative')
45 PuppetLint.configuration.send('disable_top_scope_facts')
46 PuppetLint.configuration.send('disable_topscope_variable')
47 PuppetLint.configuration.send('disable_relative_classname_inclusion')
48 PuppetLint.configuration.send('disable_parameter_documentation')
49 PuppetLint.configuration.send('disable_anchor_resource')
50 PuppetLint.configuration.send('disable_strict_indent')
51 PuppetLint.configuration.send('disable_unquoted_string_in_case')
52 PuppetLint.configuration.send('disable_optional_default')
53
54
55 if Bundler.rubygems.find_name('github_changelog_generator').any?
56   GitHubChangelogGenerator::RakeTask.new :changelog do |config|
57     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?
58     config.user = "#{changelog_user}"
59     config.project = "#{changelog_project}"
60     config.since_tag = "5.0.1"
61     config.future_release = "#{changelog_future_release}"
62     config.exclude_labels = ['maintenance']
63     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)."
64     config.add_pr_wo_labels = true
65     config.issues = false
66     config.merge_prefix = "### UNCATEGORIZED PRS; LABEL THEM ON GITHUB"
67     config.configure_sections = {
68       "Changed" => {
69         "prefix" => "### Changed",
70         "labels" => ["backwards-incompatible"],
71       },
72       "Added" => {
73         "prefix" => "### Added",
74         "labels" => ["enhancement", "feature"],
75       },
76       "Fixed" => {
77         "prefix" => "### Fixed",
78         "labels" => ["bug", "documentation", "bugfix"],
79       },
80     }
81   end
82 else
83   desc 'Generate a Changelog from GitHub'
84   task :changelog do
85     raise <<EOM
86 The changelog tasks depends on recent features of the github_changelog_generator gem.
87 Please manually add it to your .sync.yml for now, and run `pdk update`:
88 ---
89 Gemfile:
90   optional:
91     ':development':
92       - gem: 'github_changelog_generator'
93         version: '~> 1.15'
94         condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')"
95 EOM
96   end
97 end
98