module PDQTest::Pdk

the main purpose of this is to add emoji after running a PDK lifecycle.. There is basically no other way to do this mega-hack. while `pdk` itself is a kind of selective wrapper around ruby, I couldn't get calling `pdk` from inside `pdk bundle` to work, nor could I figure out how to load the PDK libraries from the “inside”

Constants

PDK_TAGS

Copy these values from PDK generated metadata to module metadata

PDK_VERSION_TAG

Golden metadata key which proves PDK is already installed

SYNC_YML

Public Class Methods

amend_sync_yml(data) click to toggle source
# File lib/pdqtest/pdk.rb, line 59
def self.amend_sync_yml(data)
  if File.exist? SYNC_YML
    sync = YAML.load_file(SYNC_YML)

    # PDQTest < 2.0.4 mistakenly dropped an array into
    # .sync.yml[.gitattributes][include] that will crash PDK on upgrade
    # nuke this key on sight to fix
    if sync.dig(".gitattributes", "include").is_a? Array
      sync[".gitattributes"].delete("include")
    end
  else
    sync = {}
  end
  sync.deep_merge!(data)
  $logger.info("Updated .sync.yml with #{data}")

  File.open(SYNC_YML, 'w') { |f| YAML.dump(sync, f) }
end
enable_pdk(pdk_metadata) click to toggle source
# File lib/pdqtest/pdk.rb, line 43
def self.enable_pdk(pdk_metadata)
  if ! is_pdk_enabled
    $logger.info("enabling PDK in metadata.json")
    metadata = Puppet.module_metadata

    PDK_TAGS.each do |pdk_tag|
      metadata[pdk_tag] = pdk_metadata[pdk_tag]
    end
    PDQTest::Puppet.save_module_metadata(metadata)
  end
end
is_pdk_enabled() click to toggle source
# File lib/pdqtest/pdk.rb, line 55
def self.is_pdk_enabled
  Puppet.module_metadata.include?(PDK_VERSION_TAG)
end
run(subcommand) click to toggle source
# File lib/pdqtest/pdk.rb, line 24
def self.run(subcommand)
  if Util.is_windows
    pdk = "powershell -command \"pdk #{subcommand}\" ; exit $LastExitCode"
  else
    pdk = "pdk #{subcommand}"
  end

  # write a .fixtures.yml for PDK test commands
  if subcommand =~ /test/
    PDQTest::Puppet.fixtures_yml
  end

  # our environment is heavly contaminated by bundler and maybe RVM too
  status = system(Util.clean_env, pdk, unsetenv_others: true)

  PDQTest::Emoji.partial_status(status, subcommand)
  status
end