puppetlabs_spec_helper 2.7.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/.rubocop.yml +114 -463
- data/.rubocop_todo.yml +119 -0
- data/.travis.yml +17 -16
- data/CHANGELOG.md +212 -5
- data/CODEOWNERS +2 -0
- data/Gemfile +32 -12
- data/HISTORY.md +498 -0
- data/README.md +81 -98
- data/Rakefile +37 -7
- data/lib/puppetlabs_spec_helper/module_spec_helper.rb +41 -0
- data/lib/puppetlabs_spec_helper/puppet_spec_helper.rb +12 -11
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb +5 -3
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb +14 -10
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb +12 -13
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb +20 -17
- data/lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb +3 -1
- data/lib/puppetlabs_spec_helper/rake_tasks.rb +250 -117
- data/lib/puppetlabs_spec_helper/tasks/beaker.rb +20 -16
- data/lib/puppetlabs_spec_helper/tasks/check_symlinks.rb +52 -0
- data/lib/puppetlabs_spec_helper/tasks/fixtures.rb +301 -167
- data/lib/puppetlabs_spec_helper/version.rb +3 -1
- data/puppet_spec_helper.rb +3 -1
- data/puppetlabs_spec_helper.gemspec +24 -22
- data/puppetlabs_spec_helper.rb +3 -1
- metadata +67 -26
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Initialize puppet for testing by loading the
|
|
2
4
|
# 'puppetlabs_spec_helper/puppet_spec_helper' library
|
|
3
5
|
require 'puppetlabs_spec_helper/puppet_spec_helper'
|
|
@@ -8,9 +10,9 @@ module PuppetlabsSpec
|
|
|
8
10
|
# instance suitable for placing in a test harness with the intent of
|
|
9
11
|
# testing parser functions from modules.
|
|
10
12
|
def scope(parts = {})
|
|
11
|
-
RSpec.deprecate('scope', :
|
|
13
|
+
RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')
|
|
12
14
|
|
|
13
|
-
if
|
|
15
|
+
if %r{^2\.[67]}.match?(Puppet.version)
|
|
14
16
|
# loadall should only be necessary prior to 3.x
|
|
15
17
|
# Please note, loadall needs to happen first when creating a scope, otherwise
|
|
16
18
|
# you might receive undefined method `function_*' errors
|
|
@@ -19,15 +21,15 @@ module PuppetlabsSpec
|
|
|
19
21
|
|
|
20
22
|
scope_compiler = parts[:compiler] || compiler
|
|
21
23
|
scope_parent = parts[:parent] || scope_compiler.topscope
|
|
22
|
-
scope_resource = parts[:resource] || resource(:
|
|
24
|
+
scope_resource = parts[:resource] || resource(type: :node, title: scope_compiler.node.name)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
scope = if %r{^2\.[67]}.match?(Puppet.version)
|
|
27
|
+
Puppet::Parser::Scope.new(compiler: scope_compiler)
|
|
28
|
+
else
|
|
29
|
+
Puppet::Parser::Scope.new(scope_compiler)
|
|
30
|
+
end
|
|
29
31
|
|
|
30
|
-
scope.source = Puppet::Resource::Type.new(:node,
|
|
32
|
+
scope.source = Puppet::Resource::Type.new(:node, 'foo')
|
|
31
33
|
scope.parent = scope_parent
|
|
32
34
|
scope
|
|
33
35
|
end
|
|
@@ -35,13 +37,13 @@ module PuppetlabsSpec
|
|
|
35
37
|
|
|
36
38
|
def resource(parts = {})
|
|
37
39
|
resource_type = parts[:type] || :hostclass
|
|
38
|
-
resource_name = parts[:name] ||
|
|
40
|
+
resource_name = parts[:name] || 'testing'
|
|
39
41
|
Puppet::Resource::Type.new(resource_type, resource_name)
|
|
40
42
|
end
|
|
41
43
|
module_function :resource
|
|
42
44
|
|
|
43
45
|
def compiler(parts = {})
|
|
44
|
-
compiler_node = parts[:node] || node
|
|
46
|
+
compiler_node = parts[:node] || node
|
|
45
47
|
Puppet::Parser::Compiler.new(compiler_node)
|
|
46
48
|
end
|
|
47
49
|
module_function :compiler
|
|
@@ -49,12 +51,12 @@ module PuppetlabsSpec
|
|
|
49
51
|
def node(parts = {})
|
|
50
52
|
node_name = parts[:name] || 'testinghost'
|
|
51
53
|
options = parts[:options] || {}
|
|
52
|
-
if Puppet.version.to_f >= 4.0
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
options
|
|
54
|
+
node_environment = if Puppet.version.to_f >= 4.0
|
|
55
|
+
Puppet::Node::Environment.create(parts[:environment] || 'test', [])
|
|
56
|
+
else
|
|
57
|
+
Puppet::Node::Environment.new(parts[:environment] || 'test')
|
|
58
|
+
end
|
|
59
|
+
options[:environment] = node_environment
|
|
58
60
|
Puppet::Node.new(node_name, options)
|
|
59
61
|
end
|
|
60
62
|
module_function :node
|
|
@@ -67,6 +69,7 @@ module PuppetlabsSpec
|
|
|
67
69
|
# exists. This is a hack, but at least it's a hidden hack and not an
|
|
68
70
|
# exposed hack.
|
|
69
71
|
return nil unless Puppet::Parser::Functions.function(name)
|
|
72
|
+
|
|
70
73
|
scope.method("function_#{name}".intern)
|
|
71
74
|
end
|
|
72
75
|
module_function :function_method
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Define the main module namespace for use by the helper modules
|
|
2
4
|
module PuppetlabsSpec
|
|
3
5
|
# FIXTURE_DIR represents the standard locations of all fixture data. Normally
|
|
4
6
|
# this represents <project>/spec/fixtures. This will be used by the fixtures
|
|
5
7
|
# library to find relative fixture data.
|
|
6
|
-
FIXTURE_DIR = File.join(
|
|
8
|
+
FIXTURE_DIR = File.join('spec', 'fixtures') unless defined?(FIXTURE_DIR)
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
# Require all necessary helper libraries so they can be used later
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'fileutils'
|
|
2
4
|
require 'rake'
|
|
3
5
|
require 'rspec/core/rake_task'
|
|
@@ -6,6 +8,8 @@ require 'pathname'
|
|
|
6
8
|
require 'puppetlabs_spec_helper/version'
|
|
7
9
|
require 'puppetlabs_spec_helper/tasks/beaker'
|
|
8
10
|
require 'puppetlabs_spec_helper/tasks/fixtures'
|
|
11
|
+
require 'puppetlabs_spec_helper/tasks/check_symlinks'
|
|
12
|
+
require 'English'
|
|
9
13
|
|
|
10
14
|
# optional gems
|
|
11
15
|
begin
|
|
@@ -14,6 +18,24 @@ rescue LoadError
|
|
|
14
18
|
# ignore
|
|
15
19
|
end
|
|
16
20
|
|
|
21
|
+
begin
|
|
22
|
+
require 'puppet_blacksmith/rake_tasks'
|
|
23
|
+
rescue LoadError
|
|
24
|
+
# ignore
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
begin
|
|
28
|
+
require 'github_changelog_generator/task'
|
|
29
|
+
rescue LoadError
|
|
30
|
+
# ignore
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
require 'puppet-strings/tasks'
|
|
35
|
+
rescue LoadError
|
|
36
|
+
# ignore
|
|
37
|
+
end
|
|
38
|
+
|
|
17
39
|
parallel_tests_loaded = false
|
|
18
40
|
begin
|
|
19
41
|
require 'parallel_tests'
|
|
@@ -22,121 +44,177 @@ rescue LoadError
|
|
|
22
44
|
# ignore
|
|
23
45
|
end
|
|
24
46
|
|
|
25
|
-
task :
|
|
47
|
+
task default: [:help]
|
|
26
48
|
|
|
27
|
-
pattern = 'spec/{aliases,classes,defines,
|
|
49
|
+
pattern = 'spec/{aliases,classes,defines,functions,hosts,integration,plans,tasks,type_aliases,types,unit}/**/*_spec.rb'
|
|
28
50
|
|
|
29
51
|
RSpec::Core::RakeTask.new(:spec_standalone) do |t, args|
|
|
30
|
-
t.rspec_opts = [
|
|
52
|
+
t.rspec_opts = []
|
|
31
53
|
t.rspec_opts << ENV['CI_SPEC_OPTIONS'] unless ENV['CI_SPEC_OPTIONS'].nil?
|
|
32
54
|
if ENV['CI_NODE_TOTAL'] && ENV['CI_NODE_INDEX']
|
|
33
55
|
ci_total = ENV['CI_NODE_TOTAL'].to_i
|
|
34
56
|
ci_index = ENV['CI_NODE_INDEX'].to_i
|
|
35
57
|
raise "CI_NODE_INDEX must be between 1-#{ci_total}" unless ci_index >= 1 && ci_index <= ci_total
|
|
58
|
+
|
|
36
59
|
files = Rake::FileList[pattern].to_a
|
|
37
60
|
per_node = (files.size / ci_total.to_f).ceil
|
|
38
61
|
t.pattern = if args.extras.nil? || args.extras.empty?
|
|
39
62
|
files.each_slice(per_node).to_a[ci_index - 1] || files.first
|
|
40
63
|
else
|
|
41
|
-
args.extras.join(
|
|
64
|
+
args.extras.join(',')
|
|
42
65
|
end
|
|
43
66
|
else
|
|
44
|
-
if args.extras.nil? || args.extras.empty?
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
t.pattern = if args.extras.nil? || args.extras.empty?
|
|
68
|
+
pattern
|
|
69
|
+
else
|
|
70
|
+
args.extras.join(',')
|
|
71
|
+
end
|
|
49
72
|
end
|
|
50
73
|
end
|
|
51
74
|
|
|
52
|
-
desc
|
|
75
|
+
desc 'List spec tests in a JSON document'
|
|
53
76
|
RSpec::Core::RakeTask.new(:spec_list_json) do |t|
|
|
54
77
|
t.rspec_opts = ['--dry-run', '--format', 'json']
|
|
55
78
|
t.pattern = pattern
|
|
56
79
|
end
|
|
57
80
|
|
|
58
|
-
desc
|
|
59
|
-
task :spec do |
|
|
81
|
+
desc 'Run spec tests and clean the fixtures directory if successful'
|
|
82
|
+
task :spec do |_t, args|
|
|
60
83
|
begin
|
|
61
84
|
Rake::Task[:spec_prep].invoke
|
|
62
85
|
Rake::Task[:spec_standalone].invoke(*args.extras)
|
|
86
|
+
Rake::Task[:spec_clean].invoke
|
|
63
87
|
ensure
|
|
88
|
+
Rake::Task[:spec_clean_symlinks].invoke
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
desc 'Run spec tests with ruby simplecov code coverage'
|
|
93
|
+
namespace :spec do
|
|
94
|
+
task :simplecov do
|
|
95
|
+
ENV['SIMPLECOV'] = 'yes'
|
|
96
|
+
Rake::Task['spec'].execute
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
desc 'Run spec tests in parallel and clean the fixtures directory if successful'
|
|
101
|
+
task :parallel_spec do |_t, args|
|
|
102
|
+
begin
|
|
103
|
+
Rake::Task[:spec_prep].invoke
|
|
104
|
+
Rake::Task[:parallel_spec_standalone].invoke(*args.extras)
|
|
64
105
|
Rake::Task[:spec_clean].invoke
|
|
106
|
+
ensure
|
|
107
|
+
Rake::Task[:spec_clean_symlinks].invoke
|
|
65
108
|
end
|
|
66
109
|
end
|
|
67
110
|
|
|
68
|
-
desc
|
|
69
|
-
task :
|
|
111
|
+
desc 'Parallel spec tests'
|
|
112
|
+
task :parallel_spec_standalone do |_t, args|
|
|
70
113
|
raise 'Add the parallel_tests gem to Gemfile to enable this task' unless parallel_tests_loaded
|
|
114
|
+
|
|
71
115
|
if Rake::FileList[pattern].to_a.empty?
|
|
72
|
-
warn
|
|
116
|
+
warn 'No files for parallel_spec to run against'
|
|
73
117
|
else
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
ensure
|
|
82
|
-
Rake::Task[:spec_clean].invoke
|
|
83
|
-
end
|
|
118
|
+
|
|
119
|
+
args = ['-t', 'rspec']
|
|
120
|
+
args.push('--').concat(ENV['CI_SPEC_OPTIONS'].strip.split(' ')).push('--') unless ENV['CI_SPEC_OPTIONS'].nil? || ENV['CI_SPEC_OPTIONS'].strip.empty?
|
|
121
|
+
args.concat(Rake::FileList[pattern].to_a)
|
|
122
|
+
|
|
123
|
+
ParallelTests::CLI.new.run(args)
|
|
124
|
+
|
|
84
125
|
end
|
|
85
126
|
end
|
|
86
127
|
|
|
87
|
-
desc
|
|
128
|
+
desc 'Build puppet module package'
|
|
88
129
|
task :build do
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
130
|
+
if Gem::Specification.find_by_name('puppet').version < Gem::Version.new('6.0.0')
|
|
131
|
+
Rake::Task['build:pmt'].invoke
|
|
132
|
+
else
|
|
133
|
+
Rake::Task['build:pdk'].invoke
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
namespace :build do
|
|
138
|
+
desc 'Build Puppet module package with PMT (Puppet < 6.0.0 only)'
|
|
139
|
+
task :pmt do
|
|
93
140
|
require 'puppet/face'
|
|
141
|
+
|
|
94
142
|
pmod = Puppet::Face['module', :current]
|
|
95
143
|
pmod.build('./')
|
|
96
144
|
end
|
|
145
|
+
|
|
146
|
+
desc 'Build Puppet module with PDK'
|
|
147
|
+
task :pdk do
|
|
148
|
+
begin
|
|
149
|
+
require 'pdk/util'
|
|
150
|
+
require 'pdk/module/build'
|
|
151
|
+
|
|
152
|
+
path = PDK::Module::Build.invoke(force: true, 'target-dir': File.join(Dir.pwd, 'pkg'))
|
|
153
|
+
puts "Module built: #{path}"
|
|
154
|
+
rescue LoadError
|
|
155
|
+
_ = `pdk --version`
|
|
156
|
+
unless $CHILD_STATUS.success?
|
|
157
|
+
warn 'Unable to build module. Please install PDK or add the `pdk` gem to your Gemfile.'
|
|
158
|
+
abort
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
system('pdk build --force')
|
|
162
|
+
end
|
|
163
|
+
end
|
|
97
164
|
end
|
|
98
165
|
|
|
99
|
-
desc
|
|
166
|
+
desc 'Clean a built module package'
|
|
100
167
|
task :clean do
|
|
101
|
-
FileUtils.rm_rf(
|
|
168
|
+
FileUtils.rm_rf('pkg/')
|
|
102
169
|
end
|
|
103
170
|
|
|
104
171
|
require 'puppet-lint/tasks/puppet-lint'
|
|
105
172
|
# Must clear as it will not override the existing puppet-lint rake task since we require to import for
|
|
106
173
|
# the PuppetLint::RakeTask
|
|
107
174
|
Rake::Task[:lint].clear
|
|
108
|
-
#
|
|
175
|
+
# Utilize PuppetLint global configuration so that these settings can be tweaked by
|
|
176
|
+
# spec_helper.rb in an individual module
|
|
109
177
|
PuppetLint.configuration.relative = true
|
|
110
|
-
PuppetLint
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
178
|
+
PuppetLint.configuration.ignore_paths ||= []
|
|
179
|
+
PuppetLint.configuration.ignore_paths << '.vendor/**/*.pp'
|
|
180
|
+
PuppetLint.configuration.ignore_paths << 'bundle/**/*.pp'
|
|
181
|
+
PuppetLint.configuration.ignore_paths << 'pkg/**/*.pp'
|
|
182
|
+
PuppetLint.configuration.ignore_paths << 'spec/**/*.pp'
|
|
183
|
+
PuppetLint.configuration.ignore_paths << 'tests/**/*.pp'
|
|
184
|
+
PuppetLint.configuration.ignore_paths << 'types/**/*.pp'
|
|
185
|
+
PuppetLint.configuration.ignore_paths << 'vendor/**/*.pp'
|
|
186
|
+
puppet_lint_disable_checks = %w[
|
|
187
|
+
80chars
|
|
188
|
+
140chars
|
|
189
|
+
class_inherits_from_params_class
|
|
190
|
+
class_parameter_defaults
|
|
191
|
+
disable_autoloader_layout
|
|
192
|
+
documentation
|
|
193
|
+
single_quote_string_with_variables
|
|
194
|
+
]
|
|
195
|
+
puppet_lint_disable_checks.each do |check|
|
|
196
|
+
PuppetLint.configuration.send("disable_#{check}")
|
|
197
|
+
end
|
|
198
|
+
PuppetLint::RakeTask.new(:lint)
|
|
199
|
+
|
|
200
|
+
desc 'Run puppet-lint and fix issues automatically'
|
|
201
|
+
PuppetLint::RakeTask.new(:lint_fix) do |config|
|
|
202
|
+
config.fix = true
|
|
127
203
|
end
|
|
128
204
|
|
|
129
205
|
require 'puppet-syntax/tasks/puppet-syntax'
|
|
130
206
|
PuppetSyntax.exclude_paths ||= []
|
|
131
|
-
PuppetSyntax.exclude_paths <<
|
|
132
|
-
PuppetSyntax.exclude_paths <<
|
|
133
|
-
PuppetSyntax.exclude_paths <<
|
|
207
|
+
PuppetSyntax.exclude_paths << 'spec/fixtures/**/*'
|
|
208
|
+
PuppetSyntax.exclude_paths << 'pkg/**/*'
|
|
209
|
+
PuppetSyntax.exclude_paths << 'vendor/**/*'
|
|
210
|
+
PuppetSyntax.exclude_paths << '.vendor/**/*'
|
|
211
|
+
PuppetSyntax.exclude_paths << 'plans/**/*'
|
|
134
212
|
if Puppet.version.to_f < 4.0
|
|
135
|
-
PuppetSyntax.exclude_paths <<
|
|
213
|
+
PuppetSyntax.exclude_paths << 'types/**/*'
|
|
136
214
|
end
|
|
137
215
|
PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'yes'
|
|
138
216
|
|
|
139
|
-
desc
|
|
217
|
+
desc 'Check syntax of Ruby files and call :syntax and :metadata_lint'
|
|
140
218
|
task :validate do
|
|
141
219
|
Dir['lib/**/*.rb'].each do |lib_file|
|
|
142
220
|
sh "ruby -c #{lib_file}"
|
|
@@ -147,7 +225,7 @@ task :validate do
|
|
|
147
225
|
if Rake::Task.task_defined?(:metadata_lint)
|
|
148
226
|
Rake::Task[:metadata_lint].invoke
|
|
149
227
|
else
|
|
150
|
-
warn
|
|
228
|
+
warn 'Skipping metadata validation; the metadata-json-lint gem was not found'
|
|
151
229
|
end
|
|
152
230
|
end
|
|
153
231
|
end
|
|
@@ -157,23 +235,23 @@ task :metadata do
|
|
|
157
235
|
if Rake::Task.task_defined?(:metadata_lint)
|
|
158
236
|
Rake::Task[:metadata_lint].invoke
|
|
159
237
|
else
|
|
160
|
-
warn
|
|
238
|
+
warn 'Skipping metadata validation; the metadata-json-lint gem was not found'
|
|
161
239
|
end
|
|
162
240
|
end
|
|
163
241
|
|
|
164
|
-
desc
|
|
242
|
+
desc 'Print development version of module'
|
|
165
243
|
task :compute_dev_version do
|
|
166
244
|
version = ''
|
|
167
|
-
if File.
|
|
245
|
+
if File.exist?('metadata.json')
|
|
168
246
|
require 'json'
|
|
169
247
|
|
|
170
|
-
modinfo = JSON.parse(File.read(
|
|
248
|
+
modinfo = JSON.parse(File.read('metadata.json'))
|
|
171
249
|
version = modinfo['version']
|
|
172
|
-
elsif File.
|
|
250
|
+
elsif File.exist?('Modulefile')
|
|
173
251
|
modfile = File.read('Modulefile')
|
|
174
|
-
version = modfile.match(
|
|
252
|
+
version = modfile.match(%r{\nversion +['"](.*)['"]})[1]
|
|
175
253
|
else
|
|
176
|
-
|
|
254
|
+
raise 'Could not find a metadata.json or Modulefile! Cannot compute dev version without one or the other!'
|
|
177
255
|
end
|
|
178
256
|
|
|
179
257
|
sha = `git rev-parse HEAD`[0..7]
|
|
@@ -183,20 +261,20 @@ task :compute_dev_version do
|
|
|
183
261
|
# If the branch is a release branch we append an 'r' into the new_version,
|
|
184
262
|
# this is due to the release branch buildID conflicting with master branch when trying to push to the staging forge.
|
|
185
263
|
# More info can be found at https://tickets.puppetlabs.com/browse/FM-6170
|
|
186
|
-
if build = ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER']
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
264
|
+
new_version = if build = (ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER'])
|
|
265
|
+
if branch.eql? 'release'
|
|
266
|
+
'%s-%s%04d-%s' % [version, 'r', build, sha] # legacy support code # rubocop:disable Style/FormatStringToken
|
|
267
|
+
else
|
|
268
|
+
'%s-%04d-%s' % [version, build, sha] # legacy support code # rubocop:disable Style/FormatStringToken
|
|
269
|
+
end
|
|
270
|
+
else
|
|
271
|
+
"#{version}-#{sha}"
|
|
272
|
+
end
|
|
195
273
|
|
|
196
274
|
print new_version
|
|
197
275
|
end
|
|
198
276
|
|
|
199
|
-
desc
|
|
277
|
+
desc 'Runs all necessary checks on a module in preparation for a release'
|
|
200
278
|
task :release_checks do
|
|
201
279
|
Rake::Task[:lint].invoke
|
|
202
280
|
Rake::Task[:validate].invoke
|
|
@@ -205,56 +283,53 @@ task :release_checks do
|
|
|
205
283
|
else
|
|
206
284
|
Rake::Task[:spec].invoke
|
|
207
285
|
end
|
|
208
|
-
Rake::Task[
|
|
209
|
-
Rake::Task["check:test_file"].invoke
|
|
210
|
-
Rake::Task["check:dot_underscore"].invoke
|
|
211
|
-
Rake::Task["check:git_ignore"].invoke
|
|
286
|
+
Rake::Task[:check].invoke
|
|
212
287
|
end
|
|
213
288
|
|
|
214
289
|
namespace :check do
|
|
215
|
-
desc
|
|
290
|
+
desc 'Fails if symlinks are present in directory'
|
|
216
291
|
task :symlinks do
|
|
217
|
-
symlinks =
|
|
292
|
+
symlinks = PuppetlabsSpecHelper::Tasks::CheckSymlinks.new.check
|
|
218
293
|
unless symlinks.empty?
|
|
219
|
-
symlinks.each { |r| puts "Symlink found: #{r
|
|
220
|
-
|
|
294
|
+
symlinks.each { |r| puts "Symlink found: #{r} => #{r.readlink}" }
|
|
295
|
+
raise 'Symlink(s) exist within this directory'
|
|
221
296
|
end
|
|
222
297
|
end
|
|
223
298
|
|
|
224
|
-
desc
|
|
299
|
+
desc 'Fails if .pp files present in tests folder'
|
|
225
300
|
task :test_file do
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
ppfiles
|
|
229
|
-
|
|
230
|
-
puts ppfiles
|
|
231
|
-
fail ".pp files present in tests folder; Move them to an examples folder following the new convention"
|
|
232
|
-
end
|
|
301
|
+
ppfiles = Dir[File.join('tests', '**', '*.pp')]
|
|
302
|
+
unless ppfiles.empty?
|
|
303
|
+
puts ppfiles
|
|
304
|
+
raise '.pp files present in tests folder; Move them to an examples folder following the new convention'
|
|
233
305
|
end
|
|
234
306
|
end
|
|
235
307
|
|
|
236
|
-
desc
|
|
308
|
+
desc 'Fails if any ._ files are present in directory'
|
|
237
309
|
task :dot_underscore do
|
|
238
|
-
dirs = Dir[
|
|
310
|
+
dirs = Dir['._*']
|
|
239
311
|
unless dirs.empty?
|
|
240
312
|
puts dirs
|
|
241
|
-
|
|
313
|
+
raise '._ files are present in the directory'
|
|
242
314
|
end
|
|
243
315
|
end
|
|
244
316
|
|
|
245
|
-
desc
|
|
317
|
+
desc 'Fails if directories contain the files specified in .gitignore'
|
|
246
318
|
task :git_ignore do
|
|
247
319
|
matched = `git ls-files --ignored --exclude-standard`
|
|
248
|
-
unless matched ==
|
|
320
|
+
unless matched == ''
|
|
249
321
|
puts matched
|
|
250
|
-
|
|
322
|
+
raise 'File specified in .gitignore has been committed'
|
|
251
323
|
end
|
|
252
324
|
end
|
|
253
325
|
end
|
|
254
326
|
|
|
255
|
-
desc
|
|
327
|
+
desc 'Run static pre release checks'
|
|
328
|
+
task check: ['check:symlinks', 'check:test_file', 'check:dot_underscore', 'check:git_ignore']
|
|
329
|
+
|
|
330
|
+
desc 'Display the list of available rake tasks'
|
|
256
331
|
task :help do
|
|
257
|
-
system(
|
|
332
|
+
system('rake -T')
|
|
258
333
|
end
|
|
259
334
|
|
|
260
335
|
begin
|
|
@@ -264,31 +339,89 @@ begin
|
|
|
264
339
|
task.options = ['-D', '-S', '-E']
|
|
265
340
|
end
|
|
266
341
|
rescue LoadError
|
|
267
|
-
desc
|
|
342
|
+
desc 'rubocop is not available in this installation'
|
|
268
343
|
task :rubocop do
|
|
269
|
-
|
|
344
|
+
raise 'rubocop is not available in this installation'
|
|
270
345
|
end
|
|
271
346
|
end
|
|
272
347
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
#
|
|
276
|
-
#
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
348
|
+
def create_gch_task(changelog_user = nil, changelog_project = nil, changelog_since_tag = nil, changelog_tag_pattern = 'v%s')
|
|
349
|
+
if Bundler.rubygems.find_name('github_changelog_generator').any?
|
|
350
|
+
# needed a place to hide these methods
|
|
351
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
|
352
|
+
def changelog_user_from_metadata
|
|
353
|
+
result = JSON.parse(File.read('metadata.json'))['author']
|
|
354
|
+
raise 'unable to find the changelog_user in .sync.yml, or the author in metadata.json' if result.nil?
|
|
355
|
+
|
|
356
|
+
puts "GitHubChangelogGenerator user:#{result}"
|
|
357
|
+
result
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
def changelog_project_from_metadata
|
|
361
|
+
result = JSON.parse(File.read('metadata.json'))['name']
|
|
362
|
+
raise 'unable to find the changelog_project in .sync.yml or the name in metadata.json' if result.nil?
|
|
363
|
+
|
|
364
|
+
puts "GitHubChangelogGenerator project:#{result}"
|
|
365
|
+
result
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def changelog_future_release
|
|
369
|
+
return unless Rake.application.top_level_tasks.include? 'changelog'
|
|
370
|
+
|
|
371
|
+
result = JSON.parse(File.read('metadata.json'))['version']
|
|
372
|
+
raise 'unable to find the future_release (version) in metadata.json' if result.nil?
|
|
373
|
+
|
|
374
|
+
puts "GitHubChangelogGenerator future_release:#{result}"
|
|
375
|
+
result
|
|
376
|
+
end
|
|
377
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
|
378
|
+
|
|
379
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
|
380
|
+
if ENV['CHANGELOG_GITHUB_TOKEN'].nil?
|
|
381
|
+
raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'"
|
|
289
382
|
end
|
|
383
|
+
|
|
384
|
+
config.user = changelog_user || changelog_user_from_metadata
|
|
385
|
+
config.project = changelog_project || changelog_project_from_metadata
|
|
386
|
+
config.since_tag = changelog_since_tag if changelog_since_tag
|
|
387
|
+
config.future_release = changelog_tag_pattern % changelog_future_release.to_s
|
|
388
|
+
config.exclude_labels = ['maintenance']
|
|
389
|
+
config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. " \
|
|
390
|
+
'The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres ' \
|
|
391
|
+
'to [Semantic Versioning](https://semver.org).'
|
|
392
|
+
config.add_pr_wo_labels = true
|
|
393
|
+
config.issues = false
|
|
394
|
+
config.merge_prefix = '### UNCATEGORIZED PRS; GO LABEL THEM'
|
|
395
|
+
config.configure_sections = {
|
|
396
|
+
'Changed' => {
|
|
397
|
+
'prefix' => '### Changed',
|
|
398
|
+
'labels' => ['backwards-incompatible'],
|
|
399
|
+
},
|
|
400
|
+
'Added' => {
|
|
401
|
+
'prefix' => '### Added',
|
|
402
|
+
'labels' => %w[feature enhancement],
|
|
403
|
+
},
|
|
404
|
+
'Fixed' => {
|
|
405
|
+
'prefix' => '### Fixed',
|
|
406
|
+
'labels' => ['bugfix'],
|
|
407
|
+
},
|
|
408
|
+
}
|
|
409
|
+
end
|
|
410
|
+
else
|
|
411
|
+
desc 'Generate a Changelog from GitHub'
|
|
412
|
+
task :changelog do
|
|
413
|
+
raise <<~MESSAGE
|
|
414
|
+
The changelog tasks depends on unreleased features of the github_changelog_generator gem.
|
|
415
|
+
Please manually add it to your .sync.yml for now, and run `pdk update`:
|
|
416
|
+
---
|
|
417
|
+
Gemfile:
|
|
418
|
+
optional:
|
|
419
|
+
':development':
|
|
420
|
+
- gem: 'github_changelog_generator'
|
|
421
|
+
git: 'https://github.com/skywinder/github-changelog-generator'
|
|
422
|
+
ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018'
|
|
423
|
+
condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')"
|
|
424
|
+
MESSAGE
|
|
290
425
|
end
|
|
291
|
-
rescue Gem::LoadError
|
|
292
|
-
puts "No gettext-setup gem found, skipping GettextSetup config initialization" if Rake.verbose == true
|
|
293
426
|
end
|
|
294
427
|
end
|