Skip to content

Commit

Permalink
(PDK-1337) Warn and unset any legacy *_GEM_VERSION env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Jun 3, 2019
1 parent 1890706 commit 2ac43e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/pdk/cli/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions spec/acceptance/version_changer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
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
if Gem.win_platform?
pre_cmd = "$env:#{gem}_GEM_VERSION='1.0.0';"
post_cmd = "; remove-item env:\\#{gem}_GEM_VERSION"
else
pre_cmd = "#{gem}_GEM_VERSION=1.0.0"
post_cmd = ''
end

describe command("#{pre_cmd} pdk validate#{post_cmd}") 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) }
Expand Down

0 comments on commit 2ac43e4

Please sign in to comment.