pdk 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1336 -1329
  3. data/LICENSE +201 -201
  4. data/README.md +163 -163
  5. data/exe/pdk +10 -10
  6. data/lib/pdk/analytics/client/google_analytics.rb +143 -143
  7. data/lib/pdk/analytics/client/noop.rb +25 -25
  8. data/lib/pdk/analytics/util.rb +19 -19
  9. data/lib/pdk/analytics.rb +30 -30
  10. data/lib/pdk/answer_file.rb +12 -12
  11. data/lib/pdk/bolt.rb +19 -19
  12. data/lib/pdk/cli/build.rb +82 -82
  13. data/lib/pdk/cli/bundle.rb +48 -48
  14. data/lib/pdk/cli/config/get.rb +26 -26
  15. data/lib/pdk/cli/config.rb +22 -22
  16. data/lib/pdk/cli/console.rb +148 -148
  17. data/lib/pdk/cli/convert.rb +52 -52
  18. data/lib/pdk/cli/env.rb +52 -52
  19. data/lib/pdk/cli/errors.rb +25 -25
  20. data/lib/pdk/cli/exec/command.rb +293 -293
  21. data/lib/pdk/cli/exec/interactive_command.rb +114 -114
  22. data/lib/pdk/cli/exec.rb +84 -84
  23. data/lib/pdk/cli/exec_group.rb +104 -104
  24. data/lib/pdk/cli/get/config.rb +24 -24
  25. data/lib/pdk/cli/get.rb +20 -20
  26. data/lib/pdk/cli/module/build.rb +12 -12
  27. data/lib/pdk/cli/module/generate.rb +47 -47
  28. data/lib/pdk/cli/module.rb +14 -14
  29. data/lib/pdk/cli/new/class.rb +32 -32
  30. data/lib/pdk/cli/new/defined_type.rb +32 -32
  31. data/lib/pdk/cli/new/fact.rb +29 -29
  32. data/lib/pdk/cli/new/function.rb +29 -29
  33. data/lib/pdk/cli/new/module.rb +53 -53
  34. data/lib/pdk/cli/new/provider.rb +29 -29
  35. data/lib/pdk/cli/new/task.rb +34 -34
  36. data/lib/pdk/cli/new/test.rb +52 -52
  37. data/lib/pdk/cli/new/transport.rb +27 -27
  38. data/lib/pdk/cli/new.rb +21 -21
  39. data/lib/pdk/cli/release/prep.rb +39 -39
  40. data/lib/pdk/cli/release/publish.rb +50 -50
  41. data/lib/pdk/cli/release.rb +194 -194
  42. data/lib/pdk/cli/remove/config.rb +80 -80
  43. data/lib/pdk/cli/remove.rb +20 -20
  44. data/lib/pdk/cli/set/config.rb +119 -119
  45. data/lib/pdk/cli/set.rb +20 -20
  46. data/lib/pdk/cli/test/unit.rb +90 -90
  47. data/lib/pdk/cli/test.rb +11 -11
  48. data/lib/pdk/cli/update.rb +64 -64
  49. data/lib/pdk/cli/util/command_redirector.rb +27 -27
  50. data/lib/pdk/cli/util/interview.rb +72 -72
  51. data/lib/pdk/cli/util/option_normalizer.rb +55 -55
  52. data/lib/pdk/cli/util/option_validator.rb +68 -68
  53. data/lib/pdk/cli/util/spinner.rb +13 -13
  54. data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
  55. data/lib/pdk/cli/util.rb +305 -305
  56. data/lib/pdk/cli/validate.rb +116 -116
  57. data/lib/pdk/cli.rb +175 -175
  58. data/lib/pdk/config/analytics_schema.json +26 -26
  59. data/lib/pdk/config/errors.rb +5 -5
  60. data/lib/pdk/config/ini_file.rb +183 -183
  61. data/lib/pdk/config/ini_file_setting.rb +39 -39
  62. data/lib/pdk/config/json.rb +34 -34
  63. data/lib/pdk/config/json_schema_namespace.rb +142 -142
  64. data/lib/pdk/config/json_schema_setting.rb +53 -53
  65. data/lib/pdk/config/json_with_schema.rb +49 -49
  66. data/lib/pdk/config/namespace.rb +354 -354
  67. data/lib/pdk/config/setting.rb +135 -135
  68. data/lib/pdk/config/validator.rb +31 -31
  69. data/lib/pdk/config/yaml.rb +46 -46
  70. data/lib/pdk/config/yaml_with_schema.rb +59 -59
  71. data/lib/pdk/config.rb +390 -390
  72. data/lib/pdk/context/control_repo.rb +60 -60
  73. data/lib/pdk/context/module.rb +28 -28
  74. data/lib/pdk/context/none.rb +22 -22
  75. data/lib/pdk/context.rb +99 -99
  76. data/lib/pdk/control_repo.rb +90 -90
  77. data/lib/pdk/generate/defined_type.rb +43 -43
  78. data/lib/pdk/generate/fact.rb +25 -25
  79. data/lib/pdk/generate/function.rb +48 -48
  80. data/lib/pdk/generate/module.rb +352 -352
  81. data/lib/pdk/generate/provider.rb +28 -28
  82. data/lib/pdk/generate/puppet_class.rb +43 -43
  83. data/lib/pdk/generate/puppet_object.rb +232 -232
  84. data/lib/pdk/generate/task.rb +68 -68
  85. data/lib/pdk/generate/transport.rb +33 -33
  86. data/lib/pdk/generate.rb +24 -24
  87. data/lib/pdk/i18n.rb +4 -4
  88. data/lib/pdk/logger.rb +45 -45
  89. data/lib/pdk/module/build.rb +322 -322
  90. data/lib/pdk/module/convert.rb +296 -296
  91. data/lib/pdk/module/metadata.rb +202 -202
  92. data/lib/pdk/module/release.rb +260 -260
  93. data/lib/pdk/module/update.rb +131 -131
  94. data/lib/pdk/module/update_manager.rb +227 -227
  95. data/lib/pdk/module.rb +30 -30
  96. data/lib/pdk/report/event.rb +370 -370
  97. data/lib/pdk/report.rb +121 -121
  98. data/lib/pdk/template/fetcher/git.rb +85 -85
  99. data/lib/pdk/template/fetcher/local.rb +28 -28
  100. data/lib/pdk/template/fetcher.rb +98 -98
  101. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
  102. data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
  103. data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
  104. data/lib/pdk/template/renderer/v1.rb +25 -25
  105. data/lib/pdk/template/renderer.rb +96 -96
  106. data/lib/pdk/template/template_dir.rb +67 -67
  107. data/lib/pdk/template.rb +59 -59
  108. data/lib/pdk/tests/unit.rb +252 -252
  109. data/lib/pdk/util/bundler.rb +259 -259
  110. data/lib/pdk/util/changelog_generator.rb +137 -137
  111. data/lib/pdk/util/env.rb +47 -47
  112. data/lib/pdk/util/filesystem.rb +138 -138
  113. data/lib/pdk/util/git.rb +179 -179
  114. data/lib/pdk/util/json_finder.rb +85 -85
  115. data/lib/pdk/util/puppet_strings.rb +125 -125
  116. data/lib/pdk/util/puppet_version.rb +266 -266
  117. data/lib/pdk/util/ruby_version.rb +179 -179
  118. data/lib/pdk/util/template_uri.rb +295 -295
  119. data/lib/pdk/util/vendored_file.rb +93 -93
  120. data/lib/pdk/util/version.rb +43 -43
  121. data/lib/pdk/util/windows/api_types.rb +82 -82
  122. data/lib/pdk/util/windows/file.rb +36 -36
  123. data/lib/pdk/util/windows/process.rb +79 -79
  124. data/lib/pdk/util/windows/string.rb +16 -16
  125. data/lib/pdk/util/windows.rb +15 -15
  126. data/lib/pdk/util.rb +278 -278
  127. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
  128. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
  129. data/lib/pdk/validate/external_command_validator.rb +208 -208
  130. data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
  131. data/lib/pdk/validate/invokable_validator.rb +228 -228
  132. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
  133. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
  134. data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
  135. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
  136. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
  137. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
  138. data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
  139. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
  140. data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
  141. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
  142. data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
  143. data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
  144. data/lib/pdk/validate/validator.rb +118 -118
  145. data/lib/pdk/validate/validator_group.rb +104 -104
  146. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
  147. data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
  148. data/lib/pdk/validate.rb +94 -94
  149. data/lib/pdk/version.rb +4 -4
  150. data/lib/pdk.rb +76 -76
  151. data/locales/config.yaml +21 -21
  152. data/locales/pdk.pot +2111 -2094
  153. metadata +3 -3
