diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index d4c15cf3a..80d167ea3 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -11,32 +11,15 @@ expeditor: steps: -- label: run-specs-ruby-2.7 +- label: run-specs-ruby-3.1 command: - .expeditor/run_linux_tests.sh rspec expeditor: executor: docker: - image: ruby:2.7 + image: ruby:3.1 -- label: run-specs-ruby-3.0 - command: - - .expeditor/run_linux_tests.sh rspec - expeditor: - executor: - docker: - image: ruby:3.0 - -- label: run-specs-windows-2.7 - command: - - powershell .expeditor/run_windows_tests.ps1 rspec - expeditor: - executor: - docker: - host_os: windows - image: rubydistros/windows-2019:2.7 - -- label: run-specs-windows-ruby-3.0 +- label: run-specs-windows-ruby-3.1 command: - powershell .expeditor/run_windows_tests.ps1 rspec expeditor: @@ -44,20 +27,24 @@ steps: docker: host_os: windows shell: ["powershell", "-Command"] - image: rubydistros/windows-2019:3.0 + image: rubydistros/windows-2019:3.1 + environment: + - FORCE_FFI_YAJL=ext + - EXPIRE_CACHE=true + - CHEF_LICENSE=accept-no-persist -- label: cookstyle-generator-cb-tests-ruby-2.7 +- label: cookstyle-generator-cb-tests-ruby-3.1 command: - .expeditor/run_linux_tests.sh "rake style:cookstyle" expeditor: executor: docker: - image: ruby:2.7 + image: ruby:3.1 -- label: chefstyle-tests-ruby-2.7 +- label: chefstyle-tests-ruby-3.1 command: - .expeditor/run_linux_tests.sh "rake style:chefstyle" expeditor: executor: docker: - image: ruby:2.7 + image: ruby:3.1 diff --git a/Gemfile b/Gemfile index 0319f14f6..ec94c3d7e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,8 +7,8 @@ group :test do gem "rspec", "~> 3.8" gem "rspec-expectations", "~> 3.8" gem "rspec-mocks", "~> 3.8" - gem "cookstyle", "=7.7.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command - gem "chefstyle", "=1.6.2" + gem "cookstyle", "=7.32.2" # this forces dependabot PRs to open which triggers cookstyle CI on the chef generate command + gem "chefstyle", "=2.2.3" gem "test-kitchen", ">= 2.11.1" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6") diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 1a4018f99..08328483d 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -43,7 +43,11 @@ Gem::Specification.new do |gem| gem.add_dependency "mixlib-shellout", ">= 2.0", "< 4.0" gem.add_dependency "ffi-yajl", ">= 1.0", "< 3.0" gem.add_dependency "minitar", "~> 0.6" - gem.add_dependency "chef", ">= 16.0" + if RUBY_VERSION.match?(/3.1/) + gem.add_dependency "chef", "~> 18.0" + else + gem.add_dependency "chef", ">= 16.0" + end gem.add_dependency "solve", "< 5.0", "> 2.0" gem.add_dependency "addressable", ">= 2.3.5", "< 2.9" gem.add_dependency "cookbook-omnifetch", "~> 0.5" diff --git a/lib/chef-cli/helpers.rb b/lib/chef-cli/helpers.rb index 9cdabd46e..6c72237ed 100644 --- a/lib/chef-cli/helpers.rb +++ b/lib/chef-cli/helpers.rb @@ -144,7 +144,7 @@ def expected_omnibus_root def default_package_home if Chef::Platform.windows? - File.join(ENV["LOCALAPPDATA"], ChefCLI::Dist::PRODUCT_PKG_HOME) + File.join(ENV["LOCALAPPDATA"], ChefCLI::Dist::PRODUCT_PKG_HOME).gsub("\\", "/") else File.expand_path("~/.#{ChefCLI::Dist::PRODUCT_PKG_HOME}") end diff --git a/lib/chef-cli/policyfile/artifactory_cookbook_source.rb b/lib/chef-cli/policyfile/artifactory_cookbook_source.rb index f3bc20f99..0e8385605 100644 --- a/lib/chef-cli/policyfile/artifactory_cookbook_source.rb +++ b/lib/chef-cli/policyfile/artifactory_cookbook_source.rb @@ -54,14 +54,12 @@ def preferred_source_for?(cookbook_name) end def universe_graph - @universe_graph ||= begin - full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end diff --git a/lib/chef-cli/policyfile/chef_server_cookbook_source.rb b/lib/chef-cli/policyfile/chef_server_cookbook_source.rb index b08453e8c..78c092e4b 100644 --- a/lib/chef-cli/policyfile/chef_server_cookbook_source.rb +++ b/lib/chef-cli/policyfile/chef_server_cookbook_source.rb @@ -52,14 +52,12 @@ def preferred_source_for?(cookbook_name) end def universe_graph - @universe_graph ||= begin - full_chef_server_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_chef_server_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end @@ -90,9 +88,7 @@ def http_connection_for(base_url) def full_chef_server_graph @full_chef_server_graph ||= - begin - http_connection_for(uri.to_s).get("/universe") - end + http_connection_for(uri.to_s).get("/universe") end end end diff --git a/lib/chef-cli/policyfile/community_cookbook_source.rb b/lib/chef-cli/policyfile/community_cookbook_source.rb index 56620a815..e637f89d9 100644 --- a/lib/chef-cli/policyfile/community_cookbook_source.rb +++ b/lib/chef-cli/policyfile/community_cookbook_source.rb @@ -52,14 +52,12 @@ def ==(other) end def universe_graph - @universe_graph ||= begin - full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| - normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| - deps_by_version[version] = metadata["dependencies"] - deps_by_version - end - normalized_graph + @universe_graph ||= full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)| + normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)| + deps_by_version[version] = metadata["dependencies"] + deps_by_version end + normalized_graph end end diff --git a/lib/chef-cli/policyfile/delivery_supermarket_source.rb b/lib/chef-cli/policyfile/delivery_supermarket_source.rb index 165f78865..db64d67ea 100644 --- a/lib/chef-cli/policyfile/delivery_supermarket_source.rb +++ b/lib/chef-cli/policyfile/delivery_supermarket_source.rb @@ -66,15 +66,13 @@ def default_source_args end def universe_graph - @universe_graph ||= begin - @community_source.universe_graph.inject({}) do |truncated, (cookbook_name, version_and_deps_list)| - sorted_versions = version_and_deps_list.keys.sort_by do |version_string| - Semverse::Version.new(version_string) - end - greatest_version = sorted_versions.last - truncated[cookbook_name] = { greatest_version => version_and_deps_list[greatest_version] } - truncated + @universe_graph ||= @community_source.universe_graph.inject({}) do |truncated, (cookbook_name, version_and_deps_list)| + sorted_versions = version_and_deps_list.keys.sort_by do |version_string| + Semverse::Version.new(version_string) end + greatest_version = sorted_versions.last + truncated[cookbook_name] = { greatest_version => version_and_deps_list[greatest_version] } + truncated end end diff --git a/lib/chef-cli/policyfile/policyfile_location_specification.rb b/lib/chef-cli/policyfile/policyfile_location_specification.rb index 91ea19bd9..af5aa5bb5 100644 --- a/lib/chef-cli/policyfile/policyfile_location_specification.rb +++ b/lib/chef-cli/policyfile/policyfile_location_specification.rb @@ -62,20 +62,18 @@ def revision_id # @return A policyfile lock fetcher compatible with the given source_options def fetcher - @fetcher ||= begin - if source_options[:path] && !source_options[:git] - Policyfile::LocalLockFetcher.new(name, source_options, storage_config) - elsif source_options[:remote] - Policyfile::RemoteLockFetcher.new(name, source_options) - elsif source_options[:server] - Policyfile::ChefServerLockFetcher.new(name, source_options, chef_config) - elsif source_options[:git] - Policyfile::GitLockFetcher.new(name, source_options, storage_config) - else - raise ChefCLI::InvalidPolicyfileLocation.new( - "Invalid policyfile lock location type. The supported locations are: #{LOCATION_TYPES.join(", ")}" - ) - end + @fetcher ||= if source_options[:path] && !source_options[:git] + Policyfile::LocalLockFetcher.new(name, source_options, storage_config) + elsif source_options[:remote] + Policyfile::RemoteLockFetcher.new(name, source_options) + elsif source_options[:server] + Policyfile::ChefServerLockFetcher.new(name, source_options, chef_config) + elsif source_options[:git] + Policyfile::GitLockFetcher.new(name, source_options, storage_config) + else + raise ChefCLI::InvalidPolicyfileLocation.new( + "Invalid policyfile lock location type. The supported locations are: #{LOCATION_TYPES.join(", ")}" + ) end end @@ -106,9 +104,7 @@ def errors # # @return [PolicyfileLock] the loaded policyfile lock def policyfile_lock - @policyfile_lock ||= begin - PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(fetcher.lock_data) - end + @policyfile_lock ||= PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(fetcher.lock_data) end # @return [Hash] The source_options that describe how to fetch this exact lock again diff --git a/lib/chef-cli/policyfile_services/export_repo.rb b/lib/chef-cli/policyfile_services/export_repo.rb index 70ff6955e..56930b79e 100644 --- a/lib/chef-cli/policyfile_services/export_repo.rb +++ b/lib/chef-cli/policyfile_services/export_repo.rb @@ -121,12 +121,12 @@ def with_staging_dir random_string = SecureRandom.hex(2) path = "chef-export-#{random_string}" Dir.mktmpdir(path) do |d| - begin - @staging_dir = d - yield - ensure - @staging_dir = nil - end + + @staging_dir = d + yield + ensure + @staging_dir = nil + end end diff --git a/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb b/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb index e3f5f0e18..82f8fa310 100644 --- a/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb +++ b/lib/chef-cli/skeletons/code_generator/files/default/repo/cookbooks/example/recipes/default.rb @@ -1,7 +1,7 @@ # This is a Chef Infra Client recipe file. It can be used to specify resources # which will apply configuration to a server. -log "Welcome to Chef Infra Client, #{node['example']['name']}!" do +log "Welcome to Chef Infra Client, #{node["example"]["name"]}!" do level :info end diff --git a/spec/unit/command/generator_commands/repo_spec.rb b/spec/unit/command/generator_commands/repo_spec.rb index 86499b831..77fec47e3 100644 --- a/spec/unit/command/generator_commands/repo_spec.rb +++ b/spec/unit/command/generator_commands/repo_spec.rb @@ -256,7 +256,7 @@ def generator_context let(:file) { "cookbooks/example/recipes/default.rb" } it "has the right contents" do - expect(file_contents).to match(/log "Welcome to Chef Infra Client, \#\{node\['example'\]\['name'\]\}!" do/) + expect(file_contents).to match(/log "Welcome to Chef Infra Client, \#\{node\["example"\]\["name"\]\}!" do/) end end end diff --git a/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb b/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb index ace053bab..671a742cc 100644 --- a/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb +++ b/spec/unit/kitchen/provisioner/chef_zero_capture_spec.rb @@ -60,10 +60,10 @@ end after do - begin - subject.cleanup_sandbox - rescue # rubocop:disable Lint/HandleExceptions - end + + subject.cleanup_sandbox + rescue # rubocop:disable Lint/HandleExceptions + end end diff --git a/spec/unit/policyfile/comparison_base_spec.rb b/spec/unit/policyfile/comparison_base_spec.rb index d11b4f986..33c2f3298 100644 --- a/spec/unit/policyfile/comparison_base_spec.rb +++ b/spec/unit/policyfile/comparison_base_spec.rb @@ -251,11 +251,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do @@ -285,11 +285,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/clean_policies_spec.rb b/spec/unit/policyfile_services/clean_policies_spec.rb index 6c8a010ee..a4cf0dcd7 100644 --- a/spec/unit/policyfile_services/clean_policies_spec.rb +++ b/spec/unit/policyfile_services/clean_policies_spec.rb @@ -46,11 +46,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do @@ -196,11 +196,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do @@ -215,7 +215,7 @@ # this will continue to print that out until they remove HTTPServerException expected_message = <<~ERROR Failed to delete some policy revisions: - - appserver (4444444444444444444444444444444444444444444444444444444444444444): Net::HTTPServerException 403 \"Unauthorized\" + - appserver (4444444444444444444444444444444444444444444444444444444444444444): Net::HTTPClientException 403 \"Unauthorized\" ERROR expect { clean_policies_service.run }.to raise_error do |error| diff --git a/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb b/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb index d30133109..7fd996025 100644 --- a/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb +++ b/spec/unit/policyfile_services/clean_policy_cookbooks_spec.rb @@ -103,11 +103,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/push_archive_spec.rb b/spec/unit/policyfile_services/push_archive_spec.rb index 1310c4a31..85cb2bb8b 100644 --- a/spec/unit/policyfile_services/push_archive_spec.rb +++ b/spec/unit/policyfile_services/push_archive_spec.rb @@ -129,13 +129,13 @@ def create_archive context "with an invalid archive" do let(:exception) do - begin - push_archive_service.run - rescue ChefCLI::PolicyfilePushArchiveError => e - e - else - nil - end + + push_archive_service.run + rescue ChefCLI::PolicyfilePushArchiveError => e + e + else + nil + end let(:exception_cause) { exception.cause } diff --git a/spec/unit/policyfile_services/rm_policy_group_spec.rb b/spec/unit/policyfile_services/rm_policy_group_spec.rb index 5dc713239..73cc32ee3 100644 --- a/spec/unit/policyfile_services/rm_policy_group_spec.rb +++ b/spec/unit/policyfile_services/rm_policy_group_spec.rb @@ -93,11 +93,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/rm_policy_spec.rb b/spec/unit/policyfile_services/rm_policy_spec.rb index 66e9771ee..bb87f6e5b 100644 --- a/spec/unit/policyfile_services/rm_policy_spec.rb +++ b/spec/unit/policyfile_services/rm_policy_spec.rb @@ -69,11 +69,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do @@ -108,11 +108,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/show_policy_spec.rb b/spec/unit/policyfile_services/show_policy_spec.rb index e03fa43de..aa985c10b 100644 --- a/spec/unit/policyfile_services/show_policy_spec.rb +++ b/spec/unit/policyfile_services/show_policy_spec.rb @@ -65,11 +65,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end let(:policies_url) { "/policies" } @@ -823,11 +823,11 @@ end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do diff --git a/spec/unit/policyfile_services/undelete_spec.rb b/spec/unit/policyfile_services/undelete_spec.rb index 1acddb378..02319bd79 100644 --- a/spec/unit/policyfile_services/undelete_spec.rb +++ b/spec/unit/policyfile_services/undelete_spec.rb @@ -185,11 +185,11 @@ def next_time end let(:http_exception) do - begin - response.error! - rescue => e - e - end + + response.error! + rescue => e + e + end before do