(maint) Update for PDK templates
[puppet-modules/puppetlabs-apt.git] / Rakefile
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 require 'puppet_pot_generator/rake_tasks'
8
9 def changelog_user
10   return unless Rake.application.top_level_tasks.include? "changelog"
11   returnVal = nil || JSON.load(File.read('metadata.json'))['author']
12   raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil?
13   puts "GitHubChangelogGenerator user:#{returnVal}"
14   returnVal
15 end
16
17 def changelog_project
18   return unless Rake.application.top_level_tasks.include? "changelog"
19
20   returnVal = nil
21   returnVal ||= begin
22     metadata_source = JSON.load(File.read('metadata.json'))['source']
23     metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z})
24
25     metadata_source_match && metadata_source_match[1]
26   end
27
28   raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil?
29
30   puts "GitHubChangelogGenerator project:#{returnVal}"
31   returnVal
32 end
33
34 def changelog_future_release
35   return unless Rake.application.top_level_tasks.include? "changelog"
36   returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version']
37   raise "unable to find the future_release (version) in metadata.json" if returnVal.nil?
38   puts "GitHubChangelogGenerator future_release:#{returnVal}"
39   returnVal
40 end
41
42 PuppetLint.configuration.send('disable_relative')
43
44 if Bundler.rubygems.find_name('github_changelog_generator').any?
45   GitHubChangelogGenerator::RakeTask.new :changelog do |config|
46     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?
47     config.user = "#{changelog_user}"
48     config.project = "#{changelog_project}"
49     config.future_release = "#{changelog_future_release}"
50     config.exclude_labels = ['maintenance']
51     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)."
52     config.add_pr_wo_labels = true
53     config.issues = false
54     config.merge_prefix = "### UNCATEGORIZED PRS; GO LABEL THEM"
55     config.configure_sections = {
56       "Changed" => {
57         "prefix" => "### Changed",
58         "labels" => ["backwards-incompatible"],
59       },
60       "Added" => {
61         "prefix" => "### Added",
62         "labels" => ["feature", "enhancement"],
63       },
64       "Fixed" => {
65         "prefix" => "### Fixed",
66         "labels" => ["bugfix"],
67       },
68     }
69   end
70 else
71   desc 'Generate a Changelog from GitHub'
72   task :changelog do
73     raise <<EOM
74 The changelog tasks depends on unreleased features of the github_changelog_generator gem.
75 Please manually add it to your .sync.yml for now, and run `pdk update`:
76 ---
77 Gemfile:
78   optional:
79     ':development':
80       - gem: 'github_changelog_generator'
81         git: 'https://github.com/skywinder/github-changelog-generator'
82         ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018'
83         condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')"
84 EOM
85   end
86 end
87