@@ -1,260 +1,260 @@
1
- require 'pdk'
2
-
3
- module PDK
4
- module Module
5
- class Release
6
- def self.invoke(module_path, options = {})
7
- new(module_path, options).run
8
- end
9
-
10
- attr_reader :options
11
-
12
- attr_reader :module_path
13
-
14
- def initialize(module_path, options = {})
15
- @options = options
16
-
17
- # TODO: Currently the release process can ONLY be run if the working directory IS the module root. However, in the future
18
- # this WILL change, so we have the API arguments for it, but only accept `nil` for the first parameter
19
- raise PDK::CLI::ExitWithError, _('Running the release process outside of the working directory is not supported') unless module_path.nil?
20
-
21
- if module_path.nil?
22
- module_path = PDK::Util.module_root
23
- raise PDK::CLI::ExitWithError, _('The module release process requires a valid module path') % { module_path: module_path } if module_path.nil?
24
- end
25
- raise PDK::CLI::ExitWithError, _('%{module_path} is not a valid module') % { module_path: module_path } unless PDK::Util.in_module_root?(module_path)
26
- @module_path = module_path
27
- end
28
-
29
- def run
30
- # Pre-release checks
31
- unless force?
32
- raise PDK::CLI::ExitWithError, _('The module is not PDK compatible') if requires_pdk_compatibility? && !pdk_compatible?
33
- raise PDK::CLI::ExitWithError, _('The module is not Forge compatible') if requires_forge_compatibility? && !forge_compatible?
34
- end
35
-
36
- # Note that these checks are duplicated in the run_publish method, however it's a much better
37
- # experience to fail early, than going through the whole process, only to error at the end knowing full well
38
- # it'll fail anyway.
39
- validate_publish_options!
40
-
41
- run_validations(options) unless skip_validation?
42
-
43
- PDK.logger.info _('Releasing %{module_name} - from version %{module_version}') % {
44
- module_name: module_metadata.data['name'],
45
- module_version: module_metadata.data['version'],
46
- }
47
-
48
- PDK::Util::ChangelogGenerator.generate_changelog unless skip_changelog?
49
-
50
- # Calculate the new module version
51
- new_version = specified_version
52
- if new_version.nil? && !skip_changelog?
53
- new_version = PDK::Util::ChangelogGenerator.compute_next_version(module_metadata.data['version'])
54
- end
55
- new_version = module_metadata.data['version'] if new_version.nil?
56
-
57
- if new_version != module_metadata.data['version']
58
- PDK.logger.info _('Updating version to %{module_version}') % {
59
- module_version: new_version,
60
- }
61
-
62
- # Set the new version in metadata file
63
- module_metadata.data['version'] = new_version
64
- write_module_metadata!
65
-
66
- # Update the changelog with the correct version
67
- PDK::Util::ChangelogGenerator.generate_changelog unless skip_changelog?
68
-
69
- # Check if the versions match
70
- latest_version = PDK::Util::ChangelogGenerator.latest_version
71
- unless latest_version
72
- 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
- end
74
- end
75
-
76
- run_documentation(options) unless skip_documentation?
77
-
78
- run_dependency_checker(options) unless skip_dependency?
79
-
80
- if skip_build?
81
- # Even if we're skipping the build, we still need the name of the tarball
82
- # Use the specified package path if set
83
- package_file = specified_package if package_file.nil?
84
- # Use the default as a last resort
85
- package_file = default_package_filename if package_file.nil?
86
- else
87
- package_file = run_build(options)
88
- end
89
-
90
- run_publish(options.dup, package_file) unless skip_publish?
91
- end
92
-
93
- def module_metadata
94
- @module_metada ||= PDK::Module::Metadata.from_file(File.join(module_path, 'metadata.json'))
95
- end
96
-
97
- def write_module_metadata!
98
- module_metadata.write!(File.join(module_path, 'metadata.json'))
99
- clear_cached_data
100
- end
101
-
102
- def default_package_filename
103
- return @default_tarball_filename unless @default_tarball_filename.nil?
104
- builder = PDK::Module::Build.new(module_dir: module_path)
105
- @default_tarball_filename = builder.package_file
106
- end
107
-
108
- def run_validations(opts)
109
- # TODO: Surely I can use a pre-existing class for this?
110
- PDK::CLI::Util.validate_puppet_version_opts(opts)
111
-
112
- PDK::CLI::Util.module_version_check
113
-
114
- puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
115
- PDK::Util::PuppetVersion.fetch_puppet_dev if opts[:'puppet-dev']
116
- PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
117
-
118
- PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
119
-
120
- validator_exit_code, = PDK::Validate.invoke_validators_by_name(PDK.context, PDK::Validate.validator_names, false, options)
121
- raise PDK::CLI::ExitWithError, _('An error occured during validation') unless validator_exit_code.zero?
122
- end
123
-
124
- def run_documentation(_opts)
125
- PDK.logger.info _('Updating documentation using puppet strings')
126
- docs_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'exec', 'puppet', 'strings', 'generate', '--format', 'markdown', '--out', 'REFERENCE.md')
127
- docs_command.context = :module
128
- result = docs_command.execute!
129
- raise PDK::CLI::ExitWithError, _('An error occured generating the module documentation: %{stdout}') % { stdout: result[:stdout] } unless result[:exit_code].zero?
130
- end
131
-
132
- def run_dependency_checker(_opts)
133
- # run dependency-checker and output dependent modules list
134
- PDK.logger.info _('Running dependency checks')
135
-
136
- dep_command = PDK::CLI::Exec::Command.new('dependency-checker', 'metadata.json')
137
- dep_command.context = :module
138
- result = dep_command.execute!
139
-
140
- raise PDK::CLI::ExitWithError, _('An error occured checking the module dependencies: %{stdout}') % { stdout: result[:stdout] } unless result[:exit_code].zero?
141
- end
142
-
143
- # @return [String] Path to the built tarball
144
- def run_build(opts)
145
- PDK::Module::Build.invoke(opts.dup)
146
- end
147
-
148
- def run_publish(_opts, tarball_path)
149
- validate_publish_options!
150
- raise PDK::CLI::ExitWithError, _('Module tarball %{tarball_path} does not exist') % { tarball_path: tarball_path } unless PDK::Util::Filesystem.file?(tarball_path)
151
-
152
- # TODO: Replace this code when the upload functionality is added to the forge ruby gem
153
- require 'base64'
154
- file_data = Base64.encode64(PDK::Util::Filesystem.read_file(tarball_path, open_args: 'rb'))
155
-
156
- PDK.logger.info _('Uploading tarball to puppet forge...')
157
- uri = URI(forge_upload_url)
158
- require 'net/http'
159
- request = Net::HTTP::Post.new(uri.path)
160
- request['Authorization'] = 'Bearer ' + forge_token
161
- request['Content-Type'] = 'application/json'
162
- data = { file: file_data }
163
-
164
- request.body = data.to_json
165
-
166
- require 'openssl'
167
- use_ssl = uri.class == URI::HTTPS
168
- response = Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
169
- http.request(request)
170
- end
171
-
172
- raise PDK::CLI::ExitWithError, _('Error uploading to Puppet Forge: %{result}') % { result: response.body } unless response.is_a?(Net::HTTPSuccess)
173
- PDK.logger.info _('Publish to Forge was successful')
174
- end
175
-
176
- def validate_publish_options!
177
- return if skip_publish?
178
- raise PDK::CLI::ExitWithError, _('Missing forge-upload-url option') unless forge_upload_url
179
- raise PDK::CLI::ExitWithError, _('Missing forge-token option') unless forge_token
180
- end
181
-
182
- def force?
183
- options[:force]
184
- end
185
-
186
- def skip_build?
187
- options[:'skip-build']
188
- end
189
-
190
- def skip_changelog?
191
- options[:'skip-changelog']
192
- end
193
-
194
- def skip_dependency?
195
- options[:'skip-dependency']
196
- end
197
-
198
- def skip_documentation?
199
- options[:'skip-documentation']
200
- end
201
-
202
- def skip_publish?
203
- options[:'skip-publish']
204
- end
205
-
206
- def skip_validation?
207
- options[:'skip-validation']
208
- end
209
-
210
- def specified_version
211
- options[:version]
212
- end
213
-
214
- def specified_package
215
- options[:file]
216
- end
217
-
218
- def forge_token
219
- options[:'forge-token']
220
- end
221
-
222
- def forge_upload_url
223
- options[:'forge-upload-url']
224
- end
225
-
226
- def requires_pdk_compatibility?
227
- # Validation, Changelog and Dependency checks require the
228
- # module to be PDK Compatible
229
- !(skip_validation? && skip_changelog? && skip_dependency?)
230
- end
231
-
232
- def requires_forge_compatibility?
233
- # Pushing to the for requires the metadata to be forge compatible
234
- !skip_publish?
235
- end
236
-
237
- #:nocov:
238
- # These are just convenience methods and are tested elsewhere
239
- def forge_compatible?
240
- module_metadata.forge_ready?
241
- end
242
-
243
- def pdk_compatible?
244
- return @pdk_compatible unless @pdk_compatible.nil?
245
-
246
- builder = PDK::Module::Build.new(module_dir: module_path)
247
- @pdk_compatible = builder.module_pdk_compatible?
248
- end
249
- #:nocov:
250
-
251
- private
252
-
253
- def clear_cached_data
254
- @module_metadata = nil
255
- @pdk_compatible = nil
256
- @default_tarball_filename = nil
257
- end
258
- end
259
- end
260
- end
1
+ require 'pdk'
2
+
3
+ module PDK
4
+ module Module
5
+ class Release
6
+ def self.invoke(module_path, options = {})
7
+ new(module_path, options).run
8
+ end
9
+
10
+ attr_reader :options
11
+
12
+ attr_reader :module_path
13
+
14
+ def initialize(module_path, options = {})
15
+ @options = options
16
+
17
+ # TODO: Currently the release process can ONLY be run if the working directory IS the module root. However, in the future
18
+ # this WILL change, so we have the API arguments for it, but only accept `nil` for the first parameter
19
+ raise PDK::CLI::ExitWithError, _('Running the release process outside of the working directory is not supported') unless module_path.nil?
20
+
21
+ if module_path.nil?
22
+ module_path = PDK::Util.module_root
23
+ raise PDK::CLI::ExitWithError, _('The module release process requires a valid module path') % { module_path: module_path } if module_path.nil?
24
+ end
25
+ raise PDK::CLI::ExitWithError, _('%{module_path} is not a valid module') % { module_path: module_path } unless PDK::Util.in_module_root?(module_path)
26
+ @module_path = module_path
27
+ end
28
+
29
+ def run
30
+ # Pre-release checks
31
+ unless force?
32
+ raise PDK::CLI::ExitWithError, _('The module is not PDK compatible') if requires_pdk_compatibility? && !pdk_compatible?
33
+ raise PDK::CLI::ExitWithError, _('The module is not Forge compatible') if requires_forge_compatibility? && !forge_compatible?
34
+ end
35
+
36
+ # Note that these checks are duplicated in the run_publish method, however it's a much better
37
+ # experience to fail early, than going through the whole process, only to error at the end knowing full well
38
+ # it'll fail anyway.
39
+ validate_publish_options!
40
+
41
+ run_validations(options) unless skip_validation?
42
+
43
+ PDK.logger.info _('Releasing %{module_name} - from version %{module_version}') % {
44
+ module_name: module_metadata.data['name'],
45
+ module_version: module_metadata.data['version'],
46
+ }
47
+
48
+ PDK::Util::ChangelogGenerator.generate_changelog unless skip_changelog?
49
+
50
+ # Calculate the new module version
51
+ new_version = specified_version
52
+ if new_version.nil? && !skip_changelog?
53
+ new_version = PDK::Util::ChangelogGenerator.compute_next_version(module_metadata.data['version'])
54
+ end
55
+ new_version = module_metadata.data['version'] if new_version.nil?
56
+
57
+ if new_version != module_metadata.data['version']
58
+ PDK.logger.info _('Updating version to %{module_version}') % {
59
+ module_version: new_version,
60
+ }
61
+
62
+ # Set the new version in metadata file
63
+ module_metadata.data['version'] = new_version
64
+ write_module_metadata!
65
+
66
+ # Update the changelog with the correct version
67
+ PDK::Util::ChangelogGenerator.generate_changelog unless skip_changelog?
68
+
69
+ # Check if the versions match
70
+ latest_version = PDK::Util::ChangelogGenerator.latest_version
71
+ unless latest_version
72
+ 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
+ end
74
+ end
75
+
76
+ run_documentation(options) unless skip_documentation?
77
+
78
+ run_dependency_checker(options) unless skip_dependency?
79
+
80
+ if skip_build?
81
+ # Even if we're skipping the build, we still need the name of the tarball
82
+ # Use the specified package path if set
83
+ package_file = specified_package if package_file.nil?
84
+ # Use the default as a last resort
85
+ package_file = default_package_filename if package_file.nil?
86
+ else
87
+ package_file = run_build(options)
88
+ end
89
+
90
+ run_publish(options.dup, package_file) unless skip_publish?
91
+ end
92
+
93
+ def module_metadata
94
+ @module_metada ||= PDK::Module::Metadata.from_file(File.join(module_path, 'metadata.json'))
95
+ end
96
+
97
+ def write_module_metadata!
98
+ module_metadata.write!(File.join(module_path, 'metadata.json'))
99
+ clear_cached_data
100
+ end
101
+
102
+ def default_package_filename
103
+ return @default_tarball_filename unless @default_tarball_filename.nil?
104
+ builder = PDK::Module::Build.new(module_dir: module_path)
105
+ @default_tarball_filename = builder.package_file
106
+ end
107
+
108
+ def run_validations(opts)
109
+ # TODO: Surely I can use a pre-existing class for this?
110
+ PDK::CLI::Util.validate_puppet_version_opts(opts)
111
+
112
+ PDK::CLI::Util.module_version_check
113
+
114
+ puppet_env = PDK::CLI::Util.puppet_from_opts_or_env(opts)
115
+ PDK::Util::PuppetVersion.fetch_puppet_dev if opts[:'puppet-dev']
116
+ PDK::Util::RubyVersion.use(puppet_env[:ruby_version])
117
+
118
+ PDK::Util::Bundler.ensure_bundle!(puppet_env[:gemset])
119
+
120
+ validator_exit_code, = PDK::Validate.invoke_validators_by_name(PDK.context, PDK::Validate.validator_names, false, options)
121
+ raise PDK::CLI::ExitWithError, _('An error occured during validation') unless validator_exit_code.zero?
122
+ end
123
+
124
+ def run_documentation(_opts)
125
+ PDK.logger.info _('Updating documentation using puppet strings')
126
+ docs_command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, 'exec', 'puppet', 'strings', 'generate', '--format', 'markdown', '--out', 'REFERENCE.md')
127
+ docs_command.context = :module
128
+ result = docs_command.execute!
129
+ raise PDK::CLI::ExitWithError, _('An error occured generating the module documentation: %{stdout}') % { stdout: result[:stdout] } unless result[:exit_code].zero?
130
+ end
131
+
132
+ def run_dependency_checker(_opts)
133
+ # run dependency-checker and output dependent modules list
134
+ PDK.logger.info _('Running dependency checks')
135
+
136
+ dep_command = PDK::CLI::Exec::Command.new('dependency-checker', 'metadata.json')
137
+ dep_command.context = :module
138
+ result = dep_command.execute!
139
+
140
+ raise PDK::CLI::ExitWithError, _('An error occured checking the module dependencies: %{stdout}') % { stdout: result[:stdout] } unless result[:exit_code].zero?
141
+ end
142
+
143
+ # @return [String] Path to the built tarball
144
+ def run_build(opts)
145
+ PDK::Module::Build.invoke(opts.dup)
146
+ end
147
+
148
+ def run_publish(_opts, tarball_path)
149
+ validate_publish_options!
150
+ raise PDK::CLI::ExitWithError, _('Module tarball %{tarball_path} does not exist') % { tarball_path: tarball_path } unless PDK::Util::Filesystem.file?(tarball_path)
151
+
152
+ # TODO: Replace this code when the upload functionality is added to the forge ruby gem
153
+ require 'base64'
154
+ file_data = Base64.encode64(PDK::Util::Filesystem.read_file(tarball_path, open_args: 'rb'))
155
+
156
+ PDK.logger.info _('Uploading tarball to puppet forge...')
157
+ uri = URI(forge_upload_url)
158
+ require 'net/http'
159
+ request = Net::HTTP::Post.new(uri.path)
160
+ request['Authorization'] = 'Bearer ' + forge_token
161
+ request['Content-Type'] = 'application/json'
162
+ data = { file: file_data }
163
+
164
+ request.body = data.to_json
165
+
166
+ require 'openssl'
167
+ use_ssl = uri.class == URI::HTTPS
168
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
169
+ http.request(request)
170
+ end
171
+
172
+ raise PDK::CLI::ExitWithError, _('Error uploading to Puppet Forge: %{result}') % { result: response.body } unless response.is_a?(Net::HTTPSuccess)
173
+ PDK.logger.info _('Publish to Forge was successful')
174
+ end
175
+
176
+ def validate_publish_options!
177
+ return if skip_publish?
178
+ raise PDK::CLI::ExitWithError, _('Missing forge-upload-url option') unless forge_upload_url
179
+ raise PDK::CLI::ExitWithError, _('Missing forge-token option') unless forge_token
180
+ end
181
+
182
+ def force?
183
+ options[:force]
184
+ end
185
+
186
+ def skip_build?
187
+ options[:'skip-build']
188
+ end
189
+
190
+ def skip_changelog?
191
+ options[:'skip-changelog']
192
+ end
193
+
194
+ def skip_dependency?
195
+ options[:'skip-dependency']
196
+ end
197
+
198
+ def skip_documentation?
199
+ options[:'skip-documentation']
200
+ end
201
+
202
+ def skip_publish?
203
+ options[:'skip-publish']
204
+ end
205
+
206
+ def skip_validation?
207
+ options[:'skip-validation']
208
+ end
209
+
210
+ def specified_version
211
+ options[:version]
212
+ end
213
+
214
+ def specified_package
215
+ options[:file]
216
+ end
217
+
218
+ def forge_token
219
+ options[:'forge-token']
220
+ end
221
+
222
+ def forge_upload_url
223
+ options[:'forge-upload-url']
224
+ end
225
+
226
+ def requires_pdk_compatibility?
227
+ # Validation, Changelog and Dependency checks require the
228
+ # module to be PDK Compatible
229
+ !(skip_validation? && skip_changelog? && skip_dependency?)
230
+ end
231
+
232
+ def requires_forge_compatibility?
233
+ # Pushing to the for requires the metadata to be forge compatible
234
+ !skip_publish?
235
+ end
236
+
237
+ #:nocov:
238
+ # These are just convenience methods and are tested elsewhere
239
+ def forge_compatible?
240
+ module_metadata.forge_ready?
241
+ end
242
+
243
+ def pdk_compatible?
244
+ return @pdk_compatible unless @pdk_compatible.nil?
245
+
246
+ builder = PDK::Module::Build.new(module_dir: module_path)
247
+ @pdk_compatible = builder.module_pdk_compatible?
248
+ end
249
+ #:nocov:
250
+
251
+ private
252
+
253
+ def clear_cached_data
254
+ @module_metadata = nil
255
+ @pdk_compatible = nil
256
+ @default_tarball_filename = nil
257
+ end
258
+ end
259
+ end
260
+ end