From 7df0e517ef501d31d2ba2bbd182f9f4f90972445 Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Thu, 30 May 2019 15:58:18 +1000 Subject: [PATCH] (PDK-1337) Warn and unset any legacy *_GEM_VERSION env vars --- lib/pdk/cli/exec.rb | 20 ++++++++++++++++++++ spec/acceptance/version_changer_spec.rb | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/pdk/cli/exec.rb b/lib/pdk/cli/exec.rb index dac74edc9..dcc3d0d1d 100644 --- a/lib/pdk/cli/exec.rb +++ b/lib/pdk/cli/exec.rb @@ -121,6 +121,24 @@ def update_environment(additional_env) @environment.merge!(additional_env) end + def check_for_legacy_env_vars + if ENV['PUPPET_GEM_VERSION'] + PDK.logger.warn_once _( + 'PUPPET_GEM_VERSION is not supported by PDK. ' \ + 'Please use the --puppet-version option on your PDK command ' \ + 'or set the PDK_PUPPET_VERSION environment variable instead', + ) + @process.environment['PUPPET_GEM_VERSION'] = nil + end + + %w[FACTER HIERA].each do |gem| + if ENV["#{gem}_GEM_VERSION"] + PDK.logger.warn_once _("#{gem}_GEM_VERSION is not supported by PDK.") + @process.environment["#{gem}_GEM_VERSION"] = nil + end + end + end + def execute! # Start spinning if configured. @spinner.auto_spin if @spinner @@ -130,6 +148,8 @@ def execute! @process.environment[k] = v end + check_for_legacy_env_vars + @process.environment['BUNDLE_IGNORE_CONFIG'] = '1' if [:module, :pwd].include?(context) diff --git a/spec/acceptance/version_changer_spec.rb b/spec/acceptance/version_changer_spec.rb index f02420a24..a7aa8f2e3 100644 --- a/spec/acceptance/version_changer_spec.rb +++ b/spec/acceptance/version_changer_spec.rb @@ -4,6 +4,21 @@ context 'in a new module' do include_context 'in a new module', 'version_select' + %w[PUPPET FACTER HIERA].each do |gem| + context "when the legacy #{gem}_GEM_VERSION environment variable is used" do + env_line = if Gem.win_platform? + "$env:#{gem}_GEM_VERSION=1.0.0" + else + "#{gem}_GEM_VERSION=1.0.0" + end + + describe command("#{env_line} pdk validate") do + its(:exit_status) { is_expected.to eq(0) } + its(:stderr) { is_expected.to match(%r{#{gem}_GEM_VERSION is not supported by PDK}im) } + end + end + end + %w[5.5.0 4.10.10].each do |puppet_version| describe command("pdk validate --puppet-version #{puppet_version}") do its(:exit_status) { is_expected.to eq(0) }