pdk 1.16.0 → 2.1.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 +167 -11
- data/README.md +1 -1
- data/lib/pdk.rb +26 -19
- data/lib/pdk/answer_file.rb +2 -93
- data/lib/pdk/cli.rb +8 -6
- data/lib/pdk/cli/config.rb +3 -1
- data/lib/pdk/cli/config/get.rb +3 -1
- data/lib/pdk/cli/convert.rb +7 -9
- data/lib/pdk/cli/env.rb +52 -0
- data/lib/pdk/cli/exec/command.rb +13 -0
- data/lib/pdk/cli/exec_group.rb +78 -43
- data/lib/pdk/cli/get.rb +20 -0
- data/lib/pdk/cli/get/config.rb +24 -0
- data/lib/pdk/cli/new.rb +2 -0
- data/lib/pdk/cli/new/class.rb +2 -1
- data/lib/pdk/cli/new/defined_type.rb +2 -1
- data/lib/pdk/cli/new/fact.rb +29 -0
- data/lib/pdk/cli/new/function.rb +29 -0
- data/lib/pdk/cli/new/provider.rb +2 -1
- data/lib/pdk/cli/new/task.rb +2 -1
- data/lib/pdk/cli/new/test.rb +2 -1
- data/lib/pdk/cli/new/transport.rb +2 -1
- data/lib/pdk/cli/release/publish.rb +11 -1
- data/lib/pdk/cli/remove.rb +20 -0
- data/lib/pdk/cli/remove/config.rb +80 -0
- data/lib/pdk/cli/set.rb +20 -0
- data/lib/pdk/cli/set/config.rb +119 -0
- data/lib/pdk/cli/update.rb +6 -8
- data/lib/pdk/cli/util.rb +7 -3
- data/lib/pdk/cli/util/option_validator.rb +6 -0
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -0
- data/lib/pdk/cli/validate.rb +26 -44
- data/lib/pdk/config.rb +264 -7
- data/lib/pdk/config/ini_file.rb +183 -0
- data/lib/pdk/config/ini_file_setting.rb +39 -0
- data/lib/pdk/config/namespace.rb +25 -5
- data/lib/pdk/config/setting.rb +3 -2
- data/lib/pdk/context.rb +99 -0
- data/lib/pdk/context/control_repo.rb +60 -0
- data/lib/pdk/context/module.rb +28 -0
- data/lib/pdk/context/none.rb +22 -0
- data/lib/pdk/control_repo.rb +40 -0
- data/lib/pdk/generate/defined_type.rb +25 -32
- data/lib/pdk/generate/fact.rb +25 -0
- data/lib/pdk/generate/function.rb +48 -0
- data/lib/pdk/generate/module.rb +14 -17
- data/lib/pdk/generate/provider.rb +15 -64
- data/lib/pdk/generate/puppet_class.rb +25 -31
- data/lib/pdk/generate/puppet_object.rb +83 -187
- data/lib/pdk/generate/task.rb +28 -46
- data/lib/pdk/generate/transport.rb +20 -74
- data/lib/pdk/module.rb +1 -1
- data/lib/pdk/module/convert.rb +43 -23
- data/lib/pdk/module/metadata.rb +6 -2
- data/lib/pdk/module/release.rb +3 -9
- data/lib/pdk/module/update.rb +7 -11
- data/lib/pdk/module/update_manager.rb +7 -0
- data/lib/pdk/report.rb +3 -3
- data/lib/pdk/report/event.rb +8 -2
- data/lib/pdk/template.rb +59 -0
- data/lib/pdk/template/fetcher.rb +98 -0
- data/lib/pdk/template/fetcher/git.rb +85 -0
- data/lib/pdk/template/fetcher/local.rb +28 -0
- data/lib/pdk/template/renderer.rb +96 -0
- data/lib/pdk/template/renderer/v1.rb +25 -0
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -0
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -0
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -0
- data/lib/pdk/template/template_dir.rb +67 -0
- data/lib/pdk/tests/unit.rb +8 -1
- data/lib/pdk/util.rb +38 -39
- data/lib/pdk/util/bundler.rb +2 -1
- data/lib/pdk/util/changelog_generator.rb +11 -2
- data/lib/pdk/util/json_finder.rb +84 -0
- data/lib/pdk/util/puppet_strings.rb +3 -3
- data/lib/pdk/util/puppet_version.rb +2 -2
- data/lib/pdk/util/ruby_version.rb +5 -1
- data/lib/pdk/util/template_uri.rb +13 -14
- data/lib/pdk/util/vendored_file.rb +1 -2
- data/lib/pdk/validate.rb +79 -25
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -0
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -0
- data/lib/pdk/validate/external_command_validator.rb +208 -0
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -0
- data/lib/pdk/validate/invokable_validator.rb +220 -0
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -0
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -0
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -0
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -0
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -0
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -0
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -0
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -0
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -0
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -0
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -0
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -0
- data/lib/pdk/validate/validator.rb +118 -0
- data/lib/pdk/validate/validator_group.rb +104 -0
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -0
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -0
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +477 -313
- metadata +77 -35
- data/lib/pdk/module/template_dir.rb +0 -115
- data/lib/pdk/module/template_dir/base.rb +0 -268
- data/lib/pdk/module/template_dir/git.rb +0 -91
- data/lib/pdk/module/template_dir/local.rb +0 -21
- data/lib/pdk/template_file.rb +0 -96
- data/lib/pdk/validate/base_validator.rb +0 -215
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -82
- data/lib/pdk/validate/metadata/metadata_syntax.rb +0 -111
- data/lib/pdk/validate/metadata_validator.rb +0 -26
- data/lib/pdk/validate/puppet/puppet_epp.rb +0 -135
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -64
- data/lib/pdk/validate/puppet/puppet_syntax.rb +0 -135
- data/lib/pdk/validate/puppet_validator.rb +0 -26
- data/lib/pdk/validate/ruby/rubocop.rb +0 -72
- data/lib/pdk/validate/ruby_validator.rb +0 -26
- data/lib/pdk/validate/tasks/metadata_lint.rb +0 -130
- data/lib/pdk/validate/tasks/name.rb +0 -90
- data/lib/pdk/validate/tasks_validator.rb +0 -29
- data/lib/pdk/validate/yaml/syntax.rb +0 -125
- data/lib/pdk/validate/yaml_validator.rb +0 -28
@@ -3,84 +3,30 @@ require 'pdk'
|
|
3
3
|
module PDK
|
4
4
|
module Generate
|
5
5
|
class Transport < PuppetObject
|
6
|
-
|
7
|
-
|
8
|
-
# Prepares the data needed to render the new defined type template.
|
9
|
-
#
|
10
|
-
# @return [Hash{Symbol => Object}] a hash of information that will be
|
11
|
-
# provided to the defined type and defined type spec templates during
|
12
|
-
# rendering.
|
13
|
-
def template_data
|
14
|
-
data = {
|
15
|
-
name: object_name,
|
16
|
-
transport_class: Transport.class_name_from_object_name(object_name),
|
17
|
-
}
|
18
|
-
|
19
|
-
data
|
20
|
-
end
|
21
|
-
|
22
|
-
def raise_precondition_error(error)
|
23
|
-
raise PDK::CLI::ExitWithError, _('%{error}: Creating a transport needs some local configuration in your module.' \
|
24
|
-
' Please follow the docs at https://github.com/puppetlabs/puppet-resource_api#getting-started.') % { error: error }
|
25
|
-
end
|
26
|
-
|
27
|
-
def check_preconditions
|
28
|
-
super
|
29
|
-
# These preconditions can be removed once the pdk-templates are carrying the puppet-resource_api gem by default, and have switched
|
30
|
-
# the default mock_with value.
|
31
|
-
sync_path = PDK::Util.find_upwards('.sync.yml')
|
32
|
-
if sync_path.nil?
|
33
|
-
raise_precondition_error(_('.sync.yml not found'))
|
34
|
-
end
|
35
|
-
sync = YAML.load_file(sync_path)
|
36
|
-
if !sync.is_a? Hash
|
37
|
-
raise_precondition_error(_('.sync.yml contents is not a Hash'))
|
38
|
-
elsif !sync.key? 'Gemfile'
|
39
|
-
raise_precondition_error(_('Gemfile configuration not found'))
|
40
|
-
elsif !sync['Gemfile'].key? 'optional'
|
41
|
-
raise_precondition_error(_('Gemfile.optional configuration not found'))
|
42
|
-
elsif !sync['Gemfile']['optional'].key? ':development'
|
43
|
-
raise_precondition_error(_('Gemfile.optional.:development configuration not found'))
|
44
|
-
elsif sync['Gemfile']['optional'][':development'].none? { |g| g['gem'] == 'puppet-resource_api' }
|
45
|
-
raise_precondition_error(_('puppet-resource_api not found in the Gemfile config'))
|
46
|
-
elsif !sync.key? 'spec/spec_helper.rb'
|
47
|
-
raise_precondition_error(_('spec/spec_helper.rb configuration not found'))
|
48
|
-
elsif !sync['spec/spec_helper.rb'].key? 'mock_with'
|
49
|
-
raise_precondition_error(_('spec/spec_helper.rb.mock_with configuration not found'))
|
50
|
-
elsif !sync['spec/spec_helper.rb']['mock_with'] == ':rspec'
|
51
|
-
raise_precondition_error(_('spec/spec_helper.rb.mock_with not set to \':rspec\''))
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [String] the path where the new transport will be written.
|
56
|
-
def target_object_path
|
57
|
-
@target_object_path ||= File.join(module_dir, 'lib', 'puppet', 'transport', object_name) + '.rb'
|
6
|
+
def friendly_name
|
7
|
+
'Resource API Transport'.freeze
|
58
8
|
end
|
59
9
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
@target_spec_path ||= File.join(module_dir, 'spec', 'unit', 'puppet', 'transport', object_name) + '_spec.rb'
|
74
|
-
end
|
75
|
-
|
76
|
-
# @return [String] the path where the tests for the new schema will be written.
|
77
|
-
def target_type_spec_path
|
78
|
-
@target_type_spec_path ||= File.join(module_dir, 'spec', 'unit', 'puppet', 'transport', 'schema', object_name) + '_spec.rb'
|
10
|
+
def template_files
|
11
|
+
# Note : Due to how the V1 templates work, the names of the source template files may be mismatched to
|
12
|
+
# their destination, e.g. transport_type.erb is really a transport schema
|
13
|
+
files = {
|
14
|
+
'transport_spec.erb' => File.join('spec', 'unit', 'puppet', 'transport', object_name) + '_spec.rb',
|
15
|
+
'transport_type_spec.erb' => File.join('spec', 'unit', 'puppet', 'transport', 'schema', object_name) + '_spec.rb',
|
16
|
+
}
|
17
|
+
return files if spec_only?
|
18
|
+
files.merge(
|
19
|
+
'transport.erb' => File.join('lib', 'puppet', 'transport', object_name) + '.rb',
|
20
|
+
'transport_device.erb' => File.join('lib', 'puppet', 'util', 'network_device', object_name, 'device.rb'),
|
21
|
+
'transport_type.erb' => File.join('lib', 'puppet', 'transport', 'schema', object_name) + '.rb',
|
22
|
+
)
|
79
23
|
end
|
80
24
|
|
81
|
-
|
82
|
-
|
83
|
-
|
25
|
+
def template_data
|
26
|
+
{
|
27
|
+
name: object_name,
|
28
|
+
transport_class: class_name_from_object_name(object_name),
|
29
|
+
}
|
84
30
|
end
|
85
31
|
end
|
86
32
|
end
|
data/lib/pdk/module.rb
CHANGED
@@ -4,7 +4,6 @@ module PDK
|
|
4
4
|
autoload :Convert, 'pdk/module/convert'
|
5
5
|
autoload :Metadata, 'pdk/module/metadata'
|
6
6
|
autoload :Release, 'pdk/module/release'
|
7
|
-
autoload :TemplateDir, 'pdk/module/template_dir'
|
8
7
|
autoload :UpdateManager, 'pdk/module/update_manager'
|
9
8
|
autoload :Update, 'pdk/module/update'
|
10
9
|
|
@@ -16,6 +15,7 @@ module PDK
|
|
16
15
|
'/REVISION',
|
17
16
|
'/spec/fixtures/modules/',
|
18
17
|
'/vendor/',
|
18
|
+
'.DS_Store',
|
19
19
|
].freeze
|
20
20
|
|
21
21
|
def default_ignored_pathspec(ignore_dotfiles = true)
|
data/lib/pdk/module/convert.rb
CHANGED
@@ -26,6 +26,7 @@ module PDK
|
|
26
26
|
unless update_manager.changes?
|
27
27
|
if adding_tests?
|
28
28
|
add_tests!
|
29
|
+
print_result 'Convert completed'
|
29
30
|
else
|
30
31
|
require 'pdk/report'
|
31
32
|
|
@@ -53,18 +54,15 @@ module PDK
|
|
53
54
|
return unless continue
|
54
55
|
end
|
55
56
|
|
56
|
-
# Remove these files straight away as these changes are not something
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
57
|
+
# Remove these files straight away as these changes are not something
|
58
|
+
# that the user needs to review.
|
59
|
+
update_manager.unlink_file('Gemfile.lock')
|
60
|
+
update_manager.unlink_file(File.join('.bundle', 'config'))
|
61
61
|
|
62
62
|
update_manager.sync_changes!
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
PDK::Util::Bundler.ensure_bundle!
|
67
|
-
end
|
64
|
+
require 'pdk/util/bundler'
|
65
|
+
PDK::Util::Bundler.ensure_bundle!
|
68
66
|
|
69
67
|
add_tests! if adding_tests?
|
70
68
|
|
@@ -88,41 +86,59 @@ module PDK
|
|
88
86
|
end
|
89
87
|
|
90
88
|
def missing_tests?
|
91
|
-
|
89
|
+
!available_test_generators.empty?
|
90
|
+
end
|
91
|
+
|
92
|
+
def available_test_generators
|
93
|
+
# Only select generators which can run and have no pre-existing files
|
94
|
+
test_generators.select do |gen|
|
95
|
+
if gen.can_run?
|
96
|
+
gen.template_files.none? { |_, dst_path| PDK::Util::Filesystem.exist?(File.join(gen.context.root_path, dst_path)) }
|
97
|
+
else
|
98
|
+
false
|
99
|
+
end
|
100
|
+
end
|
92
101
|
end
|
93
102
|
|
94
|
-
def test_generators
|
103
|
+
def test_generators(context = PDK.context)
|
95
104
|
return @test_generators unless @test_generators.nil?
|
96
105
|
require 'pdk/util/puppet_strings'
|
97
106
|
|
98
107
|
test_gens = PDK::Util::PuppetStrings.all_objects.map do |generator, objects|
|
99
108
|
(objects || []).map do |obj|
|
100
|
-
generator.new(
|
109
|
+
generator.new(context, obj['name'], spec_only: true)
|
101
110
|
end
|
102
111
|
end
|
103
112
|
|
104
113
|
@test_generators = test_gens.flatten
|
105
114
|
end
|
106
115
|
|
107
|
-
def
|
108
|
-
|
109
|
-
gen.
|
116
|
+
def stage_tests!(manager)
|
117
|
+
available_test_generators.each do |gen|
|
118
|
+
gen.stage_changes(manager)
|
110
119
|
end
|
120
|
+
manager
|
111
121
|
end
|
112
122
|
|
113
|
-
def
|
114
|
-
update_manager.
|
123
|
+
def add_tests!
|
124
|
+
update_manager.clear!
|
125
|
+
stage_tests!(update_manager)
|
126
|
+
|
127
|
+
if update_manager.changes?
|
128
|
+
update_manager.sync_changes!
|
129
|
+
print_summary
|
130
|
+
else
|
131
|
+
PDK::Report.default_target.puts(_('No test changes required.'))
|
132
|
+
end
|
115
133
|
end
|
116
134
|
|
117
|
-
def stage_changes!
|
135
|
+
def stage_changes!(context = PDK.context)
|
118
136
|
require 'pdk/util/filesystem'
|
119
137
|
|
120
138
|
metadata_path = File.join(module_dir, 'metadata.json')
|
121
139
|
|
122
|
-
PDK::
|
123
|
-
new_metadata = update_metadata(metadata_path,
|
124
|
-
templates.module_metadata = new_metadata.data unless new_metadata.nil?
|
125
|
-
|
140
|
+
PDK::Template.with(template_uri, context) do |template_dir|
|
141
|
+
new_metadata = update_metadata(metadata_path, template_dir.metadata)
|
126
142
|
if options[:noop] && new_metadata.nil?
|
127
143
|
update_manager.add_file(metadata_path, '')
|
128
144
|
elsif PDK::Util::Filesystem.file?(metadata_path)
|
@@ -131,7 +147,11 @@ module PDK
|
|
131
147
|
update_manager.add_file(metadata_path, new_metadata.to_json)
|
132
148
|
end
|
133
149
|
|
134
|
-
|
150
|
+
# new_metadata == nil when creating a new module but with --noop@
|
151
|
+
module_name = new_metadata.nil? ? 'new-module' : new_metadata.data['name']
|
152
|
+
metadata_for_render = new_metadata.nil? ? {} : new_metadata.data
|
153
|
+
|
154
|
+
template_dir.render_new_module(module_name, metadata_for_render) do |relative_file_path, file_content, file_status|
|
135
155
|
absolute_file_path = File.join(module_dir, relative_file_path)
|
136
156
|
case file_status
|
137
157
|
when :unmanage
|
data/lib/pdk/module/metadata.rb
CHANGED
@@ -27,7 +27,7 @@ module PDK
|
|
27
27
|
'Debian based Linux' => [
|
28
28
|
{
|
29
29
|
'operatingsystem' => 'Debian',
|
30
|
-
'operatingsystemrelease' => ['
|
30
|
+
'operatingsystemrelease' => ['10'],
|
31
31
|
},
|
32
32
|
{
|
33
33
|
'operatingsystem' => 'Ubuntu',
|
@@ -54,6 +54,10 @@ module PDK
|
|
54
54
|
'operatingsystem' => 'windows',
|
55
55
|
'operatingsystemrelease' => %w[2019 10],
|
56
56
|
},
|
57
|
+
'AIX' => {
|
58
|
+
'operatingsystem' => 'AIX',
|
59
|
+
'operatingsystemrelease' => %w[6.1 7.1 7.2],
|
60
|
+
},
|
57
61
|
}.freeze
|
58
62
|
|
59
63
|
DEFAULT_OPERATING_SYSTEMS = [
|
@@ -77,7 +81,7 @@ module PDK
|
|
77
81
|
OPERATING_SYSTEMS[os_name]
|
78
82
|
}.flatten,
|
79
83
|
'requirements' => [
|
80
|
-
{ 'name' => 'puppet', 'version_requirement' => '>=
|
84
|
+
{ 'name' => 'puppet', 'version_requirement' => '>= 6.21.0 < 8.0.0' },
|
81
85
|
],
|
82
86
|
}.freeze
|
83
87
|
|
data/lib/pdk/module/release.rb
CHANGED
@@ -105,20 +105,14 @@ module PDK
|
|
105
105
|
|
106
106
|
PDK::CLI::Util.module_version_check
|
107
107
|
|
108
|
-
report = PDK::Report.new
|
109
108
|
puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
|
110
109
|
PDK::Util::PuppetVersion.fetch_puppet_dev if opts[:'puppet-dev']
|
111
110
|
PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
|
112
111
|
|
113
|
-
opts = opts.merge(puppet_env[:gemset])
|
114
|
-
|
115
112
|
PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
|
116
113
|
|
117
|
-
|
118
|
-
|
119
|
-
validator_exit_code = validator.invoke(report, opts.dup)
|
120
|
-
raise PDK::CLI::ExitWithError, _('An error occured during validation') unless validator_exit_code.zero?
|
121
|
-
end
|
114
|
+
validator_exit_code, = PDK::Validate.invoke_validators_by_name(PDK.context, PDK::Validate.validator_names, false, options)
|
115
|
+
raise PDK::CLI::ExitWithError, _('An error occured during validation') unless validator_exit_code.zero?
|
122
116
|
end
|
123
117
|
|
124
118
|
def run_documentation(_opts)
|
@@ -169,7 +163,7 @@ module PDK
|
|
169
163
|
http.request(request)
|
170
164
|
end
|
171
165
|
|
172
|
-
raise PDK::CLI::ExitWithError, _('Error uploading to Puppet Forge: %{result}') % { result: response } unless response.is_a?(Net::HTTPSuccess)
|
166
|
+
raise PDK::CLI::ExitWithError, _('Error uploading to Puppet Forge: %{result}') % { result: response.body } unless response.is_a?(Net::HTTPSuccess)
|
173
167
|
PDK.logger.info _('Publish to Forge was successful')
|
174
168
|
end
|
175
169
|
|
data/lib/pdk/module/update.rb
CHANGED
@@ -33,19 +33,15 @@ module PDK
|
|
33
33
|
return unless PDK::CLI::Util.prompt_for_yes(message)
|
34
34
|
end
|
35
35
|
|
36
|
-
# Remove these files straight away as these changes are not something
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
36
|
+
# Remove these files straight away as these changes are not something
|
37
|
+
# that the user needs to review.
|
38
|
+
update_manager.unlink_file('Gemfile.lock')
|
39
|
+
update_manager.unlink_file(File.join('.bundle', 'config'))
|
41
40
|
|
42
41
|
update_manager.sync_changes!
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
PDK::Util::Bundler.ensure_bundle!
|
48
|
-
end
|
43
|
+
require 'pdk/util/bundler'
|
44
|
+
PDK::Util::Bundler.ensure_bundle!
|
49
45
|
|
50
46
|
print_result 'Update completed'
|
51
47
|
end
|
@@ -89,7 +85,7 @@ module PDK
|
|
89
85
|
private
|
90
86
|
|
91
87
|
def latest_template?
|
92
|
-
[PDK::TEMPLATE_REF, 'master'].include?(template_uri.uri_fragment)
|
88
|
+
[PDK::TEMPLATE_REF, 'master', 'main'].include?(template_uri.uri_fragment)
|
93
89
|
end
|
94
90
|
|
95
91
|
def current_template_version
|
@@ -75,6 +75,13 @@ module PDK
|
|
75
75
|
changes[:modified].key?(path)
|
76
76
|
end
|
77
77
|
|
78
|
+
def clear!
|
79
|
+
@modified_files.clear
|
80
|
+
@added_files.clear
|
81
|
+
@removed_files.clear
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
|
78
85
|
# Apply any pending changes stored in the UpdateManager to the module.
|
79
86
|
#
|
80
87
|
# @raise (see #calculate_diffs)
|
data/lib/pdk/report.rb
CHANGED
@@ -104,7 +104,7 @@ module PDK
|
|
104
104
|
if event.rspec_puppet_coverage?
|
105
105
|
coverage_report = event.to_text
|
106
106
|
else
|
107
|
-
report << event.to_text unless event.pass?
|
107
|
+
report << event.to_text unless event.pass? || event.skipped?
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -113,8 +113,8 @@ module PDK
|
|
113
113
|
|
114
114
|
if target.is_a?(String)
|
115
115
|
PDK::Util::Filesystem.write_file(target, report.join("\n"))
|
116
|
-
|
117
|
-
target << report.join("\n")
|
116
|
+
elsif !report.empty?
|
117
|
+
target << report.join("\n") << "\n"
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
data/lib/pdk/report/event.rb
CHANGED
@@ -111,8 +111,8 @@ module PDK
|
|
111
111
|
location = nil if location.empty?
|
112
112
|
|
113
113
|
# TODO: maybe add trace
|
114
|
-
header = [severity, source, location, message].compact.join(': ')
|
115
114
|
if source == 'rspec'
|
115
|
+
header = [severity, source, location, message].compact.join(': ')
|
116
116
|
result = [header, " #{test}"]
|
117
117
|
context = context_lines
|
118
118
|
unless context.nil?
|
@@ -123,7 +123,13 @@ module PDK
|
|
123
123
|
|
124
124
|
result.compact.join("\n")
|
125
125
|
else
|
126
|
-
|
126
|
+
output = ['pdk']
|
127
|
+
output << "(#{severity.upcase}):" unless severity.nil?
|
128
|
+
output << "#{source}:" unless source.nil?
|
129
|
+
output << message unless message.nil?
|
130
|
+
output << "(#{location})" unless location.nil?
|
131
|
+
|
132
|
+
output.join(' ')
|
127
133
|
end
|
128
134
|
end
|
129
135
|
|
data/lib/pdk/template.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Template
|
5
|
+
autoload :Fetcher, 'pdk/template/fetcher'
|
6
|
+
autoload :Renderer, 'pdk/template/renderer'
|
7
|
+
autoload :TemplateDir, 'pdk/template/template_dir'
|
8
|
+
|
9
|
+
MODULE_TEMPLATE_TYPE = :module_template
|
10
|
+
|
11
|
+
# Creates a TemplateDir object with the path or URL to the template
|
12
|
+
# and the block of code to run to be run while the template is available.
|
13
|
+
#
|
14
|
+
# The template directory is only guaranteed to be available on disk
|
15
|
+
# within the scope of the block passed to this method.
|
16
|
+
#
|
17
|
+
# @param uri [PDK::Util::TemplateURI] The path to a directory to use as the
|
18
|
+
# template or a URI to a git repository.
|
19
|
+
#
|
20
|
+
# @param context [PDK::Context::AbstractContext] The context in which the template will render to
|
21
|
+
#
|
22
|
+
# @yieldparam self [PDK::Template::TemplateDir] The initialised object with
|
23
|
+
# the template available on disk.
|
24
|
+
#
|
25
|
+
# @example Using a git repository as a template
|
26
|
+
# PDK::Template.with('https://github.com/puppetlabs/pdk-templates') do |t|
|
27
|
+
# t.render_module('module, PDK.context) do |filename, content, status|
|
28
|
+
# File.open(filename, 'w') do |file|
|
29
|
+
# ...
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# @raise [ArgumentError] If no block is given to this method.
|
35
|
+
# @raise [PDK::CLI::FatalError]
|
36
|
+
# @raise [ArgumentError]
|
37
|
+
#
|
38
|
+
# @api public
|
39
|
+
def self.with(uri, context)
|
40
|
+
unless block_given?
|
41
|
+
raise ArgumentError, _('%{class_name}.with must be passed a block.') % { class_name: name }
|
42
|
+
end
|
43
|
+
unless uri.is_a? PDK::Util::TemplateURI
|
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
|
+
end
|
46
|
+
|
47
|
+
Fetcher.with(uri) do |fetcher|
|
48
|
+
template_dir = TemplateDir.instance(uri, fetcher.path, context)
|
49
|
+
template_dir.metadata = fetcher.metadata
|
50
|
+
|
51
|
+
template_type = uri.default? ? 'default' : 'custom'
|
52
|
+
PDK.analytics.event('TemplateDir', 'initialize', label: template_type)
|
53
|
+
|
54
|
+
yield template_dir
|
55
|
+
end
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|