Skip to content

Commit

Permalink
Merge pull request #1374 from puppetlabs/cat-1896-use_puppet-modulebu…
Browse files Browse the repository at this point in the history
…ilder

(CAT-1896) - Use puppet-modulebuilder for `PDK build`
  • Loading branch information
gavindidrichsen committed Jul 11, 2024
2 parents 1a35834 + f01112c commit da0a3b8
Show file tree
Hide file tree
Showing 9 changed files with 60 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
1 change: 1 addition & 0 deletions lib/pdk/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Util
def exit_process(exit_code)
exit exit_code
end
module_function :exit_process
# :nocov:

# Searches upwards from current working directory for the given target file.
Expand Down
Loading

0 comments on commit da0a3b8

Please sign in to comment.