Skip to content

Commit 28b3516

Browse files
authored
Merge pull request #1797 from beechtom/1779/bolt-gem
(GH-1779) Warn when Bolt is installed as a gem
2 parents 347f590 + 9c1156f commit 28b3516

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
55
# Disable analytics when running in development
66
ENV['BOLT_DISABLE_ANALYTICS'] = 'true'
77

8+
# Disable warning that Bolt may be installed as a gem
9+
ENV['BOLT_GEM'] = 'true'
10+
811
gemspec
912

1013
# Bolt server gems are managed here not in the gemspec

lib/bolt/cli.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,20 @@ def analytics
804804
end
805805

806806
def bundled_content
807+
# If the bundled content directory is empty, Bolt is likely installed as a gem.
808+
if ENV['BOLT_GEM'].nil? && incomplete_install?
809+
msg = <<~MSG.chomp
810+
Bolt may be installed as a gem. To use Bolt reliably and with all of its
811+
dependencies, uninstall the 'bolt' gem and install Bolt as a package:
812+
https://puppet.com/docs/bolt/latest/bolt_installing.html
813+
814+
If you meant to install Bolt as a gem and want to disable this warning,
815+
set the BOLT_GEM environment variable.
816+
MSG
817+
818+
@logger.warn(msg)
819+
end
820+
807821
# We only need to enumerate bundled content when running a task or plan
808822
content = { 'Plan' => [],
809823
'Task' => [],
@@ -827,5 +841,11 @@ def config_loaded
827841
MSG
828842
@logger.debug(msg)
829843
end
844+
845+
# Gem installs include the aggregate, canary, and puppetdb_fact modules, while
846+
# package installs include modules listed in the Bolt repo Puppetfile
847+
def incomplete_install?
848+
(Dir.children(Bolt::PAL::MODULES_PATH) - %w[aggregate canary puppetdb_fact]).empty?
849+
end
830850
end
831851
end

spec/bolt/cli_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,37 @@ def stub_config(file_content = {})
5656
allow(Bolt::Util).to receive(:read_optional_yaml_hash).and_return(file_content)
5757
end
5858

59+
context 'gem install' do
60+
around(:each) do |example|
61+
original_value = ENV['BOLT_GEM']
62+
example.run
63+
ensure
64+
ENV['BOLT_GEM'] = original_value
65+
end
66+
67+
it 'displays a warning when Bolt is installed as a gem' do
68+
ENV.delete('BOLT_GEM')
69+
70+
cli = Bolt::CLI.new(%w[task show])
71+
allow(cli).to receive(:incomplete_install?).and_return(true)
72+
cli.execute(cli.parse)
73+
74+
output = @log_output.readlines.join
75+
expect(output).to match(/Bolt may be installed as a gem/)
76+
end
77+
78+
it 'does not display a warning when BOLT_GEM is set' do
79+
ENV['BOLT_GEM'] = 'true'
80+
81+
cli = Bolt::CLI.new(%w[task show])
82+
allow(cli).to receive(:incomplete_install?).and_return(true)
83+
cli.execute(cli.parse)
84+
85+
output = @log_output.readlines.join
86+
expect(output).not_to match(/Bolt may be installed as a gem/)
87+
end
88+
end
89+
5990
context "without a config file" do
6091
let(:project) { Bolt::Project.new('.') }
6192
before(:each) do

0 commit comments

Comments
 (0)