pdk 2.6.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +11 -10
- data/lib/pdk/analytics/client/google_analytics.rb +4 -2
- data/lib/pdk/cli/build.rb +17 -21
- data/lib/pdk/cli/bundle.rb +4 -5
- data/lib/pdk/cli/config/get.rb +6 -6
- data/lib/pdk/cli/config.rb +3 -3
- data/lib/pdk/cli/console.rb +7 -7
- data/lib/pdk/cli/convert.rb +11 -11
- data/lib/pdk/cli/env.rb +3 -4
- data/lib/pdk/cli/errors.rb +1 -1
- data/lib/pdk/cli/exec/command.rb +12 -14
- data/lib/pdk/cli/exec/interactive_command.rb +11 -11
- data/lib/pdk/cli/exec.rb +4 -4
- data/lib/pdk/cli/exec_group.rb +1 -3
- data/lib/pdk/cli/get/config.rb +5 -5
- data/lib/pdk/cli/get.rb +2 -2
- data/lib/pdk/cli/module/build.rb +3 -3
- data/lib/pdk/cli/module/generate.rb +4 -4
- data/lib/pdk/cli/module.rb +3 -3
- data/lib/pdk/cli/new/class.rb +4 -4
- data/lib/pdk/cli/new/defined_type.rb +4 -4
- data/lib/pdk/cli/new/fact.rb +3 -3
- data/lib/pdk/cli/new/function.rb +4 -4
- data/lib/pdk/cli/new/module.rb +10 -11
- data/lib/pdk/cli/new/provider.rb +3 -3
- data/lib/pdk/cli/new/task.rb +5 -5
- data/lib/pdk/cli/new/test.rb +7 -7
- data/lib/pdk/cli/new/transport.rb +3 -3
- data/lib/pdk/cli/new.rb +3 -3
- data/lib/pdk/cli/release/prep.rb +9 -9
- data/lib/pdk/cli/release/publish.rb +7 -11
- data/lib/pdk/cli/release.rb +35 -39
- data/lib/pdk/cli/remove/config.rb +15 -15
- data/lib/pdk/cli/remove.rb +2 -2
- data/lib/pdk/cli/set/config.rb +16 -16
- data/lib/pdk/cli/set.rb +2 -2
- data/lib/pdk/cli/test/unit.rb +13 -13
- data/lib/pdk/cli/test.rb +2 -2
- data/lib/pdk/cli/update.rb +19 -29
- data/lib/pdk/cli/util/command_redirector.rb +1 -1
- data/lib/pdk/cli/util/interview.rb +4 -4
- data/lib/pdk/cli/util/option_normalizer.rb +2 -2
- data/lib/pdk/cli/util/option_validator.rb +1 -1
- data/lib/pdk/cli/util.rb +19 -20
- data/lib/pdk/cli/validate.rb +16 -18
- data/lib/pdk/cli.rb +16 -33
- data/lib/pdk/config/ini_file_setting.rb +2 -2
- data/lib/pdk/config/json_schema_namespace.rb +3 -3
- data/lib/pdk/config/json_schema_setting.rb +1 -1
- data/lib/pdk/config/json_with_schema.rb +1 -1
- data/lib/pdk/config/namespace.rb +4 -4
- data/lib/pdk/config/setting.rb +5 -5
- data/lib/pdk/config/validator.rb +2 -2
- data/lib/pdk/config/yaml.rb +2 -2
- data/lib/pdk/config/yaml_with_schema.rb +3 -3
- data/lib/pdk/config.rb +18 -20
- data/lib/pdk/context/control_repo.rb +1 -1
- data/lib/pdk/context/module.rb +1 -1
- data/lib/pdk/context/none.rb +1 -1
- data/lib/pdk/generate/module.rb +52 -64
- data/lib/pdk/generate/puppet_object.rb +6 -6
- data/lib/pdk/generate/task.rb +1 -1
- data/lib/pdk/module/build.rb +11 -16
- data/lib/pdk/module/convert.rb +14 -16
- data/lib/pdk/module/metadata.rb +12 -12
- data/lib/pdk/module/release.rb +20 -19
- data/lib/pdk/module/update.rb +5 -5
- data/lib/pdk/module/update_manager.rb +6 -6
- data/lib/pdk/report/event.rb +11 -11
- data/lib/pdk/template/fetcher/git.rb +4 -4
- data/lib/pdk/template/fetcher.rb +1 -1
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +1 -1
- data/lib/pdk/template/renderer/v1/renderer.rb +5 -7
- data/lib/pdk/template/renderer/v1/template_file.rb +3 -1
- data/lib/pdk/template/template_dir.rb +1 -1
- data/lib/pdk/template.rb +2 -2
- data/lib/pdk/tests/unit.rb +12 -12
- data/lib/pdk/util/bundler.rb +14 -14
- data/lib/pdk/util/changelog_generator.rb +6 -8
- data/lib/pdk/util/filesystem.rb +2 -2
- data/lib/pdk/util/git.rb +5 -5
- data/lib/pdk/util/puppet_strings.rb +2 -2
- data/lib/pdk/util/puppet_version.rb +24 -17
- data/lib/pdk/util/ruby_version.rb +2 -5
- data/lib/pdk/util/template_uri.rb +8 -8
- data/lib/pdk/util/vendored_file.rb +3 -3
- data/lib/pdk/util/windows/api_types.rb +3 -4
- data/lib/pdk/util/windows/file.rb +1 -1
- data/lib/pdk/util/windows/process.rb +5 -8
- data/lib/pdk/util.rb +2 -2
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +5 -5
- data/lib/pdk/validate/invokable_validator.rb +6 -6
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +2 -2
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +2 -2
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +38 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +1 -1
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +4 -4
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +2 -5
- data/lib/pdk/validate/validator.rb +1 -1
- data/lib/pdk/validate/validator_group.rb +1 -1
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +4 -4
- data/lib/pdk/validate.rb +2 -1
- data/lib/pdk/version.rb +2 -2
- data/lib/pdk.rb +0 -2
- metadata +32 -54
- data/lib/pdk/i18n.rb +0 -4
- data/locales/config.yaml +0 -21
- data/locales/pdk.pot +0 -2111
data/lib/pdk/module/release.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'pdk'
|
2
|
+
require 'uri'
|
2
3
|
|
3
4
|
module PDK
|
4
5
|
module Module
|
@@ -16,21 +17,21 @@ module PDK
|
|
16
17
|
|
17
18
|
# TODO: Currently the release process can ONLY be run if the working directory IS the module root. However, in the future
|
18
19
|
# this WILL change, so we have the API arguments for it, but only accept `nil` for the first parameter
|
19
|
-
raise PDK::CLI::ExitWithError,
|
20
|
+
raise PDK::CLI::ExitWithError, 'Running the release process outside of the working directory is not supported' unless module_path.nil?
|
20
21
|
|
21
22
|
if module_path.nil?
|
22
23
|
module_path = PDK::Util.module_root
|
23
|
-
raise PDK::CLI::ExitWithError,
|
24
|
+
raise PDK::CLI::ExitWithError, 'The module release process requires a valid module path' % { module_path: module_path } if module_path.nil?
|
24
25
|
end
|
25
|
-
raise PDK::CLI::ExitWithError,
|
26
|
+
raise PDK::CLI::ExitWithError, '%{module_path} is not a valid module' % { module_path: module_path } unless PDK::Util.in_module_root?(module_path)
|
26
27
|
@module_path = module_path
|
27
28
|
end
|
28
29
|
|
29
30
|
def run
|
30
31
|
# Pre-release checks
|
31
32
|
unless force?
|
32
|
-
raise PDK::CLI::ExitWithError,
|
33
|
-
raise PDK::CLI::ExitWithError,
|
33
|
+
raise PDK::CLI::ExitWithError, 'The module is not PDK compatible' if requires_pdk_compatibility? && !pdk_compatible?
|
34
|
+
raise PDK::CLI::ExitWithError, 'The module is not Forge compatible' if requires_forge_compatibility? && !forge_compatible?
|
34
35
|
end
|
35
36
|
|
36
37
|
# Note that these checks are duplicated in the run_publish method, however it's a much better
|
@@ -40,7 +41,7 @@ module PDK
|
|
40
41
|
|
41
42
|
run_validations(options) unless skip_validation?
|
42
43
|
|
43
|
-
PDK.logger.info
|
44
|
+
PDK.logger.info 'Releasing %{module_name} - from version %{module_version}' % {
|
44
45
|
module_name: module_metadata.data['name'],
|
45
46
|
module_version: module_metadata.data['version'],
|
46
47
|
}
|
@@ -55,7 +56,7 @@ module PDK
|
|
55
56
|
new_version = module_metadata.data['version'] if new_version.nil?
|
56
57
|
|
57
58
|
if new_version != module_metadata.data['version']
|
58
|
-
PDK.logger.info
|
59
|
+
PDK.logger.info 'Updating version to %{module_version}' % {
|
59
60
|
module_version: new_version,
|
60
61
|
}
|
61
62
|
|
@@ -69,7 +70,7 @@ module PDK
|
|
69
70
|
# Check if the versions match
|
70
71
|
latest_version = PDK::Util::ChangelogGenerator.latest_version
|
71
72
|
unless latest_version
|
72
|
-
raise PDK::CLI::ExitWithError,
|
73
|
+
raise PDK::CLI::ExitWithError, '%{new_version} does not match %{latest_version}' % { new_version: new_version, latest_version: latest_version } if new_version != latest_version
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
@@ -118,26 +119,26 @@ module PDK
|
|
118
119
|
PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
|
119
120
|
|
120
121
|
validator_exit_code, = PDK::Validate.invoke_validators_by_name(PDK.context, PDK::Validate.validator_names, false, options)
|
121
|
-
raise PDK::CLI::ExitWithError,
|
122
|
+
raise PDK::CLI::ExitWithError, 'An error occured during validation' unless validator_exit_code.zero?
|
122
123
|
end
|
123
124
|
|
124
125
|
def run_documentation(_opts)
|
125
|
-
PDK.logger.info
|
126
|
+
PDK.logger.info 'Updating documentation using puppet strings'
|
126
127
|
docs_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'exec', 'puppet', 'strings', 'generate', '--format', 'markdown', '--out', 'REFERENCE.md')
|
127
128
|
docs_command.context = :module
|
128
129
|
result = docs_command.execute!
|
129
|
-
raise PDK::CLI::ExitWithError,
|
130
|
+
raise PDK::CLI::ExitWithError, 'An error occured generating the module documentation: %{stdout}' % { stdout: result[:stdout] } unless result[:exit_code].zero?
|
130
131
|
end
|
131
132
|
|
132
133
|
def run_dependency_checker(_opts)
|
133
134
|
# run dependency-checker and output dependent modules list
|
134
|
-
PDK.logger.info
|
135
|
+
PDK.logger.info 'Running dependency checks'
|
135
136
|
|
136
137
|
dep_command = PDK::CLI::Exec::Command.new('dependency-checker', 'metadata.json')
|
137
138
|
dep_command.context = :module
|
138
139
|
result = dep_command.execute!
|
139
140
|
|
140
|
-
raise PDK::CLI::ExitWithError,
|
141
|
+
raise PDK::CLI::ExitWithError, 'An error occured checking the module dependencies: %{stdout}' % { stdout: result[:stdout] } unless result[:exit_code].zero?
|
141
142
|
end
|
142
143
|
|
143
144
|
# @return [String] Path to the built tarball
|
@@ -147,13 +148,13 @@ module PDK
|
|
147
148
|
|
148
149
|
def run_publish(_opts, tarball_path)
|
149
150
|
validate_publish_options!
|
150
|
-
raise PDK::CLI::ExitWithError,
|
151
|
+
raise PDK::CLI::ExitWithError, 'Module tarball %{tarball_path} does not exist' % { tarball_path: tarball_path } unless PDK::Util::Filesystem.file?(tarball_path)
|
151
152
|
|
152
153
|
# TODO: Replace this code when the upload functionality is added to the forge ruby gem
|
153
154
|
require 'base64'
|
154
155
|
file_data = Base64.encode64(PDK::Util::Filesystem.read_file(tarball_path, open_args: 'rb'))
|
155
156
|
|
156
|
-
PDK.logger.info
|
157
|
+
PDK.logger.info 'Uploading tarball to puppet forge...'
|
157
158
|
uri = URI(forge_upload_url)
|
158
159
|
require 'net/http'
|
159
160
|
request = Net::HTTP::Post.new(uri.path)
|
@@ -169,14 +170,14 @@ module PDK
|
|
169
170
|
http.request(request)
|
170
171
|
end
|
171
172
|
|
172
|
-
raise PDK::CLI::ExitWithError,
|
173
|
-
PDK.logger.info
|
173
|
+
raise PDK::CLI::ExitWithError, 'Error uploading to Puppet Forge: %{result}' % { result: response.body } unless response.is_a?(Net::HTTPSuccess)
|
174
|
+
PDK.logger.info 'Publish to Forge was successful'
|
174
175
|
end
|
175
176
|
|
176
177
|
def validate_publish_options!
|
177
178
|
return if skip_publish?
|
178
|
-
raise PDK::CLI::ExitWithError,
|
179
|
-
raise PDK::CLI::ExitWithError,
|
179
|
+
raise PDK::CLI::ExitWithError, 'Missing forge-upload-url option' unless forge_upload_url
|
180
|
+
raise PDK::CLI::ExitWithError, 'Missing forge-token option' unless forge_token
|
180
181
|
end
|
181
182
|
|
182
183
|
def force?
|
data/lib/pdk/module/update.rb
CHANGED
@@ -11,13 +11,13 @@ module PDK
|
|
11
11
|
stage_changes!
|
12
12
|
|
13
13
|
if current_version == new_version
|
14
|
-
PDK.logger.debug
|
14
|
+
PDK.logger.debug 'This module is already up to date with version %{version} of the template.' % {
|
15
15
|
version: new_version,
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
19
|
unless update_manager.changes?
|
20
|
-
PDK::Report.default_target.puts(
|
20
|
+
PDK::Report.default_target.puts('No changes required.')
|
21
21
|
return
|
22
22
|
end
|
23
23
|
|
@@ -29,7 +29,7 @@ module PDK
|
|
29
29
|
return if noop?
|
30
30
|
|
31
31
|
unless force?
|
32
|
-
message =
|
32
|
+
message = 'Do you want to continue and make these changes to your module?'
|
33
33
|
return unless PDK::CLI::Util.prompt_for_yes(message)
|
34
34
|
end
|
35
35
|
|
@@ -114,9 +114,9 @@ module PDK
|
|
114
114
|
|
115
115
|
def update_message
|
116
116
|
format_string = if template_uri.default?
|
117
|
-
|
117
|
+
'Updating %{module_name} using the default template, from %{current_version} to %{new_version}'
|
118
118
|
else
|
119
|
-
|
119
|
+
'Updating %{module_name} using the template at %{template_url}, from %{current_version} to %{new_version}'
|
120
120
|
end
|
121
121
|
|
122
122
|
format_string % {
|
@@ -115,13 +115,13 @@ module PDK
|
|
115
115
|
require 'pdk/util/filesystem'
|
116
116
|
|
117
117
|
if PDK::Util::Filesystem.file?(path)
|
118
|
-
PDK.logger.debug(
|
118
|
+
PDK.logger.debug("unlinking '%{path}'" % { path: path })
|
119
119
|
PDK::Util::Filesystem.rm(path)
|
120
120
|
else
|
121
|
-
PDK.logger.debug(
|
121
|
+
PDK.logger.debug("'%{path}': already gone" % { path: path })
|
122
122
|
end
|
123
123
|
rescue => e
|
124
|
-
raise PDK::CLI::ExitWithError,
|
124
|
+
raise PDK::CLI::ExitWithError, "Unable to remove '%{path}': %{message}" % {
|
125
125
|
path: path,
|
126
126
|
message: e.message,
|
127
127
|
}
|
@@ -141,7 +141,7 @@ module PDK
|
|
141
141
|
next if @diff_cache.key?(file[:path])
|
142
142
|
|
143
143
|
unless PDK::Util::Filesystem.readable?(file[:path])
|
144
|
-
raise PDK::CLI::ExitWithError,
|
144
|
+
raise PDK::CLI::ExitWithError, "Unable to open '%{path}' for reading" % { path: file[:path] }
|
145
145
|
end
|
146
146
|
|
147
147
|
old_content = PDK::Util::Filesystem.read_file(file[:path])
|
@@ -160,10 +160,10 @@ module PDK
|
|
160
160
|
require 'pdk/util/filesystem'
|
161
161
|
|
162
162
|
PDK::Util::Filesystem.mkdir_p(File.dirname(path))
|
163
|
-
PDK.logger.debug(
|
163
|
+
PDK.logger.debug("writing '%{path}'" % { path: path })
|
164
164
|
PDK::Util::Filesystem.write_file(path, content)
|
165
165
|
rescue Errno::EACCES
|
166
|
-
raise PDK::CLI::ExitWithError,
|
166
|
+
raise PDK::CLI::ExitWithError, "You do not have permission to write to '%{path}'" % { path: path }
|
167
167
|
end
|
168
168
|
|
169
169
|
# Generate a unified diff of the changes to be made to a file.
|
data/lib/pdk/report/event.rb
CHANGED
@@ -195,11 +195,11 @@ module PDK
|
|
195
195
|
# a String.
|
196
196
|
def sanitise_file(value)
|
197
197
|
if value.nil? || (value.is_a?(String) && value.empty?)
|
198
|
-
raise ArgumentError,
|
198
|
+
raise ArgumentError, 'File not specified.'
|
199
199
|
end
|
200
200
|
|
201
201
|
unless value.is_a?(String)
|
202
|
-
raise ArgumentError,
|
202
|
+
raise ArgumentError, 'File must be a String.'
|
203
203
|
end
|
204
204
|
|
205
205
|
require 'pathname'
|
@@ -235,17 +235,17 @@ module PDK
|
|
235
235
|
# a String or Symbol representation of a valid state.
|
236
236
|
def sanitise_state(value)
|
237
237
|
if value.nil? || (value.is_a?(String) && value.empty?)
|
238
|
-
raise ArgumentError,
|
238
|
+
raise ArgumentError, 'State not specified.'
|
239
239
|
end
|
240
240
|
|
241
241
|
value = value.to_sym if value.is_a?(String)
|
242
242
|
unless value.is_a?(Symbol)
|
243
|
-
raise ArgumentError,
|
243
|
+
raise ArgumentError, 'State must be a Symbol, not %{type}' % { type: value.class }
|
244
244
|
end
|
245
245
|
|
246
246
|
valid_states = [:passed, :error, :failure, :skipped]
|
247
247
|
unless valid_states.include?(value)
|
248
|
-
raise ArgumentError,
|
248
|
+
raise ArgumentError, 'Invalid state %{state}. Valid states are: %{valid}.' % {
|
249
249
|
state: value.inspect,
|
250
250
|
valid: valid_states.map(&:inspect).join(', '),
|
251
251
|
}
|
@@ -264,7 +264,7 @@ module PDK
|
|
264
264
|
# @raise [ArgumentError] if the value is nil or an empty String.
|
265
265
|
def sanitise_source(value)
|
266
266
|
if value.nil? || (value.is_a?(String) && value.empty?)
|
267
|
-
raise ArgumentError,
|
267
|
+
raise ArgumentError, 'Source not specified.'
|
268
268
|
end
|
269
269
|
|
270
270
|
value.to_s
|
@@ -285,11 +285,11 @@ module PDK
|
|
285
285
|
end
|
286
286
|
|
287
287
|
unless valid_types.include?(value.class)
|
288
|
-
raise ArgumentError,
|
288
|
+
raise ArgumentError, 'Line must be an Integer or a String representation of an Integer.'
|
289
289
|
end
|
290
290
|
|
291
291
|
if value.is_a?(String) && value !~ %r{\A[0-9]+\Z}
|
292
|
-
raise ArgumentError,
|
292
|
+
raise ArgumentError, 'The line number can contain only the digits 0-9.'
|
293
293
|
end
|
294
294
|
|
295
295
|
value.to_i
|
@@ -310,11 +310,11 @@ module PDK
|
|
310
310
|
end
|
311
311
|
|
312
312
|
unless valid_types.include?(value.class)
|
313
|
-
raise ArgumentError,
|
313
|
+
raise ArgumentError, 'Column must be an Integer or a String representation of an Integer.'
|
314
314
|
end
|
315
315
|
|
316
316
|
if value.is_a?(String) && value !~ %r{\A[0-9]+\Z}
|
317
|
-
raise ArgumentError,
|
317
|
+
raise ArgumentError, 'The column number can contain only the digits 0-9.'
|
318
318
|
end
|
319
319
|
|
320
320
|
value.to_i
|
@@ -332,7 +332,7 @@ module PDK
|
|
332
332
|
valid_types = [Array]
|
333
333
|
|
334
334
|
unless valid_types.include?(value.class)
|
335
|
-
raise ArgumentError,
|
335
|
+
raise ArgumentError, 'Trace must be an Array of stack trace lines.'
|
336
336
|
end
|
337
337
|
|
338
338
|
# Drop any stacktrace lines that include '/gems/' in the path or
|
@@ -22,7 +22,7 @@ module PDK
|
|
22
22
|
# We don't do a checkout of local-path repos. There are lots of edge
|
23
23
|
# cases or user un-expectations.
|
24
24
|
if PDK::Util::Git.work_tree?(uri.shell_path)
|
25
|
-
PDK.logger.warn
|
25
|
+
PDK.logger.warn "Repository '%{repo}' has a work-tree; skipping git reset." % {
|
26
26
|
repo: uri.shell_path,
|
27
27
|
}
|
28
28
|
@path = uri.shell_path
|
@@ -49,7 +49,7 @@ module PDK
|
|
49
49
|
unless clone_result[:exit_code].zero?
|
50
50
|
PDK.logger.error clone_result[:stdout]
|
51
51
|
PDK.logger.error clone_result[:stderr]
|
52
|
-
raise PDK::CLI::FatalError,
|
52
|
+
raise PDK::CLI::FatalError, "Unable to clone git repository at '%{repo}' into '%{dest}'." % { repo: origin_repo, dest: temp_dir }
|
53
53
|
end
|
54
54
|
@path = PDK::Util.canonical_path(temp_dir)
|
55
55
|
|
@@ -63,10 +63,10 @@ module PDK
|
|
63
63
|
|
64
64
|
PDK.logger.error reset_result[:stdout]
|
65
65
|
PDK.logger.error reset_result[:stderr]
|
66
|
-
raise PDK::CLI::FatalError,
|
66
|
+
raise PDK::CLI::FatalError, "Unable to checkout '%{ref}' of git repository at '%{path}'." % { ref: git_ref, path: temp_dir }
|
67
67
|
end
|
68
68
|
else
|
69
|
-
PDK.logger.warn
|
69
|
+
PDK.logger.warn "Uncommitted changes found when attempting to checkout '%{ref}' of git repository at '%{path}'; skipping git reset." % { ref: git_ref, path: temp_dir }
|
70
70
|
@metadata['template-ref'] = describe_path_and_ref(temp_dir)
|
71
71
|
end
|
72
72
|
end
|
data/lib/pdk/template/fetcher.rb
CHANGED
@@ -35,7 +35,7 @@ module PDK
|
|
35
35
|
# @raise [ArgumentError] If no block is given to this method.
|
36
36
|
# @return [void]
|
37
37
|
def self.with(uri, options = {})
|
38
|
-
raise ArgumentError,
|
38
|
+
raise ArgumentError, '%{class_name}.with must be passed a block.' % { class_name: name } unless block_given?
|
39
39
|
fetcher = instance(uri, options)
|
40
40
|
|
41
41
|
begin
|
@@ -93,7 +93,7 @@ module PDK
|
|
93
93
|
begin
|
94
94
|
YAML.safe_load(PDK::Util::Filesystem.read_file(loc), [], [], true)
|
95
95
|
rescue Psych::SyntaxError => e
|
96
|
-
PDK.logger.warn
|
96
|
+
PDK.logger.warn "'%{file}' is not a valid YAML file: %{problem} %{context} at line %{line} column %{column}" % {
|
97
97
|
file: loc,
|
98
98
|
problem: e.problem,
|
99
99
|
context: e.context,
|
@@ -21,7 +21,7 @@ module PDK
|
|
21
21
|
template_file = single_item_path(relative_file_path)
|
22
22
|
return nil unless PDK::Util::Filesystem.file?(template_file) && PDK::Util::Filesystem.readable?(template_file)
|
23
23
|
|
24
|
-
PDK.logger.debug(
|
24
|
+
PDK.logger.debug("Rendering '%{template}'..." % { template: template_file })
|
25
25
|
new_template_file(template_file, template_data_hash).render
|
26
26
|
end
|
27
27
|
|
@@ -71,7 +71,7 @@ module PDK
|
|
71
71
|
|
72
72
|
files_in_template(dirs).each do |template_file, template_loc|
|
73
73
|
template_file = template_file.to_s
|
74
|
-
PDK.logger.debug(
|
74
|
+
PDK.logger.debug("Rendering '%{template}'..." % { template: template_file })
|
75
75
|
dest_path = template_file.sub(%r{\.erb\Z}, '')
|
76
76
|
config = legacy_template_dir.config_for(dest_path)
|
77
77
|
|
@@ -89,10 +89,8 @@ module PDK
|
|
89
89
|
begin
|
90
90
|
dest_content = new_template_file(File.join(template_loc, template_file), configs: config, template_dir: legacy_template_dir).render
|
91
91
|
rescue => error
|
92
|
-
error_msg =
|
93
|
-
|
94
|
-
'%{exception}: %{message}',
|
95
|
-
) % { template: template_file, exception: error.class, message: error.message }
|
92
|
+
error_msg = "Failed to render template '%{template}'\n" \
|
93
|
+
'%{exception}: %{message}' % { template: template_file, exception: error.class, message: error.message }
|
96
94
|
raise PDK::CLI::FatalError, error_msg
|
97
95
|
end
|
98
96
|
end
|
@@ -113,7 +111,7 @@ module PDK
|
|
113
111
|
temp_paths = []
|
114
112
|
dirlocs = []
|
115
113
|
dirs.each do |dir|
|
116
|
-
raise ArgumentError,
|
114
|
+
raise ArgumentError, "The directory '%{dir}' doesn't exist" % { dir: dir } unless PDK::Util::Filesystem.directory?(dir)
|
117
115
|
temp_paths += PDK::Util::Filesystem.glob(File.join(dir, *glob_suffix), File::FNM_DOTMATCH).select do |template_path|
|
118
116
|
if PDK::Util::Filesystem.file?(template_path) && !PDK::Util::Filesystem.symlink?(template_path)
|
119
117
|
dirlocs << dir
|
@@ -69,7 +69,7 @@ module PDK
|
|
69
69
|
return PDK::Util::Filesystem.read_file(@template_file)
|
70
70
|
end
|
71
71
|
|
72
|
-
raise ArgumentError,
|
72
|
+
raise ArgumentError, "'%{template}' is not a readable file" % { template: @template_file }
|
73
73
|
end
|
74
74
|
|
75
75
|
# Renders the content of the template file as an ERB template.
|
@@ -80,6 +80,8 @@ module PDK
|
|
80
80
|
#
|
81
81
|
# @api private
|
82
82
|
def render_erb
|
83
|
+
require 'erb'
|
84
|
+
|
83
85
|
renderer = ERB.new(template_content, nil, '-')
|
84
86
|
renderer.filename = @template_file
|
85
87
|
renderer.result(binding)
|
@@ -36,7 +36,7 @@ module PDK
|
|
36
36
|
@metadata = {}
|
37
37
|
|
38
38
|
@renderer = renderer.nil? ? Renderer.instance(uri, path, context) : renderer
|
39
|
-
raise
|
39
|
+
raise 'Could not find a compatible template renderer for %{path}' % { path: path } if @renderer.nil?
|
40
40
|
end
|
41
41
|
|
42
42
|
# Later additions may include Control Repo rendering, for example
|
data/lib/pdk/template.rb
CHANGED
@@ -38,10 +38,10 @@ module PDK
|
|
38
38
|
# @api public
|
39
39
|
def self.with(uri, context)
|
40
40
|
unless block_given?
|
41
|
-
raise ArgumentError,
|
41
|
+
raise ArgumentError, '%{class_name}.with must be passed a block.' % { class_name: name }
|
42
42
|
end
|
43
43
|
unless uri.is_a? PDK::Util::TemplateURI
|
44
|
-
raise ArgumentError,
|
44
|
+
raise ArgumentError, '%{class_name}.with must be passed a PDK::Util::TemplateURI, got a %{uri_type}' % { uri_type: uri.class, class_name: name }
|
45
45
|
end
|
46
46
|
|
47
47
|
Fetcher.with(uri) do |fetcher|
|
data/lib/pdk/tests/unit.rb
CHANGED
@@ -61,23 +61,23 @@ module PDK
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.tear_down
|
64
|
-
result = rake('spec_clean',
|
64
|
+
result = rake('spec_clean', 'Cleaning up after running unit tests.')
|
65
65
|
|
66
66
|
return if result[:exit_code].zero?
|
67
67
|
|
68
|
-
PDK.logger.error(
|
69
|
-
print_failure(result,
|
68
|
+
PDK.logger.error('The spec_clean rake task failed with the following error(s):')
|
69
|
+
print_failure(result, 'Failed to clean up after running unit tests')
|
70
70
|
end
|
71
71
|
|
72
72
|
def self.setup
|
73
|
-
result = rake('spec_prep',
|
73
|
+
result = rake('spec_prep', 'Preparing to run the unit tests.')
|
74
74
|
|
75
75
|
return if result[:exit_code].zero?
|
76
76
|
|
77
77
|
tear_down
|
78
78
|
|
79
|
-
PDK.logger.error(
|
80
|
-
print_failure(result,
|
79
|
+
PDK.logger.error('The spec_prep rake task failed with the following error(s):')
|
80
|
+
print_failure(result, 'Failed to prepare to run the unit tests.')
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.invoke(report, options = {})
|
@@ -97,7 +97,7 @@ module PDK
|
|
97
97
|
|
98
98
|
environment = { 'CI_SPEC_OPTIONS' => '--format j' }
|
99
99
|
environment['PUPPET_GEM_VERSION'] = options[:puppet] if options[:puppet]
|
100
|
-
spinner_msg = options[:parallel] ?
|
100
|
+
spinner_msg = options[:parallel] ? 'Running unit tests in parallel.' : 'Running unit tests.'
|
101
101
|
|
102
102
|
if options[:interactive]
|
103
103
|
environment['CI_SPEC_OPTIONS'] = if options[:verbose]
|
@@ -122,7 +122,7 @@ module PDK
|
|
122
122
|
result[:exit_code] = 0
|
123
123
|
end
|
124
124
|
|
125
|
-
raise PDK::CLI::FatalError,
|
125
|
+
raise PDK::CLI::FatalError, 'Unit test output did not contain a valid JSON result: %{output}' % { output: result[:stdout] } if json_result.nil? || json_result.empty?
|
126
126
|
|
127
127
|
json_result = merge_json_results(json_result) if options[:parallel]
|
128
128
|
|
@@ -174,7 +174,7 @@ module PDK
|
|
174
174
|
return unless json_data['summary']
|
175
175
|
|
176
176
|
# TODO: standardize summary output
|
177
|
-
$stderr.puts ' ' <<
|
177
|
+
$stderr.puts ' ' << 'Evaluated %{total} tests in %{duration} seconds: %{failures} failures, %{pending} pending.' % {
|
178
178
|
total: json_data['summary']['example_count'],
|
179
179
|
duration: duration,
|
180
180
|
failures: json_data['summary']['failure_count'],
|
@@ -230,15 +230,15 @@ module PDK
|
|
230
230
|
environment = {}
|
231
231
|
environment['PUPPET_GEM_VERSION'] = options[:puppet] if options[:puppet]
|
232
232
|
|
233
|
-
output = rake('spec_list_json',
|
233
|
+
output = rake('spec_list_json', 'Finding unit tests.', environment)
|
234
234
|
|
235
235
|
rspec_json = PDK::Util.find_first_json_in(output[:stdout])
|
236
|
-
raise PDK::CLI::FatalError,
|
236
|
+
raise PDK::CLI::FatalError, 'Failed to find valid JSON in output from rspec: %{output}' % { output: output[:stdout] } unless rspec_json
|
237
237
|
if rspec_json['examples'].empty?
|
238
238
|
rspec_message = rspec_json['messages'][0]
|
239
239
|
return [] if rspec_message == 'No examples found.'
|
240
240
|
|
241
|
-
raise PDK::CLI::FatalError,
|
241
|
+
raise PDK::CLI::FatalError, 'Unable to enumerate examples. rspec reported: %{message}' % { message: rspec_message }
|
242
242
|
else
|
243
243
|
examples = []
|
244
244
|
rspec_json['examples'].each do |example|
|
data/lib/pdk/util/bundler.rb
CHANGED
@@ -12,12 +12,12 @@ module PDK
|
|
12
12
|
gem_overrides ||= { puppet: nil, hiera: nil, facter: nil }
|
13
13
|
|
14
14
|
if already_bundled?(bundle.gemfile, gem_overrides)
|
15
|
-
PDK.logger.debug(
|
15
|
+
PDK.logger.debug('Bundler managed gems already up to date.')
|
16
16
|
return
|
17
17
|
end
|
18
18
|
|
19
19
|
unless bundle.gemfile?
|
20
|
-
PDK.logger.debug(
|
20
|
+
PDK.logger.debug("No Gemfile found in '%{cwd}'. Skipping bundler management." % { cwd: Dir.pwd })
|
21
21
|
return
|
22
22
|
end
|
23
23
|
|
@@ -93,7 +93,7 @@ module PDK
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def installed?(gem_overrides = {})
|
96
|
-
PDK.logger.debug(
|
96
|
+
PDK.logger.debug('Checking for missing Gemfile dependencies.')
|
97
97
|
|
98
98
|
argv = ['check', "--gemfile=#{gemfile}", '--dry-run']
|
99
99
|
|
@@ -123,25 +123,25 @@ module PDK
|
|
123
123
|
end
|
124
124
|
|
125
125
|
unless vendored_gemfile_lock
|
126
|
-
raise PDK::CLI::FatalError,
|
126
|
+
raise PDK::CLI::FatalError, 'Vendored Gemfile.lock (%{source}) not found.' % {
|
127
127
|
source: vendored_gemfile_lock,
|
128
128
|
}
|
129
129
|
end
|
130
130
|
|
131
|
-
PDK.logger.debug(
|
131
|
+
PDK.logger.debug('Using vendored Gemfile.lock from %{source}.' % { source: vendored_gemfile_lock })
|
132
132
|
PDK::Util::Filesystem.cp(vendored_gemfile_lock, File.join(PDK::Util.module_root, 'Gemfile.lock'))
|
133
133
|
else
|
134
134
|
argv = ['lock']
|
135
135
|
|
136
136
|
cmd = bundle_command(*argv).tap do |c|
|
137
|
-
c.add_spinner(
|
137
|
+
c.add_spinner('Resolving default Gemfile dependencies.')
|
138
138
|
end
|
139
139
|
|
140
140
|
result = cmd.execute!
|
141
141
|
|
142
142
|
unless result[:exit_code].zero?
|
143
143
|
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
144
|
-
raise PDK::CLI::FatalError,
|
144
|
+
raise PDK::CLI::FatalError, 'Unable to resolve default Gemfile dependencies.'
|
145
145
|
end
|
146
146
|
|
147
147
|
# After initial lockfile generation, re-resolve json gem to built-in
|
@@ -154,7 +154,7 @@ module PDK
|
|
154
154
|
end
|
155
155
|
|
156
156
|
def update_lock!(options = {})
|
157
|
-
PDK.logger.debug(
|
157
|
+
PDK.logger.debug('Updating Gemfile dependencies.')
|
158
158
|
|
159
159
|
argv = ['lock', "--lockfile=#{gemfile_lock}", '--update']
|
160
160
|
|
@@ -182,7 +182,7 @@ module PDK
|
|
182
182
|
|
183
183
|
unless result[:exit_code].zero?
|
184
184
|
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
185
|
-
raise PDK::CLI::FatalError,
|
185
|
+
raise PDK::CLI::FatalError, 'Unable to resolve Gemfile dependencies.'
|
186
186
|
end
|
187
187
|
|
188
188
|
true
|
@@ -195,7 +195,7 @@ module PDK
|
|
195
195
|
argv << '-j4' unless Gem.win_platform? && Gem::Version.new(PDK::Util::RubyVersion.active_ruby_version) < Gem::Version.new('2.3.5')
|
196
196
|
|
197
197
|
cmd = bundle_command(*argv).tap do |c|
|
198
|
-
c.add_spinner(
|
198
|
+
c.add_spinner('Installing missing Gemfile dependencies.')
|
199
199
|
c.update_environment(gemfile_env(gem_overrides)) unless gem_overrides.empty?
|
200
200
|
end
|
201
201
|
|
@@ -203,14 +203,14 @@ module PDK
|
|
203
203
|
|
204
204
|
unless result[:exit_code].zero?
|
205
205
|
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
206
|
-
raise PDK::CLI::FatalError,
|
206
|
+
raise PDK::CLI::FatalError, 'Unable to install missing Gemfile dependencies.'
|
207
207
|
end
|
208
208
|
|
209
209
|
true
|
210
210
|
end
|
211
211
|
|
212
212
|
def binstubs!(gems)
|
213
|
-
raise PDK::CLI::FatalError,
|
213
|
+
raise PDK::CLI::FatalError, 'Unable to install requested binstubs as the Gemfile is missing' if gemfile.nil?
|
214
214
|
binstub_dir = File.join(File.dirname(gemfile), 'bin')
|
215
215
|
return true if gems.all? { |gem| PDK::Util::Filesystem.file?(File.join(binstub_dir, gem)) }
|
216
216
|
|
@@ -218,8 +218,8 @@ module PDK
|
|
218
218
|
result = cmd.execute!
|
219
219
|
|
220
220
|
unless result[:exit_code].zero?
|
221
|
-
PDK.logger.fatal(
|
222
|
-
raise PDK::CLI::FatalError,
|
221
|
+
PDK.logger.fatal("Failed to generate binstubs for '%{gems}':\n%{output}" % { gems: gems.join(' '), output: result.values_at(:stdout, :stderr).join("\n") }) unless PDK.logger.debug?
|
222
|
+
raise PDK::CLI::FatalError, 'Unable to install requested binstubs.'
|
223
223
|
end
|
224
224
|
|
225
225
|
true
|
@@ -9,16 +9,14 @@ module PDK
|
|
9
9
|
|
10
10
|
# Raises if the github_changelog_generator is not available
|
11
11
|
def self.github_changelog_generator_available!
|
12
|
-
check_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, '
|
12
|
+
check_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'info', 'github_changelog_generator')
|
13
13
|
check_command.context = :module
|
14
14
|
|
15
15
|
result = check_command.execute!
|
16
16
|
|
17
17
|
return if result[:exit_code].zero?
|
18
18
|
|
19
|
-
raise PDK::CLI::ExitWithError,
|
20
|
-
'Unable to generate the changelog as the %{gem} gem is not included in this module\'s Gemfile',
|
21
|
-
) % { gem: GEM }
|
19
|
+
raise PDK::CLI::ExitWithError, 'Unable to generate the changelog as the %{gem} gem is not included in this module\'s Gemfile' % { gem: GEM }
|
22
20
|
end
|
23
21
|
|
24
22
|
# Runs the Changelog Generator gem (in the module's context) to automatically create a CHANGLELOG.MD file
|
@@ -31,11 +29,11 @@ module PDK
|
|
31
29
|
changelog_command.context = :module
|
32
30
|
|
33
31
|
result = changelog_command.execute!
|
34
|
-
raise PDK::CLI::ExitWithError,
|
32
|
+
raise PDK::CLI::ExitWithError, 'Error generating changelog: %{stdout}' % { stdout: result[:stdout] } unless result[:exit_code].zero?
|
35
33
|
|
36
34
|
output = changelog_content
|
37
35
|
|
38
|
-
raise PDK::CLI::ExitWithError,
|
36
|
+
raise PDK::CLI::ExitWithError, 'The generated changelog contains uncategorized Pull Requests. Please label them and try again. See %{changelog_file} for more details' % { changelog_file: changelog_file } if output =~ %r{UNCATEGORIZED PRS; GO LABEL THEM} # rubocop:disable Metrics/LineLength
|
39
37
|
output
|
40
38
|
end
|
41
39
|
|
@@ -44,9 +42,9 @@ module PDK
|
|
44
42
|
# @param current_version [String, Gem::Version] The current version of the module
|
45
43
|
# @return [String] The new version. May be the same as the current version if there are no notable changes
|
46
44
|
def self.compute_next_version(current_version)
|
47
|
-
raise PDK::CLI::ExitWithError,
|
45
|
+
raise PDK::CLI::ExitWithError, 'Invalid version string %{version}' % { version: current_version } unless current_version =~ VERSION_REGEX
|
48
46
|
version = Gem::Version.create(current_version).segments
|
49
|
-
PDK.logger.info
|
47
|
+
PDK.logger.info 'Determing the target version from \'%{file}\'' % { file: changelog_file }
|
50
48
|
|
51
49
|
# Grab all lines that start with ## between from the latest changes
|
52
50
|
# For example given the changelog below
|