Skip to content

Commit

Permalink
(CAT-1896) - Use puppet-modulebuilder for build functionality
Browse files Browse the repository at this point in the history
This commit updates the pdk to use the module builder gem
for its build functionality. The PDK build code had largely
duplicated this, therefore we were maintaining two codebases
with very similiar purpose.
  • Loading branch information
jordanbreen28 committed Jul 10, 2024
1 parent 3f0ca66 commit 4baf850
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 764 deletions.
9 changes: 6 additions & 3 deletions lib/pdk/cli/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module CLI
option nil, 'force', 'Skips the prompts and builds the module package.'

run do |opts, _args, _cmd|
require 'pdk/module/build'
require 'pdk/module/metadata'
require 'pdk/cli/util'

Expand All @@ -37,7 +36,11 @@ module CLI
end
end

builder = PDK::Module::Build.new(opts)
# build module
require 'puppet/modulebuilder'
module_dir = PDK::Util::Filesystem.expand_path(Dir.pwd)
target_dir = PDK::Util::Filesystem.expand_path(opts[:'target-dir'])
builder = Puppet::Modulebuilder::Builder.new(module_dir, target_dir, PDK.logger)

unless opts[:force]
if builder.package_already_exists?
Expand All @@ -49,7 +52,7 @@ module CLI
end
end

unless builder.module_pdk_compatible?
unless PDK::Util.module_pdk_compatible?(module_dir)
PDK.logger.info 'This module is not compatible with PDK, so PDK can not validate or test this build. ' \
'Unvalidated modules may have errors when uploading to the Forge. ' \
'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.'
Expand Down
1 change: 0 additions & 1 deletion lib/pdk/cli/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'pdk/util/bundler'
require 'pdk/cli/util/interview'
require 'pdk/util/changelog_generator'
require 'pdk/module/build'

module PDK
module CLI
Expand Down
302 changes: 0 additions & 302 deletions lib/pdk/module/build.rb

This file was deleted.

15 changes: 9 additions & 6 deletions lib/pdk/module/release.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pdk'
require 'uri'
require 'puppet/modulebuilder'

module PDK
module Module
Expand Down Expand Up @@ -77,7 +78,7 @@ def run
# Use the default as a last resort
package_file = default_package_filename if package_file.nil?
else
package_file = run_build(options)
package_file = run_build
end

run_publish(options.dup, package_file) unless skip_publish?
Expand All @@ -95,7 +96,7 @@ def write_module_metadata!
def default_package_filename
return @default_tarball_filename unless @default_tarball_filename.nil?

builder = PDK::Module::Build.new(module_dir: module_path)
builder = Puppet::Modulebuilder::Builder.new(module_path, nil, PDK.logger)
@default_tarball_filename = builder.package_file
end

Expand Down Expand Up @@ -135,8 +136,11 @@ def run_dependency_checker(_opts)
end

# @return [String] Path to the built tarball
def run_build(opts)
PDK::Module::Build.invoke(opts.dup)
def run_build
module_dir = PDK::Util::Filesystem.expand_path(module_path || Dir.pwd)
target_dir = File.join(module_dir, 'pkg')
builder = Puppet::Modulebuilder::Builder.new(module_dir, target_dir, PDK.logger)
builder.build
end

def run_publish(_opts, tarball_path)
Expand Down Expand Up @@ -238,8 +242,7 @@ def forge_compatible?
def pdk_compatible?
return @pdk_compatible unless @pdk_compatible.nil?

builder = PDK::Module::Build.new(module_dir: module_path)
@pdk_compatible = builder.module_pdk_compatible?
@pdk_compatible = PDK::Util.module_pdk_compatible?(module_path)
end
# :nocov:

Expand Down
3 changes: 3 additions & 0 deletions pdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Gem::Specification.new do |spec|
# json-schema and deps
spec.add_runtime_dependency 'json-schema', '~> 4.0'

#  PDK build
spec.add_runtime_dependency 'puppet-modulebuilder', '~> 1.0'

# Other deps
spec.add_runtime_dependency 'deep_merge', '~> 1.2.2'
spec.add_runtime_dependency 'diff-lcs', '>= 1.5.0'
Expand Down
Loading

0 comments on commit 4baf850

Please sign in to comment.