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