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