From a50369b8719648f86f8bec18bb39d2cc85d83658 Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Tue, 23 May 2023 16:40:57 +0530 Subject: [PATCH 01/48] Chef license commands implementation Signed-off-by: Ashique P S --- chef-cli.gemspec | 1 + lib/chef-cli/builtin_commands.rb | 2 + lib/chef-cli/command/license.rb | 105 +++++++++++++++++++++++++++++++ lib/chef-cli/licensing/base.rb | 43 +++++++++++++ lib/chef-cli/licensing/config.rb | 25 ++++++++ 5 files changed, 176 insertions(+) create mode 100644 lib/chef-cli/command/license.rb create mode 100644 lib/chef-cli/licensing/base.rb create mode 100644 lib/chef-cli/licensing/config.rb diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 968898d2..40ed1b93 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,4 +50,5 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" + gem.add_dependency "chef-licensing", "~> 0.4" end diff --git a/lib/chef-cli/builtin_commands.rb b/lib/chef-cli/builtin_commands.rb index 6bcee200..5102bcb1 100644 --- a/lib/chef-cli/builtin_commands.rb +++ b/lib/chef-cli/builtin_commands.rb @@ -57,4 +57,6 @@ c.builtin "describe-cookbook", :DescribeCookbook, require_path: "chef-cli/command/describe_cookbook", desc: "Prints cookbook checksum information used for cookbook identifier" + c.builtin "license", :License, require_path: "chef-cli/command/license", + desc: "View the active license or generate the free/trial licenses for the chef workstation" end diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb new file mode 100644 index 00000000..148f4ae5 --- /dev/null +++ b/lib/chef-cli/command/license.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +# Copyright:: Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require_relative "base" +require "chef-cli/licensing/base" +require "byebug" +require_relative "../configurable" + +module ChefCLI + module Command + + # This class will manage the license command in the chef-cli + class License < Base + + include Configurable + + MAIN_COMMAND_HELP = <<~HELP + Usage: #{ChefCLI::Dist::EXEC} license [SUBCOMMAND] + + `#{ChefCLI::Dist::EXEC} license` command will validate the existing license + or will help you interactively generate new free/trial license and activate the + commercial license the chef team has sent you through email. + HELP + + SUB_COMMANDS = [ + { name: "list", description: "List the currently active license" }, + { name: "add", description: "Create a new Free/Trial license or activate the commercial license" } + ] + + attr_accessor :ui + + def self.banner + <<~BANNER + #{MAIN_COMMAND_HELP} + Subcommands: + #{SUB_COMMANDS.map do |c| + " #{c[:name].ljust(7)}#{c[:description]}" + end.join("\n") } + + Options: + BANNER + end + + def initialize + super + + @ui = UI.new + end + + def run(params) + config_license_debug if debug? + remaining_args = parse_options(params) + return 1 unless validate_params!(remaining_args) + + if remaining_args.blank? + ChefCLI::Licensing::Base.validate + else + ChefCLI::Licensing::Base.send(remaining_args[0]) + end + end + + def debug? + !!config[:debug] + end + + def validate_params!(args) + if args.length > 1 + ui.err("Too many arguments") + return false + end + + valid_subcommands = SUB_COMMANDS.collect { |c| c[:name] } + args.each do |arg| + next if valid_subcommands.include?(arg) + + ui.err("Invalid option: #{arg}") + return false + end + + true + end + + private + + def config_license_debug + ChefLicensing.output = ui + end + end + end +end diff --git a/lib/chef-cli/licensing/base.rb b/lib/chef-cli/licensing/base.rb new file mode 100644 index 00000000..50c2ffa1 --- /dev/null +++ b/lib/chef-cli/licensing/base.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +# Copyright:: Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "chef-licensing" +require_relative "config" + +module ChefCLI + module Licensing + class Base + class << self + + def validate + ChefLicensing.fetch_and_persist.each do |license_key| + ui.msg "License Key: #{license_key}" + end + end + + def list + ChefLicensing.list_license_keys_info + end + + def add + ChefLicensing.add_license + end + end + end + end +end diff --git a/lib/chef-cli/licensing/config.rb b/lib/chef-cli/licensing/config.rb new file mode 100644 index 00000000..5777c567 --- /dev/null +++ b/lib/chef-cli/licensing/config.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# Copyright:: Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "chef-licensing" + +ChefLicensing.configure do |config| + config.chef_product_name = "chef" + config.chef_entitlement_id = "a5213d76-181f-4924-adba-4b7ed2b098b5" + config.chef_executable_name = "chef" +end From c8a515c8aded0829f592195c282c9cc877fc8b63 Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Tue, 23 May 2023 17:05:32 +0530 Subject: [PATCH 02/48] Added the faraday_middleware for testing Signed-off-by: Ashique P S --- lib/chef-cli/licensing/base.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/chef-cli/licensing/base.rb b/lib/chef-cli/licensing/base.rb index 50c2ffa1..a14e76ff 100644 --- a/lib/chef-cli/licensing/base.rb +++ b/lib/chef-cli/licensing/base.rb @@ -18,6 +18,8 @@ require "chef-licensing" require_relative "config" +require "faraday_middleware" + module ChefCLI module Licensing From bd63ea5b91fab09bad3a665aeb911a5cd7011232 Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Wed, 24 May 2023 10:21:48 +0530 Subject: [PATCH 03/48] Fixed the issue with ui object Signed-off-by: Ashique P S --- lib/chef-cli/licensing/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef-cli/licensing/base.rb b/lib/chef-cli/licensing/base.rb index a14e76ff..43fa61f6 100644 --- a/lib/chef-cli/licensing/base.rb +++ b/lib/chef-cli/licensing/base.rb @@ -28,7 +28,7 @@ class << self def validate ChefLicensing.fetch_and_persist.each do |license_key| - ui.msg "License Key: #{license_key}" + puts "License Key: #{license_key}" end end From f90fa615e852b838fda4315c89fd26e5efd6e73f Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Wed, 24 May 2023 10:26:10 +0530 Subject: [PATCH 04/48] Chefstyle fixes Signed-off-by: Ashique P S --- lib/chef-cli/command/license.rb | 6 +++--- lib/chef-cli/licensing/base.rb | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index 148f4ae5..9e7381e7 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -39,7 +39,7 @@ class License < Base SUB_COMMANDS = [ { name: "list", description: "List the currently active license" }, - { name: "add", description: "Create a new Free/Trial license or activate the commercial license" } + { name: "add", description: "Create a new Free/Trial license or activate the commercial license" }, ] attr_accessor :ui @@ -49,8 +49,8 @@ def self.banner #{MAIN_COMMAND_HELP} Subcommands: #{SUB_COMMANDS.map do |c| - " #{c[:name].ljust(7)}#{c[:description]}" - end.join("\n") } + " #{c[:name].ljust(7)}#{c[:description]}" + end.join("\n") } Options: BANNER diff --git a/lib/chef-cli/licensing/base.rb b/lib/chef-cli/licensing/base.rb index 43fa61f6..a7b930c0 100644 --- a/lib/chef-cli/licensing/base.rb +++ b/lib/chef-cli/licensing/base.rb @@ -20,7 +20,6 @@ require_relative "config" require "faraday_middleware" - module ChefCLI module Licensing class Base From 2a7e9fb7cf1a81dba4b08446b3d4c4770f589929 Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Wed, 24 May 2023 10:26:32 +0530 Subject: [PATCH 05/48] Specs for the license commands Signed-off-by: Ashique P S --- spec/unit/command/license_spec.rb | 152 ++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 spec/unit/command/license_spec.rb diff --git a/spec/unit/command/license_spec.rb b/spec/unit/command/license_spec.rb new file mode 100644 index 00000000..7a432f00 --- /dev/null +++ b/spec/unit/command/license_spec.rb @@ -0,0 +1,152 @@ +# +# Copyright:: Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "spec_helper" +require "chef-cli/command/license" +require "shared/command_with_ui_object" +require "chef-cli/licensing/base" + +describe ChefCLI::Command::License do + it_behaves_like "a command with a UI object" + + let(:params) { [] } + let(:ui) { TestHelpers::TestUI.new } + + let(:command) do + c = described_class.new + c.validate_params!(params) + c.ui = ui + c + end + + it "disables debug by default" do + expect(command.debug?).to be(false) + end + + context "invalid parameters passed" do + let(:multiple_params) { %w{add list} } + let(:invalid_command) { %w{not_a_subcommand} } + + it "should fail with errors when multiple subcommands passed" do + expect(command.run(multiple_params)).to eq(1) + end + + it "should fail for invalid argument" do + expect(command.run(invalid_command)).to eq(1) + end + end + + context "license command" do + context "when pre-accepted license exists" do + let(:license_keys) { %w{tsmc-abcd} } + + before(:each) do + allow(ChefLicensing).to receive(:fetch_and_persist).and_return(license_keys) + end + + it "should be successful" do + expect { command.run(params) }.not_to raise_exception + end + + it "should return the correct license key" do + expect(command.run(params)).to eq(license_keys) + end + end + + context "when no licenses are accepted previously" do + let(:new_key) { ["tsmc-123456789"] } + before(:each) do + ChefLicensing.configure do |config| + config.license_server_url = "https://license.test" + config.license_server_api_key = "token-123" + config.chef_product_name = "chef" + config.chef_entitlement_id = "chef-entitled-id" + config.chef_executable_name = "chef" + end + + # Disable the active license check + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:licenses_active?).and_return(false) + # Disable the UI engine + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:append_extra_info_to_tui_engine) + # Disable the API call to fetch the license type + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:get_license_type).and_return("free") + # Disable the overwriting to the license.yml file + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::File).to receive(:persist) + + # Mocks the user prompt to enter the license + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::Prompt).to receive(:fetch).and_return(new_key) + end + + it "should create and stores the new license" do + expect { command.run(params) }.not_to raise_exception + end + + it "should be same as the user entered license" do + expect(command.run(params)).to eq(new_key) + end + end + end + + context "chef license list command" do + let(:params) { %w{list} } + let(:license_key) { "tsmn-123123" } + + before do + command.ui = ui + end + + context "when no licenses are accepted" do + it "should return the correct error message" do + expect(command.run(params)).to eq(0) + + expect(ui.output).to eq("No license keys found on disk.") + end + end + + context "when there is a valid license" do + before do + allow(ChefLicensing).to receive(:list_license_keys_info).and_return(license_key) + end + + it "should print the license details" do + expect(command.run(params)).to eq(license_key) + end + end + end + + context "chef license add command" do + let(:params) { %w{add} } + let(:license_key) { ["tsmn-123123"] } + + before do + # Disable the API call to fetch the license type + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:get_license_type).and_return("free") + # Disable the overwriting to the license.yml file + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::File).to receive(:persist) + # Mocks the user prompt to enter the license + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::Prompt).to receive(:fetch).and_return(license_key) + end + + it "should not raise any errors" do + expect { command.run(params) }.not_to raise_exception + end + + it "should create and store the new license" do + expect(command.run(params)).to eq(license_key) + end + end +end From 697862fd78fd765f09b302a72579ca4d98e83135 Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Fri, 26 May 2023 11:00:54 +0530 Subject: [PATCH 06/48] Added option to pass license key as a param Signed-off-by: Ashique P S --- lib/chef-cli/builtin_commands.rb | 2 +- lib/chef-cli/command/license.rb | 8 ++++++-- lib/chef-cli/licensing/config.rb | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/chef-cli/builtin_commands.rb b/lib/chef-cli/builtin_commands.rb index 5102bcb1..1b239792 100644 --- a/lib/chef-cli/builtin_commands.rb +++ b/lib/chef-cli/builtin_commands.rb @@ -58,5 +58,5 @@ c.builtin "describe-cookbook", :DescribeCookbook, require_path: "chef-cli/command/describe_cookbook", desc: "Prints cookbook checksum information used for cookbook identifier" c.builtin "license", :License, require_path: "chef-cli/command/license", - desc: "View the active license or generate the free/trial licenses for the chef workstation" + desc: "Create & install a new license on the system or view installed license(s)." end diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index 9e7381e7..d30c2749 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -38,10 +38,14 @@ class License < Base HELP SUB_COMMANDS = [ - { name: "list", description: "List the currently active license" }, - { name: "add", description: "Create a new Free/Trial license or activate the commercial license" }, + { name: "list", description: "List details of the license(s) installed on the system." }, + { name: "add", description: "Create & install a Free/ Trial license or install a Commercial license on the system." }, ] + option :chef_license_key, + long: "--chef-license-key LICENSE", + description: "New license key to accept and store in the system" + attr_accessor :ui def self.banner diff --git a/lib/chef-cli/licensing/config.rb b/lib/chef-cli/licensing/config.rb index 5777c567..98f82664 100644 --- a/lib/chef-cli/licensing/config.rb +++ b/lib/chef-cli/licensing/config.rb @@ -19,7 +19,7 @@ require "chef-licensing" ChefLicensing.configure do |config| - config.chef_product_name = "chef" - config.chef_entitlement_id = "a5213d76-181f-4924-adba-4b7ed2b098b5" + config.chef_product_name = "workstation" + config.chef_entitlement_id = "x6f3bc76-a94f-4b6c-bc97-4b7ed2b045c0" config.chef_executable_name = "chef" end From 416f4fffde442f2db4ecc6a9728ba7da3a6a23d7 Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Fri, 26 May 2023 12:01:03 +0530 Subject: [PATCH 07/48] Updated the chef-licensing dependency to fetch from internal artifactory Signed-off-by: Ashique P S --- Gemfile | 4 ++++ chef-cli.gemspec | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 7461ea33..f25f0fc9 100644 --- a/Gemfile +++ b/Gemfile @@ -26,3 +26,7 @@ group :profile do gem "stackprof-webnav" gem "memory_profiler" end + +source "https://artifactory-internal.ps.chef.co/artifactory/api/gems/omnibus-gems-local/" do + gem "chef-licensing" +end \ No newline at end of file diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 40ed1b93..fcfee05e 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,5 +50,5 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" - gem.add_dependency "chef-licensing", "~> 0.4" + # gem.add_dependency "chef-licensing", "~> 0.4" end From a99b5c157a203b66cd30eb27ea95104070b01069 Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Mon, 29 May 2023 11:18:14 +0530 Subject: [PATCH 08/48] Removed the byebug Signed-off-by: Ashique P S --- lib/chef-cli/command/license.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index d30c2749..20da7423 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -18,7 +18,6 @@ require_relative "base" require "chef-cli/licensing/base" -require "byebug" require_relative "../configurable" module ChefCLI From 1ffcadd96bc22b007afd087c1309e2e9823862df Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Fri, 2 Jun 2023 19:23:01 +0530 Subject: [PATCH 09/48] Added the feature flag for the licensing commands Signed-off-by: Ashique P S --- lib/chef-cli/command/license.rb | 8 ++++++++ lib/chef-cli/licensing/base.rb | 3 +++ spec/unit/command/license_spec.rb | 17 ++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index 20da7423..91a05c5a 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -66,6 +66,7 @@ def initialize end def run(params) + validate_feature! config_license_debug if debug? remaining_args = parse_options(params) return 1 unless validate_params!(remaining_args) @@ -103,6 +104,13 @@ def validate_params!(args) def config_license_debug ChefLicensing.output = ui end + + def validate_feature! + return if ChefCLI::Licensing::Base.feature_enabled? + + ui.err("This feature is not enabled! Run `` to enable this feature and try again.") + exit 0 + end end end end diff --git a/lib/chef-cli/licensing/base.rb b/lib/chef-cli/licensing/base.rb index a7b930c0..3cbe4f71 100644 --- a/lib/chef-cli/licensing/base.rb +++ b/lib/chef-cli/licensing/base.rb @@ -24,6 +24,9 @@ module ChefCLI module Licensing class Base class << self + def feature_enabled? + File.exists?(File.join(Dir.home, ".chef/license_feature.json")) + end def validate ChefLicensing.fetch_and_persist.each do |license_key| diff --git a/spec/unit/command/license_spec.rb b/spec/unit/command/license_spec.rb index 7a432f00..6d11f7d0 100644 --- a/spec/unit/command/license_spec.rb +++ b/spec/unit/command/license_spec.rb @@ -26,6 +26,14 @@ let(:params) { [] } let(:ui) { TestHelpers::TestUI.new } + before do + allow(ChefCLI::Licensing::Base).to receive(:feature_enabled?).and_return(true) + # Disable the access of local licenses + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_license_key_from_arg).and_return([]) + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_license_key_from_env).and_return([]) + allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_from_file).and_return([]) + end + let(:command) do c = described_class.new c.validate_params!(params) @@ -110,10 +118,13 @@ end context "when no licenses are accepted" do - it "should return the correct error message" do - expect(command.run(params)).to eq(0) + before do + allow_any_instance_of(ChefLicensing::ListLicenseKeys).to receive(:fetch_license_keys).and_return([]) + allow_any_instance_of(ChefLicensing::ListLicenseKeys).to receive(:fetch_licenses_metadata).and_return([]) + end - expect(ui.output).to eq("No license keys found on disk.") + it "should return the correct error message" do + expect(command.run(params)).to eq([]) end end From cca1d826186a257575489540cacf78933073f8b7 Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Mon, 19 Jun 2023 16:54:50 +0530 Subject: [PATCH 10/48] updated the feature flag file name Signed-off-by: Ashique P S --- lib/chef-cli/licensing/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef-cli/licensing/base.rb b/lib/chef-cli/licensing/base.rb index 3cbe4f71..2b308d8c 100644 --- a/lib/chef-cli/licensing/base.rb +++ b/lib/chef-cli/licensing/base.rb @@ -25,7 +25,7 @@ module Licensing class Base class << self def feature_enabled? - File.exists?(File.join(Dir.home, ".chef/license_feature.json")) + File.exists?(File.join(Dir.home, ".chef/fbffb2ea48910514676e1b7a51c7248290ea958c")) end def validate From 6ef75d677824cc44d28a9f8e6631ff112ed8d4ba Mon Sep 17 00:00:00 2001 From: Ashique P S Date: Tue, 11 Jul 2023 12:30:48 +0530 Subject: [PATCH 11/48] Added chef-licensing gem as a gemspec dependency Signed-off-by: Ashique P S --- Gemfile | 4 ---- chef-cli.gemspec | 2 +- lib/chef-cli/builtin_commands.rb | 7 +++++-- lib/chef-cli/command/license.rb | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index f25f0fc9..7461ea33 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,3 @@ group :profile do gem "stackprof-webnav" gem "memory_profiler" end - -source "https://artifactory-internal.ps.chef.co/artifactory/api/gems/omnibus-gems-local/" do - gem "chef-licensing" -end \ No newline at end of file diff --git a/chef-cli.gemspec b/chef-cli.gemspec index fcfee05e..40ed1b93 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,5 +50,5 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" - # gem.add_dependency "chef-licensing", "~> 0.4" + gem.add_dependency "chef-licensing", "~> 0.4" end diff --git a/lib/chef-cli/builtin_commands.rb b/lib/chef-cli/builtin_commands.rb index 1b239792..0b30069b 100644 --- a/lib/chef-cli/builtin_commands.rb +++ b/lib/chef-cli/builtin_commands.rb @@ -16,6 +16,7 @@ # require_relative "dist" +require "chef-cli/licensing/base" ChefCLI.commands do |c| c.builtin "exec", :Exec, require_path: "chef-cli/command/exec", @@ -57,6 +58,8 @@ c.builtin "describe-cookbook", :DescribeCookbook, require_path: "chef-cli/command/describe_cookbook", desc: "Prints cookbook checksum information used for cookbook identifier" - c.builtin "license", :License, require_path: "chef-cli/command/license", - desc: "Create & install a new license on the system or view installed license(s)." + if ChefCLI::Licensing::Base.feature_enabled? + c.builtin "license", :License, require_path: "chef-cli/command/license", + desc: "Create & install a new license on the system or view installed license(s)." + end end diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index 91a05c5a..a75f6253 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -108,7 +108,7 @@ def config_license_debug def validate_feature! return if ChefCLI::Licensing::Base.feature_enabled? - ui.err("This feature is not enabled! Run `` to enable this feature and try again.") + ui.err("This feature is not enabled! Run `chef license enable true` to enable this feature and try again.") exit 0 end end From edb77173ecc8ec0b907cb9a910d3396bf270c465 Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Thu, 11 Jul 2024 16:07:43 +0530 Subject: [PATCH 12/48] Licensing updates Signed-off-by: Ashique Saidalavi --- chef-cli.gemspec | 2 +- lib/chef-cli/builtin_commands.rb | 7 ++----- lib/chef-cli/command/license.rb | 8 -------- lib/chef-cli/licensing/base.rb | 5 ----- lib/chef-cli/licensing/config.rb | 2 ++ spec/unit/cli_spec.rb | 2 ++ spec/unit/command/license_spec.rb | 8 +++----- .../chefignore | 0 8 files changed, 10 insertions(+), 24 deletions(-) create mode 100644 spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 40ed1b93..7eb070a0 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,5 +50,5 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" - gem.add_dependency "chef-licensing", "~> 0.4" + gem.add_dependency "chef-licensing", "~> 0.7" end diff --git a/lib/chef-cli/builtin_commands.rb b/lib/chef-cli/builtin_commands.rb index 0b30069b..1b239792 100644 --- a/lib/chef-cli/builtin_commands.rb +++ b/lib/chef-cli/builtin_commands.rb @@ -16,7 +16,6 @@ # require_relative "dist" -require "chef-cli/licensing/base" ChefCLI.commands do |c| c.builtin "exec", :Exec, require_path: "chef-cli/command/exec", @@ -58,8 +57,6 @@ c.builtin "describe-cookbook", :DescribeCookbook, require_path: "chef-cli/command/describe_cookbook", desc: "Prints cookbook checksum information used for cookbook identifier" - if ChefCLI::Licensing::Base.feature_enabled? - c.builtin "license", :License, require_path: "chef-cli/command/license", - desc: "Create & install a new license on the system or view installed license(s)." - end + c.builtin "license", :License, require_path: "chef-cli/command/license", + desc: "Create & install a new license on the system or view installed license(s)." end diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index a75f6253..20da7423 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -66,7 +66,6 @@ def initialize end def run(params) - validate_feature! config_license_debug if debug? remaining_args = parse_options(params) return 1 unless validate_params!(remaining_args) @@ -104,13 +103,6 @@ def validate_params!(args) def config_license_debug ChefLicensing.output = ui end - - def validate_feature! - return if ChefCLI::Licensing::Base.feature_enabled? - - ui.err("This feature is not enabled! Run `chef license enable true` to enable this feature and try again.") - exit 0 - end end end end diff --git a/lib/chef-cli/licensing/base.rb b/lib/chef-cli/licensing/base.rb index 2b308d8c..01845fd5 100644 --- a/lib/chef-cli/licensing/base.rb +++ b/lib/chef-cli/licensing/base.rb @@ -18,16 +18,11 @@ require "chef-licensing" require_relative "config" -require "faraday_middleware" module ChefCLI module Licensing class Base class << self - def feature_enabled? - File.exists?(File.join(Dir.home, ".chef/fbffb2ea48910514676e1b7a51c7248290ea958c")) - end - def validate ChefLicensing.fetch_and_persist.each do |license_key| puts "License Key: #{license_key}" diff --git a/lib/chef-cli/licensing/config.rb b/lib/chef-cli/licensing/config.rb index 98f82664..901ebf43 100644 --- a/lib/chef-cli/licensing/config.rb +++ b/lib/chef-cli/licensing/config.rb @@ -22,4 +22,6 @@ config.chef_product_name = "workstation" config.chef_entitlement_id = "x6f3bc76-a94f-4b6c-bc97-4b7ed2b045c0" config.chef_executable_name = "chef" + # config.license_server_url = "https://services.chef.io/licensing" + config.license_server_url = "https://licensing-acceptance.chef.co/License" end diff --git a/spec/unit/cli_spec.rb b/spec/unit/cli_spec.rb index 51c7c18d..10e1515a 100644 --- a/spec/unit/cli_spec.rb +++ b/spec/unit/cli_spec.rb @@ -89,6 +89,8 @@ def mock_shell_out(exitstatus, stdout, stderr) commands_map.builtin "example", :TestCommand, require_path: "unit/fixtures/command/cli_test_command", desc: "Example subcommand for testing" + + allow(ChefCLI::Licensing::Base).to receive(:validate).and_return(true) end context "given no arguments or options" do diff --git a/spec/unit/command/license_spec.rb b/spec/unit/command/license_spec.rb index 6d11f7d0..f3ffc1ce 100644 --- a/spec/unit/command/license_spec.rb +++ b/spec/unit/command/license_spec.rb @@ -27,11 +27,10 @@ let(:ui) { TestHelpers::TestUI.new } before do - allow(ChefCLI::Licensing::Base).to receive(:feature_enabled?).and_return(true) # Disable the access of local licenses allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_license_key_from_arg).and_return([]) allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_license_key_from_env).and_return([]) - allow_any_instance_of(ChefLicensing::LicenseKeyFetcher).to receive(:fetch_from_file).and_return([]) + allow_any_instance_of(ChefLicensing::LicensingService::Local).to receive(:detected?).and_return(false) end let(:command) do @@ -80,7 +79,6 @@ before(:each) do ChefLicensing.configure do |config| config.license_server_url = "https://license.test" - config.license_server_api_key = "token-123" config.chef_product_name = "chef" config.chef_entitlement_id = "chef-entitled-id" config.chef_executable_name = "chef" @@ -104,7 +102,7 @@ end it "should be same as the user entered license" do - expect(command.run(params)).to eq(new_key) + expect(command.run(params)).to include(new_key.first) end end end @@ -157,7 +155,7 @@ end it "should create and store the new license" do - expect(command.run(params)).to eq(license_key) + expect(command.run(params)).to include(license_key.first) end end end diff --git a/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore b/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore new file mode 100644 index 00000000..e69de29b From 8d4a1ab908bbcd486393a90060f0c298db0f103f Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Mon, 29 Jul 2024 11:29:49 +0530 Subject: [PATCH 13/48] Updated the chef-licensing gem version Signed-off-by: Ashique Saidalavi --- chef-cli.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 7eb070a0..35a36fe6 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,5 +50,5 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" - gem.add_dependency "chef-licensing", "~> 0.7" + gem.add_dependency "chef-licensing", "~> 1.0" end From 31497988fdf717250972724ebc1ebb4b6d181f51 Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Wed, 23 Oct 2024 16:42:41 +0530 Subject: [PATCH 14/48] Fixed the spec failure Signed-off-by: Ashique Saidalavi --- spec/unit/command/license_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/unit/command/license_spec.rb b/spec/unit/command/license_spec.rb index f3ffc1ce..a53a7e44 100644 --- a/spec/unit/command/license_spec.rb +++ b/spec/unit/command/license_spec.rb @@ -95,6 +95,7 @@ # Mocks the user prompt to enter the license allow_any_instance_of(ChefLicensing::LicenseKeyFetcher::Prompt).to receive(:fetch).and_return(new_key) + allow(ChefLicensing).to receive(:fetch_and_persist).and_return(new_key) end it "should create and stores the new license" do From 2d0c47c82622294907e618613598404019028c1f Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Wed, 23 Oct 2024 17:59:30 +0530 Subject: [PATCH 15/48] Fixed the chefstyle issues Signed-off-by: Ashique Saidalavi --- lib/chef-cli/command/license.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index 20da7423..676ff2a8 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -28,7 +28,7 @@ class License < Base include Configurable - MAIN_COMMAND_HELP = <<~HELP + MAIN_COMMAND_HELP = <<~HELP.freeze Usage: #{ChefCLI::Dist::EXEC} license [SUBCOMMAND] `#{ChefCLI::Dist::EXEC} license` command will validate the existing license @@ -39,7 +39,7 @@ class License < Base SUB_COMMANDS = [ { name: "list", description: "List details of the license(s) installed on the system." }, { name: "add", description: "Create & install a Free/ Trial license or install a Commercial license on the system." }, - ] + ].freeze option :chef_license_key, long: "--chef-license-key LICENSE", From 2f889d7f183e08dbb5210feb14bebe3fe5613fdf Mon Sep 17 00:00:00 2001 From: ns Date: Thu, 5 Dec 2024 12:47:39 +0530 Subject: [PATCH 16/48] Added plan.sh file (#237) * Added plan.sh file Signed-off-by: nitin sanghi * Change gem file for app bundler on windows and plan.ps1 added Signed-off-by: nitin sanghi * Habitat pkg version sync with version file Signed-off-by: nitin sanghi * Removed duplicate dep and check linux gem are not trying to install on windows Signed-off-by: nitin sanghi * Change in linux plan file and Rakefile to add install task Signed-off-by: nitin sanghi * added hab path aware code changes Signed-off-by: nikhil2611 * fixing the git issue Signed-off-by: nikhil2611 * added the hab env and few command fix for hab path Signed-off-by: nikhil2611 * testing for plan.sh as of now Signed-off-by: nikhil2611 * adding back omnibus methods for testing Signed-off-by: nikhil2611 * initializing pkg_prefix in hab_env Signed-off-by: nikhil2611 * updated the origin variable for chef-cli Signed-off-by: nikhil2611 * Added chef spec gem Signed-off-by: nitin sanghi * testing chefspec changes Signed-off-by: nikhil2611 * Added rspec in bin dir for linking issue Signed-off-by: nitin sanghi * Chefspec dep for rspec fix to 3.12 Signed-off-by: nitin sanghi * Pinning rspec version Signed-off-by: nitin sanghi * Change chef-cli hab pkg origin Signed-off-by: nitin sanghi * Hab channel changed Signed-off-by: nitin sanghi * Chef 17400 pipeline (#241) * Add github action for hab pkg and publish Signed-off-by: nitin sanghi * Added version check on new hab pkg Signed-off-by: nitin sanghi * removed extra keyword for triggering pipeline Signed-off-by: nitin sanghi * pkg iden added using vars Signed-off-by: nitin sanghi * list all pkg to verify pkg installed Signed-off-by: nitin sanghi * Installing hab build using hart file Signed-off-by: nitin sanghi * Installing hab build using hart file Signed-off-by: nitin sanghi * Installing hab build using hart file Signed-off-by: nitin sanghi * pipeline test commit Signed-off-by: nitin sanghi * pipeline test commit Signed-off-by: nitin sanghi * pipeline test commit Signed-off-by: nitin sanghi * pipeline test commit Signed-off-by: nitin sanghi * pipeline test commit Signed-off-by: nitin sanghi * sudo for installing hab pkg Signed-off-by: nitin sanghi * sudo for installing hab pkg Signed-off-by: nitin sanghi * sudo for installing hab pkg Signed-off-by: nitin sanghi * sudo for installing hab pkg Signed-off-by: nitin sanghi * hart file version change Signed-off-by: nitin sanghi * Change pkg_indent Signed-off-by: nitin sanghi * Change pkg_indent Signed-off-by: nitin sanghi * version regex changed Signed-off-by: nitin sanghi * windows pipeline change Signed-off-by: nitin sanghi * windows pipeline change Signed-off-by: nitin sanghi * windows pipeline change Signed-off-by: nitin sanghi * windows pipeline change Signed-off-by: nitin sanghi * Windows chef-cli hab version check Signed-off-by: nitin sanghi * Windows chef-cli hab version check Signed-off-by: nitin sanghi * Windows chef-cli hab version check Signed-off-by: nitin sanghi * Change the message in test phase and throw error Signed-off-by: nitin sanghi * Change the message in test phase and throw error Signed-off-by: nitin sanghi * Hab pipeline using buildkite Signed-off-by: nitin sanghi * hab build yml file added Signed-off-by: nitin sanghi --------- Signed-off-by: nitin sanghi --------- Signed-off-by: nitin sanghi Signed-off-by: nikhil2611 Co-authored-by: nikhil2611 Co-authored-by: Nikhil Gupta <35272911+nikhil2611@users.noreply.github.com> --- .expeditor/build.habitat.yml | 9 ++ .../buildkite/artifact.habitat.test.ps1 | 86 +++++++++++++++++ .expeditor/buildkite/artifact.habitat.test.sh | 71 ++++++++++++++ .expeditor/config.yml | 35 ++++++- .expeditor/habitat-test.pipeline.yml | 35 +++++++ Gemfile | 15 +-- Rakefile | 3 + chef-cli.gemspec | 1 - habitat/plan.ps1 | 92 +++++++++++++++++++ habitat/plan.sh | 76 +++++++++++++++ habitat/tests/test.ps1 | 21 +++++ habitat/tests/test.sh | 26 ++++++ lib/chef-cli/command/env.rb | 14 +-- lib/chef-cli/command/exec.rb | 2 +- lib/chef-cli/helpers.rb | 47 +++++++--- 15 files changed, 502 insertions(+), 31 deletions(-) create mode 100644 .expeditor/build.habitat.yml create mode 100755 .expeditor/buildkite/artifact.habitat.test.ps1 create mode 100755 .expeditor/buildkite/artifact.habitat.test.sh create mode 100644 .expeditor/habitat-test.pipeline.yml create mode 100644 habitat/plan.ps1 create mode 100644 habitat/plan.sh create mode 100644 habitat/tests/test.ps1 create mode 100755 habitat/tests/test.sh diff --git a/.expeditor/build.habitat.yml b/.expeditor/build.habitat.yml new file mode 100644 index 00000000..72ea2567 --- /dev/null +++ b/.expeditor/build.habitat.yml @@ -0,0 +1,9 @@ +--- +origin: chef + +expeditor: + defaults: + buildkite: + retry: + automatic: + limit: 1 diff --git a/.expeditor/buildkite/artifact.habitat.test.ps1 b/.expeditor/buildkite/artifact.habitat.test.ps1 new file mode 100755 index 00000000..adeb59f6 --- /dev/null +++ b/.expeditor/buildkite/artifact.habitat.test.ps1 @@ -0,0 +1,86 @@ +#!/usr/bin/env powershell + +#Requires -Version 5 +# https://stackoverflow.com/questions/9948517 +# TODO: Set-StrictMode -Version Latest +$PSDefaultParameterValues['*:ErrorAction']='Stop' +$ErrorActionPreference = 'Stop' +$env:HAB_BLDR_CHANNEL = "LTS-2024" +$env:HAB_ORIGIN = 'ci' +$env:CHEF_LICENSE = 'accept-no-persist' +$env:HAB_LICENSE = 'accept-no-persist' +$Plan = 'chef-cli' + +Write-Host "--- system details" +$Properties = 'Caption', 'CSName', 'Version', 'BuildType', 'OSArchitecture' +Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize + +Write-Host "--- Installing the version of Habitat required" + +function Stop-HabProcess { + $habProcess = Get-Process hab -ErrorAction SilentlyContinue + if ($habProcess) { + Write-Host "Stopping hab process..." + Stop-Process -Name hab -Force + } +} + +# Installing Habitat +function Install-Habitat { + Write-Host "Downloading and installing Habitat..." + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1')) +} + +try { + hab --version +} +catch { + Set-ExecutionPolicy Bypass -Scope Process -Force + + Stop-HabProcess + + # Remove the existing hab.exe if it exists and if you have permissions + $habPath = "C:\ProgramData\Habitat\hab.exe" + if (Test-Path $habPath) { + Write-Host "Attempting to remove existing hab.exe..." + Remove-Item $habPath -Force -ErrorAction SilentlyContinue + if (Test-Path $habPath) { + Write-Host "Failed to remove hab.exe, re-running script with elevated permissions." + Start-Process powershell -Verb runAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" + exit + } + } + + Install-Habitat +} +finally { + Write-Host ":habicat: I think I have the version I need to build." +} + + +Write-Host "--- Generating fake origin key" +hab origin key generate $env:HAB_ORIGIN + +Write-Host "--- Building $Plan" +$project_root = "$(git rev-parse --show-toplevel)" +Set-Location $project_root + +$env:DO_CHECK=$true; hab pkg build . + +. $project_root/results/last_build.ps1 + +Write-Host "--- Installing $pkg_ident/$pkg_artifact" +hab pkg install -b $project_root/results/$pkg_artifact + +Write-Host "+++ Testing $Plan" + +Push-Location $project_root + +try { + Write-Host "Running unit tests..." + /habitat/tests/test.ps1 $pkg_ident +} +finally { + # Ensure we always return to the original directory + Pop-Location +} \ No newline at end of file diff --git a/.expeditor/buildkite/artifact.habitat.test.sh b/.expeditor/buildkite/artifact.habitat.test.sh new file mode 100755 index 00000000..6ded1be3 --- /dev/null +++ b/.expeditor/buildkite/artifact.habitat.test.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +set -eo pipefail + +export HAB_ORIGIN='ci' +export PLAN='chef-cli' +export CHEF_LICENSE="accept-no-persist" +export HAB_LICENSE="accept-no-persist" +export HAB_BLDR_CHANNEL="LTS-2024" + +echo "--- checking if git is installed" +if ! command -v git &> /dev/null; then + echo "Git is not installed. Installing Git..." + sudo yum install -y git +else + echo "Git is already installed." + git --version +fi + +echo "--- add an exception for this directory since detected dubious ownership in repository at /workdir" +git config --global --add safe.directory /workdir + +echo "--- git status for this workdir" +git status + +echo "--- ruby version" +ruby -v + +export project_root="$(git rev-parse --show-toplevel)" +echo "The value for project_root is: $project_root" + +export HAB_NONINTERACTIVE=true +export HAB_NOCOLORING=true +export HAB_STUDIO_SECRET_HAB_NONINTERACTIVE=true + +echo "--- system details" +uname -a + +echo "--- Installing Habitat" +id -a +curl https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.sh | bash + +echo "--- :key: Generating fake origin key" +hab origin key generate "$HAB_ORIGIN" + + +echo "--- Building $PLAN" +cd "$project_root" +DO_CHECK=true hab pkg build . + +echo "--- Sourcing 'results/last_build.sh'" +if [ -f ./results/last_build.env ]; then + cat ./results/last_build.env + . ./results/last_build.env + export pkg_artifact +fi + +echo "+++ Installing ${pkg_ident:?is undefined}" +echo "++++" +echo $project_root +echo "+++" +hab pkg install -b "${project_root:?is undefined}/results/${pkg_artifact:?is undefined}" + +echo "+++ Testing $PLAN" + +PATH="$(hab pkg path ci/chef-cli)/bin:$PATH" +export PATH +echo "PATH is $PATH" + +echo "--- :mag_right: Testing $PLAN" +${project_root}/habitat/tests/test.sh "$pkg_ident" || error 'failures during test of executables' \ No newline at end of file diff --git a/.expeditor/config.yml b/.expeditor/config.yml index b51f2c1b..29da699e 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -9,6 +9,9 @@ slack: rubygems: - chef-cli +release_branches: + - workstation-LTS: + version_constraint: 5.* github: # This deletes the GitHub PR branch after successfully merged into the release branch delete_branch_on_merge: true @@ -28,6 +31,19 @@ pipelines: - verify: description: Pull Request validation tests public: true + - habitat/build: + env: + - HAB_NONINTERACTIVE: "true" + - HAB_NOCOLORING: "true" + - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" + - habitat/test: + description: Execute tests against the habitat artifact + definition: .expeditor/habitat-test.pipeline.yml + env: + - HAB_NONINTERACTIVE: "true" + - HAB_NOCOLORING: "true" + - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" + trigger: pull_request subscriptions: # These actions are taken, in order they are specified, anytime a Pull Request is merged. @@ -45,7 +61,24 @@ subscriptions: - "Expeditor: Skip All" - built_in:build_gem: only_if: built_in:bump_version + - trigger_pipeline:habitat/test: + only_if: built_in:bump_version + ignore_labels: + - "Expeditor: Skip Habitat" + - "Expeditor: Skip All" + - trigger_pipeline:habitat/build: + only_if: built_in:bump_version + ignore_labels: + - "Expeditor: Skip Habitat" + - "Expeditor: Skip All" + - workload: project_promoted:{{agent_id}}:* actions: - built_in:rollover_changelog - - built_in:publish_rubygems \ No newline at end of file + - built_in:publish_rubygems + # the habitat chain + - workload: buildkite_hab_build_group_published:{{agent_id}}:* + actions: + # when all of the hab package publish to the unstable channel, test and promote them + - trigger_pipeline:habitat/test + \ No newline at end of file diff --git a/.expeditor/habitat-test.pipeline.yml b/.expeditor/habitat-test.pipeline.yml new file mode 100644 index 00000000..98d8b936 --- /dev/null +++ b/.expeditor/habitat-test.pipeline.yml @@ -0,0 +1,35 @@ +--- +expeditor: + defaults: + buildkite: + timeout_in_minutes: 30 + retry: + automatic: + limit: 1 + +steps: + + - label: ":linux: Validate Habitat Builds of Chef-cli" + commands: + - habitat/tests/test.sh + expeditor: + executor: + docker: + image: ruby:3.1 + privileged: true + + - label: ":windows: Validate Habitat Builds of Test Kitchen" + commands: + - .expeditor/buildkite/artifact.habitat.test.ps1 + expeditor: + executor: + docker: + host_os: windows + shell: ["powershell", "-Command"] + image: rubydistros/windows-2019:3.1 + user: 'NT AUTHORITY\SYSTEM' + environment: + - FORCE_FFI_YAJL=ext + - EXPIRE_CACHE=true + - CHEF_LICENSE=accept-no-persist + - CHEF_LICENSE_SERVER=http://hosted-license-service-lb-8000-606952349.us-west-2.elb.amazonaws.com:8000/ diff --git a/Gemfile b/Gemfile index 7461ea33..90f9a343 100644 --- a/Gemfile +++ b/Gemfile @@ -3,10 +3,10 @@ source "https://rubygems.org" gemspec gem "logger", "< 1.6" # 1.6 causes errors with mixlib-log < 3.1.1 - +gem "chefspec" group :test do gem "rake" - gem "rspec", "~> 3.8" + gem "rspec", "=3.12.0" gem "rspec-expectations", "~> 3.8" gem "rspec-mocks", "~> 3.8" gem "cookstyle" @@ -19,10 +19,13 @@ group :development do gem "pry" gem "pry-byebug" gem "rb-readline" + gem "appbundler" end group :profile do - gem "stackprof" - gem "stackprof-webnav" - gem "memory_profiler" -end + unless RUBY_PLATFORM.match?(/mswin|mingw|windows/) + gem "stackprof" + gem "stackprof-webnav" + gem "memory_profiler" + end +end \ No newline at end of file diff --git a/Rakefile b/Rakefile index 3b92ac1a..f25cfd7f 100644 --- a/Rakefile +++ b/Rakefile @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# +require "bundler/gem_tasks" namespace :style do begin @@ -52,3 +54,4 @@ namespace :style do puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV["CI"] end end + diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 35a36fe6..968898d2 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,5 +50,4 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" - gem.add_dependency "chef-licensing", "~> 1.0" end diff --git a/habitat/plan.ps1 b/habitat/plan.ps1 new file mode 100644 index 00000000..ae1e9488 --- /dev/null +++ b/habitat/plan.ps1 @@ -0,0 +1,92 @@ +$ErrorActionPreference = "Stop" +$PSDefaultParameterValues['*:ErrorAction']='Stop' + +$pkg_name="chef-cli" +$pkg_origin="chef" +$pkg_version=$(Get-Content "$PLAN_CONTEXT/../VERSION") +$pkg_maintainer="The Chef Maintainers " + +$pkg_deps=@( + "chef/ruby31-plus-devkit" + "core/git" +) +$pkg_bin_dirs=@("bin" + "vendor/bin") +$project_root= (Resolve-Path "$PLAN_CONTEXT/../").Path + +function pkg_version { + Get-Content "$SRC_PATH/VERSION" +} + +function Invoke-Before { + Set-PkgVersion +} +function Invoke-SetupEnvironment { + Push-RuntimeEnv -IsPath GEM_PATH "$pkg_prefix/vendor" + + Set-RuntimeEnv APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH + Set-RuntimeEnv FORCE_FFI_YAJL "ext" + Set-RuntimeEnv LANG "en_US.UTF-8" + Set-RuntimeEnv LC_CTYPE "en_US.UTF-8" +} + +function Invoke-Build { + try { + $env:Path += ";c:\\Program Files\\Git\\bin" + Push-Location $project_root + $env:GEM_HOME = "$HAB_CACHE_SRC_PATH/$pkg_dirname/vendor" + + Write-BuildLine " ** Configuring bundler for this build environment" + bundle config --local without integration deploy maintenance + bundle config --local jobs 4 + bundle config --local retry 5 + bundle config --local silence_root_warning 1 + Write-BuildLine " ** Using bundler to retrieve the Ruby dependencies" + bundle install + + gem build chef-cli.gemspec + Write-BuildLine " ** Using gem to install" + gem install chef-cli-*.gem --no-document + + + If ($lastexitcode -ne 0) { Exit $lastexitcode } + } finally { + Pop-Location + } +} + +function Invoke-Install { + Write-BuildLine "** Copy built & cached gems to install directory" + Copy-Item -Path "$HAB_CACHE_SRC_PATH/$pkg_dirname/*" -Destination $pkg_prefix -Recurse -Force -Exclude @("gem_make.out", "mkmf.log", "Makefile", + "*/latest", "latest", + "*/JSON-Schema-Test-Suite", "JSON-Schema-Test-Suite") + + try { + Push-Location $pkg_prefix + bundle config --local gemfile $project_root/Gemfile + Write-BuildLine "** generating binstubs for chef-cli with precise version pins" + Write-BuildLine "** generating binstubs for chef-cli with precise version pins $project_root $pkg_prefix/bin " + Invoke-Expression -Command "appbundler.bat $project_root $pkg_prefix/bin chef-cli" + If ($lastexitcode -ne 0) { Exit $lastexitcode } + Write-BuildLine " ** Running the chef-cli project's 'rake install' to install the path-based gems so they look like any other installed gem." + + If ($lastexitcode -ne 0) { Exit $lastexitcode } + } finally { + Pop-Location + } +} + +function Invoke-After { + # We don't need the cache of downloaded .gem files ... + Remove-Item $pkg_prefix/vendor/cache -Recurse -Force + # We don't need the gem docs. + Remove-Item $pkg_prefix/vendor/doc -Recurse -Force + # We don't need to ship the test suites for every gem dependency, + # only inspec's for package verification. + Get-ChildItem $pkg_prefix/vendor/gems -Filter "spec" -Directory -Recurse -Depth 1 ` + | Where-Object -FilterScript { $_.FullName -notlike "*chef-cli*" } ` + | Remove-Item -Recurse -Force + # Remove the byproducts of compiling gems with extensions + Get-ChildItem $pkg_prefix/vendor/gems -Include @("gem_make.out", "mkmf.log", "Makefile") -File -Recurse ` + | Remove-Item -Force +} \ No newline at end of file diff --git a/habitat/plan.sh b/habitat/plan.sh new file mode 100644 index 00000000..5b4953de --- /dev/null +++ b/habitat/plan.sh @@ -0,0 +1,76 @@ +export HAB_BLDR_CHANNEL="LTS-2024" +pkg_name=chef-cli +pkg_origin=chef +ruby_pkg="core/ruby3_1" +pkg_deps=(${ruby_pkg} core/coreutils) +pkg_build_deps=( + core/make + core/sed + core/gcc + core/libarchive + ) +pkg_bin_dirs=(bin) +do_setup_environment() { + build_line 'Setting GEM_HOME="$pkg_prefix/vendor"' + export GEM_HOME="$pkg_prefix/vendor" + + build_line "Setting GEM_PATH=$GEM_HOME" + export GEM_PATH="$GEM_HOME" +} + +pkg_version() { + cat "$SRC_PATH/VERSION" +} +do_before() { + update_pkg_version +} +do_unpack() { + mkdir -pv "$HAB_CACHE_SRC_PATH/$pkg_dirname" + cp -RT "$PLAN_CONTEXT"/.. "$HAB_CACHE_SRC_PATH/$pkg_dirname/" +} +do_build() { + + export GEM_HOME="$pkg_prefix/vendor" + + build_line "Setting GEM_PATH=$GEM_HOME" + export GEM_PATH="$GEM_HOME" + bundle config --local without integration deploy maintenance + bundle config --local jobs 4 + bundle config --local retry 5 + bundle config --local silence_root_warning 1 + bundle install + gem build chef-cli.gemspec +} +do_install() { + export GEM_HOME="$pkg_prefix/vendor" + + build_line "Setting GEM_PATH=$GEM_HOME" + export GEM_PATH="$GEM_HOME" + gem install chef-cli-*.gem --no-document + set_runtime_env "GEM_PATH" "${pkg_prefix}/vendor" + wrap_ruby_bin +} +wrap_ruby_bin() { + local bin="$pkg_prefix/bin/$pkg_name" + local real_bin="$GEM_HOME/gems/chef-cli-${pkg_version}/bin/chef-cli" + build_line "Adding wrapper $bin to $real_bin" + cat < "$bin" +#!$(pkg_path_for core/bash)/bin/bash +set -e + +# Set binary path that allows InSpec to use non-Hab pkg binaries +export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:\$PATH" + +# Set Ruby paths defined from 'do_setup_environment()' + export GEM_HOME="$pkg_prefix/vendor" + export GEM_PATH="$GEM_PATH" + +exec $(pkg_path_for ${ruby_pkg})/bin/ruby $real_bin \$@ +EOF + chmod -v 755 "$bin" +} + + +do_strip() { + return 0 +} \ No newline at end of file diff --git a/habitat/tests/test.ps1 b/habitat/tests/test.ps1 new file mode 100644 index 00000000..a712fea5 --- /dev/null +++ b/habitat/tests/test.ps1 @@ -0,0 +1,21 @@ +param ( + [Parameter()] + [string]$PackageIdentifier = $(throw "Usage: test.ps1 [test_pkg_ident] e.g. test.ps1 ci/user-windows/1.0.0/20190812103929") +) + + +Write-Host "--- :fire: Smokish test" +# Pester the Package +$version=hab pkg exec "${pkg_ident}" chef-cli -v +$actual_version=[Regex]::Match($version,"([0-9]+.[0-9]+.[0-9]+)").Value +$package_version=$PackageIdentifier.split("/",4)[2] + +Write-Host "package_version $package_version actual version $actual_version" +if ($package_version -eq $actual_version) +{ + Write "Chef-cli working fine" +} +else { + Write-Error "chef-cli version not met expected $package_version actual version $actual_version " + throw "Chef cli windows pipeline not working for hab pkg" +} \ No newline at end of file diff --git a/habitat/tests/test.sh b/habitat/tests/test.sh new file mode 100755 index 00000000..72e288a4 --- /dev/null +++ b/habitat/tests/test.sh @@ -0,0 +1,26 @@ + +set -euo pipefail + + +project_root="$(git rev-parse --show-toplevel)" +pkg_ident="$1" +# print error message followed by usage and exit +error () { + local message="$1" + + echo -e "\nERROR: ${message}\n" >&2 + + exit 1 +} + +[[ -n "$pkg_ident" ]] || error 'no hab package identity provided' + +package_version=$(awk -F / '{print $3}' <<<"$pkg_ident") + +cd "${project_root}" + +echo "--- :mag_right: Testing ${pkg_ident} executables" +actual_version=$(hab pkg exec "${pkg_ident}" chef-cli -v | sed -E 's/.*version: ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') +[[ "$package_version" = "$actual_version" ]] || error "chef-cli version is not the expected version. Expected '$package_version', got '$actual_version'" + + diff --git a/lib/chef-cli/command/env.rb b/lib/chef-cli/command/env.rb index d1aed4b2..c44e4c4e 100644 --- a/lib/chef-cli/command/env.rb +++ b/lib/chef-cli/command/env.rb @@ -73,19 +73,19 @@ def ruby_info def gem_environment h = {} - h["GEM ROOT"] = omnibus_env["GEM_ROOT"] - h["GEM HOME"] = omnibus_env["GEM_HOME"] - h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR) - rescue OmnibusInstallNotFound + # h["GEM ROOT"] = omnibus_env["GEM_ROOT"] + # h["GEM HOME"] = omnibus_env["GEM_HOME"] + # h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR) + # rescue OmnibusInstallNotFound h["GEM_ROOT"] = ENV["GEM_ROOT"] if ENV.key?("GEM_ROOT") h["GEM_HOME"] = ENV["GEM_HOME"] if ENV.key?("GEM_HOME") h["GEM PATHS"] = ENV["GEM_PATH"].split(File::PATH_SEPARATOR) if ENV.key?("GEM_PATH") && !ENV.key?("GEM_PATH").nil? - ensure - h + # ensure + # h end def paths - omnibus_env["PATH"].split(File::PATH_SEPARATOR) + habitat_env["PATH"].split(File::PATH_SEPARATOR) rescue OmnibusInstallNotFound ENV["PATH"].split(File::PATH_SEPARATOR) end diff --git a/lib/chef-cli/command/exec.rb b/lib/chef-cli/command/exec.rb index f1e19bde..9b86bbea 100644 --- a/lib/chef-cli/command/exec.rb +++ b/lib/chef-cli/command/exec.rb @@ -30,7 +30,7 @@ class Exec < ChefCLI::Command::Base def run(params) # Set ENV directly on the "parent" process (us) before running #exec to # ensure the custom PATH is honored when finding the command to exec - omnibus_env.each { |var, value| ENV[var] = value } + habitat_env.each { |var, value| ENV[var] = value } exec(*params) raise "Exec failed without an exception, your ruby is buggy" # should never get here end diff --git a/lib/chef-cli/helpers.rb b/lib/chef-cli/helpers.rb index 6c72237e..e658bf54 100644 --- a/lib/chef-cli/helpers.rb +++ b/lib/chef-cli/helpers.rb @@ -111,22 +111,39 @@ def git_windows_bin_dir end # - # environment vars for omnibus + # environment vars for habitat # - def omnibus_env - @omnibus_env ||= - begin - user_bin_dir = File.expand_path(File.join(Gem.user_dir, "bin")) - path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ] - path << git_bin_dir if Dir.exist?(git_bin_dir) - path << git_windows_bin_dir if Dir.exist?(git_windows_bin_dir) - { - "PATH" => path.flatten.uniq.join(File::PATH_SEPARATOR), - "GEM_ROOT" => Gem.default_dir, - "GEM_HOME" => Gem.user_dir, - "GEM_PATH" => Gem.path.join(File::PATH_SEPARATOR), - } - end + def habitat_env + @habitat_env ||= + begin + # Define the necessary paths for the Habitat environment + # Custom GEM_HOME within Habitat + pkg_prefix = get_pkg_prefix + vendor_dir = File.join(pkg_prefix, "vendor") + path = [ + File.join(pkg_prefix, "bin"), + ENV["PATH"].split(File::PATH_SEPARATOR) # Preserve existing PATH + ].flatten.uniq + + { + "PATH" => path.join(File::PATH_SEPARATOR), + "GEM_ROOT" => Gem.default_dir, # Default directory for gems + "GEM_HOME" => vendor_dir, # GEM_HOME pointing to the vendor directory + "GEM_PATH" => vendor_dir, # GEM_PATH also pointing to the vendor directory + } + end + end + + def get_pkg_prefix + pkg_origin = "chef" + pkg_name = "#{pkg_origin}/chef-cli" # Your origin and package name + path = `hab pkg path #{pkg_name}`.strip + + if $?.success? && !path.empty? + path + else + raise "Failed to get pkg_prefix for #{pkg_name}: #{path}" + end end def omnibus_expand_path(*paths) From c95378ddc1caf08b09f01d1aea5bfb561da1c5d5 Mon Sep 17 00:00:00 2001 From: ns Date: Fri, 6 Dec 2024 15:38:46 +0530 Subject: [PATCH 17/48] Testing pipleine (#242) * Testing pipleine Signed-off-by: nitin sanghi * Testing pipleine Signed-off-by: nitin sanghi * Testing pipleine Signed-off-by: nitin sanghi * Path change for test file Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * adding locales Signed-off-by: nitin sanghi * ignoring warn change sed regex Signed-off-by: nitin sanghi * ignoring warn change sed regex Signed-off-by: nitin sanghi * ignoring warn change sed regex Signed-off-by: nitin sanghi * ignoring warn change sed regex Signed-off-by: nitin sanghi * change version command Signed-off-by: nitin sanghi * change version command Signed-off-by: nitin sanghi * change version command Signed-off-by: nitin sanghi * change version command Signed-off-by: nitin sanghi * change version command Signed-off-by: nitin sanghi * change version command Signed-off-by: nitin sanghi * change version command regex Signed-off-by: nitin sanghi --------- Signed-off-by: nitin sanghi --- .expeditor/buildkite/artifact.habitat.test.ps1 | 2 +- .expeditor/buildkite/artifact.habitat.test.sh | 1 - .expeditor/config.yml | 2 ++ .expeditor/habitat-test.pipeline.yml | 3 ++- habitat/tests/test.sh | 14 +++++++++----- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.expeditor/buildkite/artifact.habitat.test.ps1 b/.expeditor/buildkite/artifact.habitat.test.ps1 index adeb59f6..209c4c83 100755 --- a/.expeditor/buildkite/artifact.habitat.test.ps1 +++ b/.expeditor/buildkite/artifact.habitat.test.ps1 @@ -78,7 +78,7 @@ Push-Location $project_root try { Write-Host "Running unit tests..." - /habitat/tests/test.ps1 $pkg_ident + habitat/tests/test.ps1 $pkg_ident } finally { # Ensure we always return to the original directory diff --git a/.expeditor/buildkite/artifact.habitat.test.sh b/.expeditor/buildkite/artifact.habitat.test.sh index 6ded1be3..fb195d1d 100755 --- a/.expeditor/buildkite/artifact.habitat.test.sh +++ b/.expeditor/buildkite/artifact.habitat.test.sh @@ -54,7 +54,6 @@ if [ -f ./results/last_build.env ]; then . ./results/last_build.env export pkg_artifact fi - echo "+++ Installing ${pkg_ident:?is undefined}" echo "++++" echo $project_root diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 29da699e..bc11f923 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -12,6 +12,8 @@ rubygems: release_branches: - workstation-LTS: version_constraint: 5.* + - main: + version_constraint: 5.* github: # This deletes the GitHub PR branch after successfully merged into the release branch delete_branch_on_merge: true diff --git a/.expeditor/habitat-test.pipeline.yml b/.expeditor/habitat-test.pipeline.yml index 98d8b936..a8636693 100644 --- a/.expeditor/habitat-test.pipeline.yml +++ b/.expeditor/habitat-test.pipeline.yml @@ -7,11 +7,12 @@ expeditor: automatic: limit: 1 + steps: - label: ":linux: Validate Habitat Builds of Chef-cli" commands: - - habitat/tests/test.sh + - .expeditor/buildkite/artifact.habitat.test.sh expeditor: executor: docker: diff --git a/habitat/tests/test.sh b/habitat/tests/test.sh index 72e288a4..d5d01cdc 100755 --- a/habitat/tests/test.sh +++ b/habitat/tests/test.sh @@ -18,9 +18,13 @@ error () { package_version=$(awk -F / '{print $3}' <<<"$pkg_ident") cd "${project_root}" - -echo "--- :mag_right: Testing ${pkg_ident} executables" -actual_version=$(hab pkg exec "${pkg_ident}" chef-cli -v | sed -E 's/.*version: ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') -[[ "$package_version" = "$actual_version" ]] || error "chef-cli version is not the expected version. Expected '$package_version', got '$actual_version'" - +echo "Testing ${pkg_ident} executables" +version=$(hab pkg exec "${pkg_ident}" chef-cli -v) +echo $version +actual_version=$(echo "$version" | sed -E 's/.*version: ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') +echo $actual_version + +if [[ "$actual_version" != *"$package_version"* ]]; then + error "chef-cli version is not the expected version. Expected '$package_version', got '$actual_version'" +fi From b4c78edfbabe6f176e213450515646f553e5b7a3 Mon Sep 17 00:00:00 2001 From: ns Date: Mon, 16 Dec 2024 19:31:58 +0530 Subject: [PATCH 18/48] Added dev channel for hab pkg (#243) Signed-off-by: nitin sanghi --- .expeditor/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index bc11f923..ce9292d5 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -28,7 +28,8 @@ github: changelog: rollup_header: Changes not yet released to rubygems.org - +artifact_channels: + - dev pipelines: - verify: description: Pull Request validation tests From 6473a1eb5ebdcf40136d77336d77f6ec2e17f8dc Mon Sep 17 00:00:00 2001 From: ns Date: Tue, 17 Dec 2024 15:40:00 +0530 Subject: [PATCH 19/48] Added action for channel alternative (#244) Signed-off-by: nitin sanghi --- .expeditor/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index ce9292d5..d7a2e2e6 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -84,4 +84,5 @@ subscriptions: actions: # when all of the hab package publish to the unstable channel, test and promote them - trigger_pipeline:habitat/test + - built_in:promote_habitat_packages \ No newline at end of file From c1a46e2134e284342e68f0933c1b38e42c3b2de9 Mon Sep 17 00:00:00 2001 From: ns Date: Tue, 17 Dec 2024 16:46:54 +0530 Subject: [PATCH 20/48] Version change for lts (#245) * Added action for channel alternative Signed-off-by: nitin sanghi * Changing version 1.0.0 for hab pkg Signed-off-by: nitin sanghi * Changing version 1.0.0 for hab pkg Signed-off-by: nitin sanghi --------- Signed-off-by: nitin sanghi --- .expeditor/config.yml | 4 ++-- VERSION | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index d7a2e2e6..b909a5b1 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -11,7 +11,7 @@ rubygems: release_branches: - workstation-LTS: - version_constraint: 5.* + version_constraint: 1.* - main: version_constraint: 5.* github: @@ -83,6 +83,6 @@ subscriptions: - workload: buildkite_hab_build_group_published:{{agent_id}}:* actions: # when all of the hab package publish to the unstable channel, test and promote them - - trigger_pipeline:habitat/test - built_in:promote_habitat_packages + - trigger_pipeline:habitat/test \ No newline at end of file diff --git a/VERSION b/VERSION index 1c3c4476..afaf360d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.6.15 \ No newline at end of file +1.0.0 \ No newline at end of file From c40fb70b53f1da067d8f71d95edbaab20c98133c Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Tue, 17 Dec 2024 09:49:06 -0500 Subject: [PATCH 21/48] adding backup branch for workstation-lts Signed-off-by: Sean Simmons From 5d45f9a5dab9918ecf27928b0d1f285c85bce1de Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Tue, 17 Dec 2024 10:03:10 -0500 Subject: [PATCH 22/48] adding branch Signed-off-by: Sean Simmons From dcf7aa4458aa2c979787232a6043c1ab67881888 Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Tue, 17 Dec 2024 10:05:17 -0500 Subject: [PATCH 23/48] adding expeditor agent Signed-off-by: Sean Simmons --- .expeditor/config.yml | 2 +- VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 4dd101aa..fa37fdab 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -5,7 +5,7 @@ slack: notify_channel: chef-ws-notify -# This publish is triggered by the `built_in:publish_rubygems` artifact_action. +# This publish is triggered by the `built_in:publish_rubygems` artifact_action! rubygems: - chef-cli diff --git a/VERSION b/VERSION index 240bf8ea..afaf360d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.6.16 \ No newline at end of file +1.0.0 \ No newline at end of file From e7d7f95ab03f58252ad3f987a378407290930269 Mon Sep 17 00:00:00 2001 From: Sean Simmons Date: Tue, 17 Dec 2024 10:06:19 -0500 Subject: [PATCH 24/48] adding expeditor agent Signed-off-by: Sean Simmons --- .expeditor/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index fa37fdab..4dd101aa 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -5,7 +5,7 @@ slack: notify_channel: chef-ws-notify -# This publish is triggered by the `built_in:publish_rubygems` artifact_action! +# This publish is triggered by the `built_in:publish_rubygems` artifact_action. rubygems: - chef-cli From 6f80381a20dbdb6623159f9e975b5e047bdded32 Mon Sep 17 00:00:00 2001 From: nitin sanghi Date: Tue, 17 Dec 2024 21:41:12 +0530 Subject: [PATCH 25/48] Change version and constraint to same as main Signed-off-by: nitin sanghi --- .expeditor/config.yml | 2 +- VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index b909a5b1..00b056bc 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -11,7 +11,7 @@ rubygems: release_branches: - workstation-LTS: - version_constraint: 1.* + version_constraint: 5.* - main: version_constraint: 5.* github: diff --git a/VERSION b/VERSION index afaf360d..240bf8ea 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 \ No newline at end of file +5.6.16 \ No newline at end of file From 1175aa2a1cbd816d7d177e082e1790f4514f095b Mon Sep 17 00:00:00 2001 From: nitin sanghi Date: Wed, 18 Dec 2024 18:50:46 +0530 Subject: [PATCH 26/48] Added one more channel and remove test from promote pipeline Signed-off-by: nitin sanghi --- .expeditor/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 00b056bc..e2e6a474 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -30,6 +30,7 @@ changelog: rollup_header: Changes not yet released to rubygems.org artifact_channels: - dev + - stable pipelines: - verify: description: Pull Request validation tests @@ -84,5 +85,4 @@ subscriptions: actions: # when all of the hab package publish to the unstable channel, test and promote them - built_in:promote_habitat_packages - - trigger_pipeline:habitat/test \ No newline at end of file From 628c23d2fc38239f7c7bcf4e38f4a3e1ac02621c Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Fri, 20 Dec 2024 12:23:10 +0530 Subject: [PATCH 27/48] added the channel variable Signed-off-by: nikhil2611 --- habitat/plan.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/habitat/plan.ps1 b/habitat/plan.ps1 index ae1e9488..34c671fa 100644 --- a/habitat/plan.ps1 +++ b/habitat/plan.ps1 @@ -1,6 +1,7 @@ $ErrorActionPreference = "Stop" $PSDefaultParameterValues['*:ErrorAction']='Stop' +$env:HAB_BLDR_CHANNEL = "LTS-2024" $pkg_name="chef-cli" $pkg_origin="chef" $pkg_version=$(Get-Content "$PLAN_CONTEXT/../VERSION") From d80d0dcd3aa064dfd917bd6ec8f6c9f6a2b46e31 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Mon, 6 Jan 2025 13:03:20 +0530 Subject: [PATCH 28/48] removed the manually created pipelines and added the channels Signed-off-by: nikhil2611 --- .expeditor/config.yml | 65 ++++++++++++++++++++--------------------- VERSION | 2 +- lib/chef-cli/version.rb | 2 +- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index e2e6a474..1f1ec870 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -11,7 +11,7 @@ rubygems: release_branches: - workstation-LTS: - version_constraint: 5.* + version_constraint: 0.* - main: version_constraint: 5.* github: @@ -28,26 +28,29 @@ github: changelog: rollup_header: Changes not yet released to rubygems.org + artifact_channels: - dev - - stable + - workstation-build + - LTS-2024 + pipelines: - verify: description: Pull Request validation tests public: true - - habitat/build: - env: - - HAB_NONINTERACTIVE: "true" - - HAB_NOCOLORING: "true" - - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" - - habitat/test: - description: Execute tests against the habitat artifact - definition: .expeditor/habitat-test.pipeline.yml - env: - - HAB_NONINTERACTIVE: "true" - - HAB_NOCOLORING: "true" - - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" - trigger: pull_request + # - habitat/build: + # env: + # - HAB_NONINTERACTIVE: "true" + # - HAB_NOCOLORING: "true" + # - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" + # - habitat/test: + # description: Execute tests against the habitat artifact + # definition: .expeditor/habitat-test.pipeline.yml + # env: + # - HAB_NONINTERACTIVE: "true" + # - HAB_NOCOLORING: "true" + # - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" + # trigger: pull_request subscriptions: # These actions are taken, in order they are specified, anytime a Pull Request is merged. @@ -65,24 +68,20 @@ subscriptions: - "Expeditor: Skip All" - built_in:build_gem: only_if: built_in:bump_version - - trigger_pipeline:habitat/test: - only_if: built_in:bump_version - ignore_labels: - - "Expeditor: Skip Habitat" - - "Expeditor: Skip All" - - trigger_pipeline:habitat/build: - only_if: built_in:bump_version - ignore_labels: - - "Expeditor: Skip Habitat" - - "Expeditor: Skip All" + # - trigger_pipeline:habitat/test: + # only_if: built_in:bump_version + # ignore_labels: + # - "Expeditor: Skip Habitat" + # - "Expeditor: Skip All" + # - trigger_pipeline:habitat/build: + # only_if: built_in:bump_version + # ignore_labels: + # - "Expeditor: Skip Habitat" + # - "Expeditor: Skip All" - - workload: project_promoted:{{agent_id}}:* - actions: - - built_in:rollover_changelog - - built_in:publish_rubygems # the habitat chain - - workload: buildkite_hab_build_group_published:{{agent_id}}:* - actions: - # when all of the hab package publish to the unstable channel, test and promote them - - built_in:promote_habitat_packages + # - workload: buildkite_hab_build_group_published:{{agent_id}}:* + # actions: + # # when all of the hab package publish to the unstable channel, test and promote them + # - built_in:promote_habitat_packages \ No newline at end of file diff --git a/VERSION b/VERSION index 240bf8ea..6c6aa7cb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.6.16 \ No newline at end of file +0.1.0 \ No newline at end of file diff --git a/lib/chef-cli/version.rb b/lib/chef-cli/version.rb index b3cff0b9..6596023c 100644 --- a/lib/chef-cli/version.rb +++ b/lib/chef-cli/version.rb @@ -16,5 +16,5 @@ # module ChefCLI - VERSION = "5.6.16".freeze + VERSION = "0.1.0".freeze end From 408d352a926035e61c377ef6f3ad05cf64927c4c Mon Sep 17 00:00:00 2001 From: ns Date: Mon, 6 Jan 2025 17:15:49 +0530 Subject: [PATCH 29/48] hab pkg promote change (#254) Signed-off-by: nitin sanghi --- .expeditor/config.yml | 25 +++++++++++-------------- .gitignore | 3 +++ VERSION | 2 +- lib/chef-cli/version.rb | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index e2e6a474..91aec7d7 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -11,7 +11,7 @@ rubygems: release_branches: - workstation-LTS: - version_constraint: 5.* + version_constraint: 0.* - main: version_constraint: 5.* github: @@ -30,7 +30,9 @@ changelog: rollup_header: Changes not yet released to rubygems.org artifact_channels: - dev - - stable + - workstation-build + - LTS-2024 + pipelines: - verify: description: Pull Request validation tests @@ -59,12 +61,6 @@ subscriptions: - "Expeditor: Skip All" - bash:.expeditor/update_version.sh: only_if: built_in:bump_version - - built_in:update_changelog: - ignore_labels: - - "Expeditor: Skip Changelog" - - "Expeditor: Skip All" - - built_in:build_gem: - only_if: built_in:bump_version - trigger_pipeline:habitat/test: only_if: built_in:bump_version ignore_labels: @@ -76,13 +72,14 @@ subscriptions: - "Expeditor: Skip Habitat" - "Expeditor: Skip All" - - workload: project_promoted:{{agent_id}}:* - actions: - - built_in:rollover_changelog - - built_in:publish_rubygems - # the habitat chain - workload: buildkite_hab_build_group_published:{{agent_id}}:* actions: # when all of the hab package publish to the unstable channel, test and promote them - built_in:promote_habitat_packages - \ No newline at end of file + # Subscribe to the promotion of the dev channel to acceptance + - workload: project_promoted:{{agent_id}}:dev:* + actions: + - built_in:promote_habitat_packages + - workload: project_promoted:{{agent_id}}:workstation-build:* + actions: + - built_in:promote_habitat_packages \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1db8f690..ee9ed9f4 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ Vagrantfile my-cookbook results/ Gemfile.lock + + +.idea/ \ No newline at end of file diff --git a/VERSION b/VERSION index 240bf8ea..6c6aa7cb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.6.16 \ No newline at end of file +0.1.0 \ No newline at end of file diff --git a/lib/chef-cli/version.rb b/lib/chef-cli/version.rb index b3cff0b9..6596023c 100644 --- a/lib/chef-cli/version.rb +++ b/lib/chef-cli/version.rb @@ -16,5 +16,5 @@ # module ChefCLI - VERSION = "5.6.16".freeze + VERSION = "0.1.0".freeze end From 8784b358b2725bb18e3d46a3f66bf518999601b9 Mon Sep 17 00:00:00 2001 From: Chef Expeditor Date: Mon, 6 Jan 2025 11:46:17 +0000 Subject: [PATCH 30/48] Bump version to 0.1.0 by Chef Expeditor Obvious fix; these changes are the result of automation not creative thinking. --- CHANGELOG.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23f60d5f..55c58c24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,16 @@ - + +## [v0.1.0](https://github.com/chef/chef-cli/tree/v0.1.0) (2025-01-06) + +#### Merged Pull Requests +- Add hab promote pipeline [#254](https://github.com/chef/chef-cli/pull/254) ([sanghinitin](https://github.com/sanghinitin)) - + +### Changes not yet released to rubygems.org + +#### Merged Pull Requests +- Add hab promote pipeline [#254](https://github.com/chef/chef-cli/pull/254) ([sanghinitin](https://github.com/sanghinitin)) From 89133baafdb94ff8492ea7024513539ff084bc13 Mon Sep 17 00:00:00 2001 From: ns Date: Mon, 6 Jan 2025 17:19:59 +0530 Subject: [PATCH 31/48] empty commit (#255) Signed-off-by: nitin sanghi From 1e40f086bcd44c2cedd4725caa49af53e0778235 Mon Sep 17 00:00:00 2001 From: Chef Expeditor Date: Mon, 6 Jan 2025 11:50:26 +0000 Subject: [PATCH 32/48] Bump version to 0.1.1 by Chef Expeditor Obvious fix; these changes are the result of automation not creative thinking. --- VERSION | 2 +- lib/chef-cli/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 6c6aa7cb..6da28dde 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 \ No newline at end of file +0.1.1 \ No newline at end of file diff --git a/lib/chef-cli/version.rb b/lib/chef-cli/version.rb index 6596023c..0640a971 100644 --- a/lib/chef-cli/version.rb +++ b/lib/chef-cli/version.rb @@ -16,5 +16,5 @@ # module ChefCLI - VERSION = "0.1.0".freeze + VERSION = "0.1.1".freeze end From a1bf9a6f42bb50c3e938898711661c681db3d078 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Mon, 6 Jan 2025 17:36:29 +0530 Subject: [PATCH 33/48] adding the pipelines to get triggered automatically Signed-off-by: nikhil2611 --- .expeditor/config.yml | 61 ++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/.expeditor/config.yml b/.expeditor/config.yml index 7d16dec2..b4731ec5 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -37,19 +37,19 @@ pipelines: - verify: description: Pull Request validation tests public: true -# - habitat/build: -# env: -# - HAB_NONINTERACTIVE: "true" -# - HAB_NOCOLORING: "true" -# - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" -# - habitat/test: -# description: Execute tests against the habitat artifact -# definition: .expeditor/habitat-test.pipeline.yml -# env: -# - HAB_NONINTERACTIVE: "true" -# - HAB_NOCOLORING: "true" -# - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" -# trigger: pull_request + - habitat/build: + env: + - HAB_NONINTERACTIVE: "true" + - HAB_NOCOLORING: "true" + - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" + - habitat/test: + description: Execute tests against the habitat artifact + definition: .expeditor/habitat-test.pipeline.yml + env: + - HAB_NONINTERACTIVE: "true" + - HAB_NOCOLORING: "true" + - HAB_STUDIO_SECRET_HAB_NONINTERACTIVE: "true" + trigger: pull_request subscriptions: # These actions are taken, in order they are specified, anytime a Pull Request is merged. @@ -61,25 +61,20 @@ subscriptions: - "Expeditor: Skip All" - bash:.expeditor/update_version.sh: only_if: built_in:bump_version -# - trigger_pipeline:habitat/test: -# only_if: built_in:bump_version -# ignore_labels: -# - "Expeditor: Skip Habitat" -# - "Expeditor: Skip All" -# - trigger_pipeline:habitat/build: -# only_if: built_in:bump_version -# ignore_labels: -# - "Expeditor: Skip Habitat" -# - "Expeditor: Skip All" + - trigger_pipeline:habitat/build: + only_if: built_in:bump_version + ignore_labels: + - "Expeditor: Skip Habitat" + - "Expeditor: Skip All" -# - workload: buildkite_hab_build_group_published:{{agent_id}}:* -# actions: -# # when all of the hab package publish to the unstable channel, test and promote them -# - built_in:promote_habitat_packages + - workload: buildkite_hab_build_group_published:{{agent_id}}:* + actions: + # when all of the hab package publish to the unstable channel, test and promote them + - built_in:promote_habitat_packages # Subscribe to the promotion of the dev channel to acceptance -# - workload: project_promoted:{{agent_id}}:dev:* -# actions: -# - built_in:promote_habitat_packages -# - workload: project_promoted:{{agent_id}}:workstation-build:* -# actions: -# - built_in:promote_habitat_packages \ No newline at end of file + - workload: project_promoted:{{agent_id}}:dev:* + actions: + - built_in:promote_habitat_packages + - workload: project_promoted:{{agent_id}}:workstation-build:* + actions: + - built_in:promote_habitat_packages From afaaeca74aef2012d4b54c1cdb133477c4af154b Mon Sep 17 00:00:00 2001 From: Chef Expeditor Date: Mon, 6 Jan 2025 12:08:28 +0000 Subject: [PATCH 34/48] Bump version to 0.1.2 by Chef Expeditor Obvious fix; these changes are the result of automation not creative thinking. --- VERSION | 2 +- lib/chef-cli/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 17e51c38..8294c184 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.1 +0.1.2 \ No newline at end of file diff --git a/lib/chef-cli/version.rb b/lib/chef-cli/version.rb index 0640a971..29bc161a 100644 --- a/lib/chef-cli/version.rb +++ b/lib/chef-cli/version.rb @@ -16,5 +16,5 @@ # module ChefCLI - VERSION = "0.1.1".freeze + VERSION = "0.1.2".freeze end From a49892753a08d7687cbec86a019b2f6f08260b2d Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Mon, 6 Jan 2025 17:39:57 +0530 Subject: [PATCH 35/48] empty commit to test pipelines Signed-off-by: nikhil2611 From 87bc8ec8948a79a86418ad34376aa3d022f0ead4 Mon Sep 17 00:00:00 2001 From: Chef Expeditor Date: Mon, 6 Jan 2025 12:11:32 +0000 Subject: [PATCH 36/48] Bump version to 0.1.3 by Chef Expeditor Obvious fix; these changes are the result of automation not creative thinking. --- VERSION | 2 +- lib/chef-cli/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 8294c184..7693c96b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.2 \ No newline at end of file +0.1.3 \ No newline at end of file diff --git a/lib/chef-cli/version.rb b/lib/chef-cli/version.rb index 29bc161a..6311d505 100644 --- a/lib/chef-cli/version.rb +++ b/lib/chef-cli/version.rb @@ -16,5 +16,5 @@ # module ChefCLI - VERSION = "0.1.2".freeze + VERSION = "0.1.3".freeze end From 267c67cba2e103c0e73a30e501a25b9845ef8336 Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <35272911+nikhil2611@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:11:16 +0530 Subject: [PATCH 37/48] Chef-18535- Updating configuration for a symantec version promote and publish and other fixes (#258) * updating version to major version and few plan file fixes Signed-off-by: nikhil2611 * added HAB_BLDR_CHANNEL env as the build pipeline still using old hab version and updated config for a symantec version promote and publish and reverting back version and release branch changes Signed-off-by: nikhil2611 * fixing the quotes Signed-off-by: nikhil2611 * chefstyle fix Signed-off-by: nikhil2611 * fixing spec failure Signed-off-by: nikhil2611 * fixing typo in gemspec Signed-off-by: nikhil2611 * updated back to omnibus_env Signed-off-by: nikhil2611 --------- Signed-off-by: nikhil2611 --- .../buildkite/artifact.habitat.test.ps1 | 1 + .expeditor/buildkite/artifact.habitat.test.sh | 1 + .expeditor/config.yml | 28 ++++----- VERSION | 2 +- chef-cli.gemspec | 1 + habitat/plan.ps1 | 1 + habitat/plan.sh | 2 + lib/chef-cli/command/env.rb | 14 ++--- lib/chef-cli/command/exec.rb | 2 +- lib/chef-cli/helpers.rb | 59 ++++++++++++------- lib/chef-cli/version.rb | 2 +- 11 files changed, 69 insertions(+), 44 deletions(-) diff --git a/.expeditor/buildkite/artifact.habitat.test.ps1 b/.expeditor/buildkite/artifact.habitat.test.ps1 index 209c4c83..b3258a15 100755 --- a/.expeditor/buildkite/artifact.habitat.test.ps1 +++ b/.expeditor/buildkite/artifact.habitat.test.ps1 @@ -6,6 +6,7 @@ $PSDefaultParameterValues['*:ErrorAction']='Stop' $ErrorActionPreference = 'Stop' $env:HAB_BLDR_CHANNEL = "LTS-2024" +$env:HAB_REFRESH_CHANNEL = "LTS-2024" $env:HAB_ORIGIN = 'ci' $env:CHEF_LICENSE = 'accept-no-persist' $env:HAB_LICENSE = 'accept-no-persist' diff --git a/.expeditor/buildkite/artifact.habitat.test.sh b/.expeditor/buildkite/artifact.habitat.test.sh index fb195d1d..db8dfd14 100755 --- a/.expeditor/buildkite/artifact.habitat.test.sh +++ b/.expeditor/buildkite/artifact.habitat.test.sh @@ -7,6 +7,7 @@ export PLAN='chef-cli' export CHEF_LICENSE="accept-no-persist" export HAB_LICENSE="accept-no-persist" export HAB_BLDR_CHANNEL="LTS-2024" +export HAB_REFRESH_CHANNEL="LTS-2024" echo "--- checking if git is installed" if ! command -v git &> /dev/null; then diff --git a/.expeditor/config.yml b/.expeditor/config.yml index b4731ec5..54e41cbb 100644 --- a/.expeditor/config.yml +++ b/.expeditor/config.yml @@ -10,10 +10,9 @@ rubygems: - chef-cli release_branches: - - workstation-LTS: - version_constraint: 0.* - main: version_constraint: 5.* + github: # This deletes the GitHub PR branch after successfully merged into the release branch delete_branch_on_merge: true @@ -28,10 +27,10 @@ github: changelog: rollup_header: Changes not yet released to rubygems.org + artifact_channels: - - dev - - workstation-build - - LTS-2024 + - unstable + - chef-dke-lts2024 pipelines: - verify: @@ -61,20 +60,21 @@ subscriptions: - "Expeditor: Skip All" - bash:.expeditor/update_version.sh: only_if: built_in:bump_version + - built_in:update_changelog: + ignore_labels: + - "Expeditor: Skip Changelog" + - "Expeditor: Skip All" + - built_in:build_gem: + only_if: built_in:bump_version - trigger_pipeline:habitat/build: only_if: built_in:bump_version ignore_labels: - "Expeditor: Skip Habitat" - "Expeditor: Skip All" - - workload: buildkite_hab_build_group_published:{{agent_id}}:* - actions: - # when all of the hab package publish to the unstable channel, test and promote them - - built_in:promote_habitat_packages - # Subscribe to the promotion of the dev channel to acceptance - - workload: project_promoted:{{agent_id}}:dev:* - actions: - - built_in:promote_habitat_packages - - workload: project_promoted:{{agent_id}}:workstation-build:* + # this works for symantec version promote + - workload: project_promoted:{{agent_id}}:* actions: + - built_in:rollover_changelog - built_in:promote_habitat_packages + - built_in:publish_rubygems \ No newline at end of file diff --git a/VERSION b/VERSION index 7693c96b..240bf8ea 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.3 \ No newline at end of file +5.6.16 \ No newline at end of file diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 968898d2..edbce7f3 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,4 +50,5 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" + gem.add_dependency "chef-licensing", ">= 1.0.2" end diff --git a/habitat/plan.ps1 b/habitat/plan.ps1 index 34c671fa..78a26d83 100644 --- a/habitat/plan.ps1 +++ b/habitat/plan.ps1 @@ -2,6 +2,7 @@ $ErrorActionPreference = "Stop" $PSDefaultParameterValues['*:ErrorAction']='Stop' $env:HAB_BLDR_CHANNEL = "LTS-2024" +$env:HAB_REFRESH_CHANNEL = "LTS-2024" $pkg_name="chef-cli" $pkg_origin="chef" $pkg_version=$(Get-Content "$PLAN_CONTEXT/../VERSION") diff --git a/habitat/plan.sh b/habitat/plan.sh index 5b4953de..953f6593 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -1,4 +1,5 @@ export HAB_BLDR_CHANNEL="LTS-2024" +export HAB_REFRESH_CHANNEL="LTS-2024" pkg_name=chef-cli pkg_origin=chef ruby_pkg="core/ruby3_1" @@ -10,6 +11,7 @@ pkg_build_deps=( core/libarchive ) pkg_bin_dirs=(bin) + do_setup_environment() { build_line 'Setting GEM_HOME="$pkg_prefix/vendor"' export GEM_HOME="$pkg_prefix/vendor" diff --git a/lib/chef-cli/command/env.rb b/lib/chef-cli/command/env.rb index c44e4c4e..d1aed4b2 100644 --- a/lib/chef-cli/command/env.rb +++ b/lib/chef-cli/command/env.rb @@ -73,19 +73,19 @@ def ruby_info def gem_environment h = {} - # h["GEM ROOT"] = omnibus_env["GEM_ROOT"] - # h["GEM HOME"] = omnibus_env["GEM_HOME"] - # h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR) - # rescue OmnibusInstallNotFound + h["GEM ROOT"] = omnibus_env["GEM_ROOT"] + h["GEM HOME"] = omnibus_env["GEM_HOME"] + h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR) + rescue OmnibusInstallNotFound h["GEM_ROOT"] = ENV["GEM_ROOT"] if ENV.key?("GEM_ROOT") h["GEM_HOME"] = ENV["GEM_HOME"] if ENV.key?("GEM_HOME") h["GEM PATHS"] = ENV["GEM_PATH"].split(File::PATH_SEPARATOR) if ENV.key?("GEM_PATH") && !ENV.key?("GEM_PATH").nil? - # ensure - # h + ensure + h end def paths - habitat_env["PATH"].split(File::PATH_SEPARATOR) + omnibus_env["PATH"].split(File::PATH_SEPARATOR) rescue OmnibusInstallNotFound ENV["PATH"].split(File::PATH_SEPARATOR) end diff --git a/lib/chef-cli/command/exec.rb b/lib/chef-cli/command/exec.rb index 9b86bbea..f1e19bde 100644 --- a/lib/chef-cli/command/exec.rb +++ b/lib/chef-cli/command/exec.rb @@ -30,7 +30,7 @@ class Exec < ChefCLI::Command::Base def run(params) # Set ENV directly on the "parent" process (us) before running #exec to # ensure the custom PATH is honored when finding the command to exec - habitat_env.each { |var, value| ENV[var] = value } + omnibus_env.each { |var, value| ENV[var] = value } exec(*params) raise "Exec failed without an exception, your ruby is buggy" # should never get here end diff --git a/lib/chef-cli/helpers.rb b/lib/chef-cli/helpers.rb index e658bf54..eaf5a58b 100644 --- a/lib/chef-cli/helpers.rb +++ b/lib/chef-cli/helpers.rb @@ -110,28 +110,47 @@ def git_windows_bin_dir @git_windows_bin_dir ||= File.expand_path(File.join(omnibus_root, "embedded", "git", "usr", "bin")) end + # # + # # environment vars for habitat + # # + # def habitat_env + # @habitat_env ||= + # begin + # # Define the necessary paths for the Habitat environment + # # Custom GEM_HOME within Habitat + # pkg_prefix = get_pkg_prefix + # vendor_dir = File.join(pkg_prefix, "vendor") + # path = [ + # File.join(pkg_prefix, "bin"), + # ENV["PATH"].split(File::PATH_SEPARATOR), # Preserve existing PATH + # ].flatten.uniq + + # { + # "PATH" => path.join(File::PATH_SEPARATOR), + # "GEM_ROOT" => Gem.default_dir, # Default directory for gems + # "GEM_HOME" => vendor_dir, # GEM_HOME pointing to the vendor directory + # "GEM_PATH" => vendor_dir, # GEM_PATH also pointing to the vendor directory + # } + # end + # end + # - # environment vars for habitat + # environment vars for omnibus # - def habitat_env - @habitat_env ||= - begin - # Define the necessary paths for the Habitat environment - # Custom GEM_HOME within Habitat - pkg_prefix = get_pkg_prefix - vendor_dir = File.join(pkg_prefix, "vendor") - path = [ - File.join(pkg_prefix, "bin"), - ENV["PATH"].split(File::PATH_SEPARATOR) # Preserve existing PATH - ].flatten.uniq - - { - "PATH" => path.join(File::PATH_SEPARATOR), - "GEM_ROOT" => Gem.default_dir, # Default directory for gems - "GEM_HOME" => vendor_dir, # GEM_HOME pointing to the vendor directory - "GEM_PATH" => vendor_dir, # GEM_PATH also pointing to the vendor directory - } - end + def omnibus_env + @omnibus_env ||= + begin + user_bin_dir = File.expand_path(File.join(Gem.user_dir, "bin")) + path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ] + path << git_bin_dir if Dir.exist?(git_bin_dir) + path << git_windows_bin_dir if Dir.exist?(git_windows_bin_dir) + { + "PATH" => path.flatten.uniq.join(File::PATH_SEPARATOR), + "GEM_ROOT" => Gem.default_dir, + "GEM_HOME" => Gem.user_dir, + "GEM_PATH" => Gem.path.join(File::PATH_SEPARATOR), + } + end end def get_pkg_prefix diff --git a/lib/chef-cli/version.rb b/lib/chef-cli/version.rb index 6311d505..b3cff0b9 100644 --- a/lib/chef-cli/version.rb +++ b/lib/chef-cli/version.rb @@ -16,5 +16,5 @@ # module ChefCLI - VERSION = "0.1.3".freeze + VERSION = "5.6.16".freeze end From 56b260735ae911bb370aa0bbd1cd07004df0b90e Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Mon, 3 Feb 2025 13:16:38 +0530 Subject: [PATCH 38/48] this func is not needed as of now Signed-off-by: nikhil2611 --- lib/chef-cli/helpers.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/chef-cli/helpers.rb b/lib/chef-cli/helpers.rb index eaf5a58b..0fa64780 100644 --- a/lib/chef-cli/helpers.rb +++ b/lib/chef-cli/helpers.rb @@ -153,17 +153,17 @@ def omnibus_env end end - def get_pkg_prefix - pkg_origin = "chef" - pkg_name = "#{pkg_origin}/chef-cli" # Your origin and package name - path = `hab pkg path #{pkg_name}`.strip - - if $?.success? && !path.empty? - path - else - raise "Failed to get pkg_prefix for #{pkg_name}: #{path}" - end - end + # def get_pkg_prefix + # pkg_origin = "chef" + # pkg_name = "#{pkg_origin}/chef-cli" # Your origin and package name + # path = `hab pkg path #{pkg_name}`.strip + + # if $?.success? && !path.empty? + # path + # else + # raise "Failed to get pkg_prefix for #{pkg_name}: #{path}" + # end + # end def omnibus_expand_path(*paths) dir = File.expand_path(File.join(paths)) From 92e22eae1ceda688d2665dfdedf013e3370f1077 Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 24 Dec 2024 13:35:16 +0530 Subject: [PATCH 39/48] Using the chef-test-kitchen-enterprise instead of old one Signed-off-by: Ashique Saidalavi --- Gemfile | 2 +- chef-cli.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 90f9a343..9258a8a7 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ group :test do gem "rspec-mocks", "~> 3.8" gem "cookstyle" gem "chefstyle" - gem "test-kitchen" + gem "chef-test-kitchen-enterprise", git: "https://github.com/chef/chef-test-kitchen-enterprise", branch: "main" gem "simplecov", require: false end diff --git a/chef-cli.gemspec b/chef-cli.gemspec index edbce7f3..35a36fe6 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -50,5 +50,5 @@ Gem::Specification.new do |gem| gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3" - gem.add_dependency "chef-licensing", ">= 1.0.2" + gem.add_dependency "chef-licensing", "~> 1.0" end From 3afcca6bc8bce47170fd4cdc3a08e6a6b55ca7fe Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 24 Dec 2024 13:47:09 +0530 Subject: [PATCH 40/48] Adding git as a pkg build dep Signed-off-by: Ashique Saidalavi --- habitat/plan.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/habitat/plan.sh b/habitat/plan.sh index 953f6593..7d5e8e51 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -9,6 +9,7 @@ pkg_build_deps=( core/sed core/gcc core/libarchive + core/git ) pkg_bin_dirs=(bin) From bd7b50e4b1af246a60ff93e27177ae7d939d8ccf Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 24 Dec 2024 15:09:09 +0530 Subject: [PATCH 41/48] Post bundle install script to setup the gems from github branches Signed-off-by: Ashique Saidalavi --- habitat/plan.ps1 | 6 +++--- habitat/plan.sh | 1 + post-bundle-install.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 post-bundle-install.rb diff --git a/habitat/plan.ps1 b/habitat/plan.ps1 index 78a26d83..e7cee43b 100644 --- a/habitat/plan.ps1 +++ b/habitat/plan.ps1 @@ -47,9 +47,9 @@ function Invoke-Build { bundle install gem build chef-cli.gemspec - Write-BuildLine " ** Using gem to install" - gem install chef-cli-*.gem --no-document - + Write-BuildLine " ** Using gem to install" + gem install chef-cli-*.gem --no-document + ruby ./post-bundle-install.rb If ($lastexitcode -ne 0) { Exit $lastexitcode } } finally { diff --git a/habitat/plan.sh b/habitat/plan.sh index 7d5e8e51..5969b09f 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -43,6 +43,7 @@ do_build() { bundle config --local silence_root_warning 1 bundle install gem build chef-cli.gemspec + ruby ./post-bundle-install.rb } do_install() { export GEM_HOME="$pkg_prefix/vendor" diff --git a/post-bundle-install.rb b/post-bundle-install.rb new file mode 100644 index 00000000..e9ae4304 --- /dev/null +++ b/post-bundle-install.rb @@ -0,0 +1,30 @@ +#!/usr/bin/env ruby + +gem_home = Gem.paths.home + +puts "fixing bundle installed gems in #{gem_home}" + +# Install gems from git repos. This makes the assumption that there is a .gemspec and +# you can simply gem build + gem install the resulting gem, so nothing fancy. This does not use +# rake install since we need --conservative --minimal-deps in order to not install duplicate gems. +# +# +puts "gem path #{gem_home}" + +Dir["#{gem_home}/bundler/gems/*"].each do |gempath| + puts "#{gempath}" + matches = File.basename(gempath).match(/.*-[A-Fa-f0-9]{12}/) + next unless matches + + gem_name = File.basename(Dir["#{gempath}/*.gemspec"].first, ".gemspec") + # FIXME: should strip any valid ruby platform off of the gem_name if it matches + + next unless gem_name + + puts "re-installing #{gem_name}..." + + Dir.chdir(gempath) do + system("gem build #{gem_name}.gemspec") or raise "gem build failed" + system("gem install #{gem_name}*.gem --conservative --minimal-deps --no-document") or raise "gem install failed" + end +end From e79549aff8e5406a70b48227eaa4d06fe73e9d41 Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 24 Dec 2024 15:20:20 +0530 Subject: [PATCH 42/48] Added the faraday_middleware gem Signed-off-by: Ashique Saidalavi --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 9258a8a7..d7097f9e 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ group :test do gem "rspec-mocks", "~> 3.8" gem "cookstyle" gem "chefstyle" + gem "faraday_middleware" gem "chef-test-kitchen-enterprise", git: "https://github.com/chef/chef-test-kitchen-enterprise", branch: "main" gem "simplecov", require: false end From 8afec2b7883a3caad69ecfbef80680012b819ebb Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 24 Dec 2024 15:41:19 +0530 Subject: [PATCH 43/48] Fixed the shell-init command Signed-off-by: Ashique Saidalavi --- lib/chef-cli/command/shell_init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef-cli/command/shell_init.rb b/lib/chef-cli/command/shell_init.rb index 7d7dda0e..0e8ca59b 100644 --- a/lib/chef-cli/command/shell_init.rb +++ b/lib/chef-cli/command/shell_init.rb @@ -103,7 +103,7 @@ def run(argv) return 1 end - env = omnibus_env.dup + env = habitat_env.dup path = env.delete("PATH") export(shell_name, "PATH", path) env.each do |var_name, value| From 93d566ee6a270f477dd79d731933208ca68e41ad Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 24 Dec 2024 17:35:06 +0530 Subject: [PATCH 44/48] Reverted the post-bundle-install script for the windows Signed-off-by: Ashique Saidalavi --- chef-cli.gemspec | 2 +- habitat/plan.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 35a36fe6..5e62b43a 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -43,7 +43,7 @@ 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", "~> 18.0" + gem.add_dependency "chef", "= 18.5.0" 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/habitat/plan.ps1 b/habitat/plan.ps1 index e7cee43b..c6580bce 100644 --- a/habitat/plan.ps1 +++ b/habitat/plan.ps1 @@ -49,7 +49,7 @@ function Invoke-Build { gem build chef-cli.gemspec Write-BuildLine " ** Using gem to install" gem install chef-cli-*.gem --no-document - ruby ./post-bundle-install.rb +# ruby ./post-bundle-install.rb If ($lastexitcode -ne 0) { Exit $lastexitcode } } finally { From 840b9a2ab677d8348a557b0cc3a7d92366b223ac Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 24 Dec 2024 18:18:33 +0530 Subject: [PATCH 45/48] Added the post-bundle-install script for windows plan file Signed-off-by: Ashique Saidalavi --- habitat/plan.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/habitat/plan.ps1 b/habitat/plan.ps1 index c6580bce..e7cee43b 100644 --- a/habitat/plan.ps1 +++ b/habitat/plan.ps1 @@ -49,7 +49,7 @@ function Invoke-Build { gem build chef-cli.gemspec Write-BuildLine " ** Using gem to install" gem install chef-cli-*.gem --no-document -# ruby ./post-bundle-install.rb + ruby ./post-bundle-install.rb If ($lastexitcode -ne 0) { Exit $lastexitcode } } finally { From 5561d8cbd5c4f2db06ee7bd4be804d5ca540185b Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 4 Feb 2025 18:40:08 +0530 Subject: [PATCH 46/48] Updated the shell-init command to work with habitat and omnibus installations Signed-off-by: Ashique Saidalavi --- chef-cli.gemspec | 2 +- lib/chef-cli/command/env.rb | 3 +- lib/chef-cli/command/exec.rb | 3 +- lib/chef-cli/command/license.rb | 2 + lib/chef-cli/command/shell_init.rb | 7 +- lib/chef-cli/completions/bash.sh.erb | 2 +- lib/chef-cli/completions/chef.fish.erb | 2 +- lib/chef-cli/completions/zsh.zsh.erb | 2 +- lib/chef-cli/dist.rb | 3 + lib/chef-cli/helpers.rb | 89 ++++++++++++++--------- lib/chef-cli/licensing/config.rb | 3 +- spec/unit/command/env_spec.rb | 2 + spec/unit/command/exec_spec.rb | 1 + spec/unit/command/shell_init_spec.rb | 98 ++++++++++++++++++++++++++ spec/unit/helpers_spec.rb | 30 +++++++- 15 files changed, 206 insertions(+), 43 deletions(-) diff --git a/chef-cli.gemspec b/chef-cli.gemspec index 5e62b43a..35a36fe6 100644 --- a/chef-cli.gemspec +++ b/chef-cli.gemspec @@ -43,7 +43,7 @@ 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", "= 18.5.0" + gem.add_dependency "chef", "~> 18.0" 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/command/env.rb b/lib/chef-cli/command/env.rb index d1aed4b2..b157d557 100644 --- a/lib/chef-cli/command/env.rb +++ b/lib/chef-cli/command/env.rb @@ -85,7 +85,8 @@ def gem_environment end def paths - omnibus_env["PATH"].split(File::PATH_SEPARATOR) + env = habitat_install? ? habitat_env : omnibus_env + env["PATH"].split(File::PATH_SEPARATOR) rescue OmnibusInstallNotFound ENV["PATH"].split(File::PATH_SEPARATOR) end diff --git a/lib/chef-cli/command/exec.rb b/lib/chef-cli/command/exec.rb index f1e19bde..d66438a7 100644 --- a/lib/chef-cli/command/exec.rb +++ b/lib/chef-cli/command/exec.rb @@ -30,7 +30,8 @@ class Exec < ChefCLI::Command::Base def run(params) # Set ENV directly on the "parent" process (us) before running #exec to # ensure the custom PATH is honored when finding the command to exec - omnibus_env.each { |var, value| ENV[var] = value } + env = habitat_install? ? habitat_env : omnibus_env + env.each { |var, value| ENV[var] = value } exec(*params) raise "Exec failed without an exception, your ruby is buggy" # should never get here end diff --git a/lib/chef-cli/command/license.rb b/lib/chef-cli/command/license.rb index 676ff2a8..039fb34e 100644 --- a/lib/chef-cli/command/license.rb +++ b/lib/chef-cli/command/license.rb @@ -75,6 +75,8 @@ def run(params) else ChefCLI::Licensing::Base.send(remaining_args[0]) end + rescue ChefLicensing::LicenseKeyFetcher::LicenseKeyNotFetchedError + ui.msg("License key not fetched. Please try again.") end def debug? diff --git a/lib/chef-cli/command/shell_init.rb b/lib/chef-cli/command/shell_init.rb index 0e8ca59b..bd1253ea 100644 --- a/lib/chef-cli/command/shell_init.rb +++ b/lib/chef-cli/command/shell_init.rb @@ -29,6 +29,7 @@ module Mixlib module ChefCLI class ShellCompletionTemplateContext + include ChefCLI::Helpers def commands ChefCLI.commands_map.command_specs.inject({}) do |cmd_info, (_key, cmd_spec)| @@ -40,6 +41,10 @@ def commands def get_binding binding end + + def habitat? + habitat_install? + end end module Command @@ -103,7 +108,7 @@ def run(argv) return 1 end - env = habitat_env.dup + env = (habitat_install? ? habitat_env : omnibus_env).dup path = env.delete("PATH") export(shell_name, "PATH", path) env.each do |var_name, value| diff --git a/lib/chef-cli/completions/bash.sh.erb b/lib/chef-cli/completions/bash.sh.erb index 79c6ada6..86f6b66d 100644 --- a/lib/chef-cli/completions/bash.sh.erb +++ b/lib/chef-cli/completions/bash.sh.erb @@ -2,4 +2,4 @@ _chef_comp() { local COMMANDS="<%= commands.keys.join(' ')-%>" COMPREPLY=($(compgen -W "$COMMANDS" -- ${COMP_WORDS[COMP_CWORD]} )) } -complete -F _chef_comp chef +complete -F _chef_comp <%= habitat? ? "chef-cli" : "chef" %> diff --git a/lib/chef-cli/completions/chef.fish.erb b/lib/chef-cli/completions/chef.fish.erb index 44f2a569..018b27e6 100644 --- a/lib/chef-cli/completions/chef.fish.erb +++ b/lib/chef-cli/completions/chef.fish.erb @@ -5,5 +5,5 @@ set -l chef_commands <%= commands.keys.join(' ') %>; <% commands.each do |command, desc| -%> -complete -c chef -f -n "not __fish_seen_subcommand_from $chef_commands" -a <%= command %> -d "<%= desc %>"; +complete -c <%= habitat? ? "chef-cli" : "chef" %> -f -n "not __fish_seen_subcommand_from $chef_commands" -a <%= command %> -d "<%= desc %>"; <% end -%> diff --git a/lib/chef-cli/completions/zsh.zsh.erb b/lib/chef-cli/completions/zsh.zsh.erb index ac4986de..15056c3c 100644 --- a/lib/chef-cli/completions/zsh.zsh.erb +++ b/lib/chef-cli/completions/zsh.zsh.erb @@ -17,5 +17,5 @@ function _chef() { fi } -compdef _chef chef +compdef _chef <%= habitat? ? "chef-cli" : "chef" %> diff --git a/lib/chef-cli/dist.rb b/lib/chef-cli/dist.rb index ead75796..a0a31856 100644 --- a/lib/chef-cli/dist.rb +++ b/lib/chef-cli/dist.rb @@ -10,6 +10,9 @@ class Dist CLI_PRODUCT = "Chef CLI".freeze CLI_GEM = "chef-cli".freeze + CHEF_DKE_PKG_NAME = "chef/chef-development-kit-enterprise".freeze + HAB_PKG_NAME = "chef/chef-cli".freeze + # the name of the overall infra product INFRA_PRODUCT = "Chef Infra".freeze diff --git a/lib/chef-cli/helpers.rb b/lib/chef-cli/helpers.rb index 0fa64780..f3edc533 100644 --- a/lib/chef-cli/helpers.rb +++ b/lib/chef-cli/helpers.rb @@ -60,6 +60,21 @@ def omnibus_install? File.exist?(expected_omnibus_root) && File.exist?(File.join(expected_omnibus_root, "version-manifest.json")) end + # The habitat version of the chef-cli can be installed with standalone or chef-development-kit-enterprise + # This method checks if the habitat version of chef-cli is installed as standalone + def habitat_standalone? + @hab_standalone ||= (hab_pkg_installed?(ChefCLI::Dist::HAB_PKG_NAME) && !habitat_chef_dke?) + end + + # This method checks if the habitat version of chef-cli is installed with chef-development-kit-enterprise + def habitat_chef_dke? + @hab_dke ||= hab_pkg_installed?(ChefCLI::Dist::CHEF_DKE_PKG_NAME) + end + + def habitat_install? + habitat_chef_dke? || habitat_standalone? + end + def omnibus_root @omnibus_root ||= omnibus_expand_path(expected_omnibus_root) end @@ -110,29 +125,30 @@ def git_windows_bin_dir @git_windows_bin_dir ||= File.expand_path(File.join(omnibus_root, "embedded", "git", "usr", "bin")) end - # # - # # environment vars for habitat - # # - # def habitat_env - # @habitat_env ||= - # begin - # # Define the necessary paths for the Habitat environment - # # Custom GEM_HOME within Habitat - # pkg_prefix = get_pkg_prefix - # vendor_dir = File.join(pkg_prefix, "vendor") - # path = [ - # File.join(pkg_prefix, "bin"), - # ENV["PATH"].split(File::PATH_SEPARATOR), # Preserve existing PATH - # ].flatten.uniq - - # { - # "PATH" => path.join(File::PATH_SEPARATOR), - # "GEM_ROOT" => Gem.default_dir, # Default directory for gems - # "GEM_HOME" => vendor_dir, # GEM_HOME pointing to the vendor directory - # "GEM_PATH" => vendor_dir, # GEM_PATH also pointing to the vendor directory - # } - # end - # end + # + # environment vars for habitat + # + def habitat_env + @habitat_env ||= + begin + # Define the necessary paths for the Habitat environment + # If it is a chef-dke installation, we will use the chef-dke bin path. + # Otherwise, we will use the chef-cli bin path. + bin_pkg_prefix = get_pkg_prefix(habitat_chef_dke? ? ChefCLI::Dist::CHEF_DKE_PKG_NAME : ChefCLI::Dist::HAB_PKG_NAME) + vendor_dir = File.join(get_pkg_prefix(ChefCLI::Dist::HAB_PKG_NAME), "vendor") + path = [ + File.join(bin_pkg_prefix, "bin"), + ENV["PATH"].split(File::PATH_SEPARATOR), # Preserve existing PATH + ].flatten.uniq + + { + "PATH" => path.join(File::PATH_SEPARATOR), + "GEM_ROOT" => Gem.default_dir, # Default directory for gems + "GEM_HOME" => vendor_dir, # GEM_HOME pointing to the vendor directory + "GEM_PATH" => vendor_dir, # GEM_PATH also pointing to the vendor directory + } + end + end # # environment vars for omnibus @@ -153,17 +169,15 @@ def omnibus_env end end - # def get_pkg_prefix - # pkg_origin = "chef" - # pkg_name = "#{pkg_origin}/chef-cli" # Your origin and package name - # path = `hab pkg path #{pkg_name}`.strip + def get_pkg_prefix(pkg_name) + path = `hab pkg path #{pkg_name}`.strip - # if $?.success? && !path.empty? - # path - # else - # raise "Failed to get pkg_prefix for #{pkg_name}: #{path}" - # end - # end + if $?.success? && !path.empty? + path + else + raise "Failed to get pkg_prefix for #{pkg_name}: #{path}" + end + end def omnibus_expand_path(*paths) dir = File.expand_path(File.join(paths)) @@ -209,5 +223,14 @@ def reset! def macos? !!(RUBY_PLATFORM =~ /darwin/) end + + # @return [Boolean] Checks if a habitat package is installed. + # If habitat itself is not installed, this method will return false. + # + # @api private + # + def hab_pkg_installed?(pkg_name) + `hab pkg list #{pkg_name} 2>/dev/null`.include?(pkg_name) rescue false + end end end diff --git a/lib/chef-cli/licensing/config.rb b/lib/chef-cli/licensing/config.rb index 901ebf43..3d3cbcf8 100644 --- a/lib/chef-cli/licensing/config.rb +++ b/lib/chef-cli/licensing/config.rb @@ -22,6 +22,5 @@ config.chef_product_name = "workstation" config.chef_entitlement_id = "x6f3bc76-a94f-4b6c-bc97-4b7ed2b045c0" config.chef_executable_name = "chef" - # config.license_server_url = "https://services.chef.io/licensing" - config.license_server_url = "https://licensing-acceptance.chef.co/License" + config.license_server_url = "https://services.chef.io/licensing" end diff --git a/spec/unit/command/env_spec.rb b/spec/unit/command/env_spec.rb index d614b397..4572ed97 100644 --- a/spec/unit/command/env_spec.rb +++ b/spec/unit/command/env_spec.rb @@ -35,6 +35,7 @@ describe "when running from within an omnibus install" do before do + allow(command_instance).to receive(:habitat_install?).and_return false allow(command_instance).to receive(:omnibus_install?).and_return true allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir) allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir) @@ -57,6 +58,7 @@ end describe "when running locally" do before do + allow(command_instance).to receive(:habitat_install?).and_return false allow(command_instance).to receive(:omnibus_install?).and_return false command_instance.ui = ui end diff --git a/spec/unit/command/exec_spec.rb b/spec/unit/command/exec_spec.rb index 6cb99a79..15fcb46a 100644 --- a/spec/unit/command/exec_spec.rb +++ b/spec/unit/command/exec_spec.rb @@ -57,6 +57,7 @@ def run_command let(:ruby_path) { File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby") } before do + allow(command_instance).to receive(:habitat_install?).and_return(false) allow(Gem).to receive(:ruby).and_return(ruby_path) # Using a fake path separator to keep to prevent people from accidentally diff --git a/spec/unit/command/shell_init_spec.rb b/spec/unit/command/shell_init_spec.rb index fbe4c752..f82f9602 100644 --- a/spec/unit/command/shell_init_spec.rb +++ b/spec/unit/command/shell_init_spec.rb @@ -39,6 +39,7 @@ before do allow(::Dir).to receive(:exist?).and_call_original + allow(command_instance).to receive(:habitat_install?).and_return(false) end context "with no explicit omnibus directory" do @@ -98,6 +99,7 @@ shared_examples "a posix shell script" do |shell| before do stub_const("File::PATH_SEPARATOR", ":") + allow(command_instance).to receive(:habitat_install?).and_return(false) end let(:expected_environment_commands) do @@ -114,6 +116,7 @@ shared_examples "a powershell script" do |shell| before do stub_const("File::PATH_SEPARATOR", ";") + allow(command_instance).to receive(:habitat_install?).and_return(false) end let(:expected_environment_commands) do @@ -163,8 +166,10 @@ before do # Stub this or else we'd have to update the test every time a new command # is added. + allow(command_instance).to receive(:habitat_install?).and_return(false) allow(command_instance.shell_completion_template_context).to receive(:commands) .and_return(command_descriptions) + allow(command_instance.shell_completion_template_context).to receive(:habitat?).and_return(false) allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir) allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir) @@ -228,6 +233,7 @@ before do # Stub this or else we'd have to update the test every time a new command # is added. + allow(command_instance).to receive(:habitat_install?).and_return(false) allow(command_instance.shell_completion_template_context).to receive(:commands) .and_return(command_descriptions) @@ -244,8 +250,10 @@ context "for fish" do before do + allow(command_instance).to receive(:habitat_install?).and_return(false) stub_const("File::PATH_SEPARATOR", ":") end + let(:expected_path) { [omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"], git_bin_dir].join(":").split(":").join('" "') } let(:expected_environment_commands) do <<~EOH @@ -336,4 +344,94 @@ end + context "habitat standalone shell-init on bash" do + let(:cli_hab_path) { "/hab/pkgs/chef/chef-cli/1.0.0/123" } + + let(:argv) { ["bash"] } + + before do + allow(command_instance).to receive(:habitat_chef_dke?).and_return(false) + allow(command_instance).to receive(:habitat_standalone?).and_return(true) + end + + it "should return the correct paths" do + expect(command_instance).to receive(:get_pkg_prefix).with("chef/chef-cli").twice.and_return(cli_hab_path) + + command_instance.run(argv) + expect(stdout_io.string).to include("export PATH=\"#{cli_hab_path}/bin") + expect(stdout_io.string).to include("export GEM_HOME=\"#{cli_hab_path}/vendor") + expect(stdout_io.string).to include("export GEM_PATH=\"#{cli_hab_path}/vendor") + end + end + + context "with chef-development-kit-enterprise habitat pkg shell-init on bash" do + + let(:chef_dke_path) { "/hab/pkgs/chef/chef-development-kit-enterprise/1.0.0/123" } + let(:cli_hab_path) { "/hab/pkgs/chef/chef-cli/1.0.0/123" } + + let(:argv) { ["bash"] } + + before do + allow(command_instance).to receive(:habitat_chef_dke?).and_return(true) + allow(command_instance).to receive(:habitat_standalone?).and_return(false) + end + + it "should return the correct paths" do + expect(command_instance).to receive(:get_pkg_prefix).with("chef/chef-development-kit-enterprise").and_return(chef_dke_path) + expect(command_instance).to receive(:get_pkg_prefix).with("chef/chef-cli").and_return(cli_hab_path) + + command_instance.run(argv) + expect(stdout_io.string).to include("export PATH=\"#{chef_dke_path}/bin") + expect(stdout_io.string).to include("export GEM_HOME=\"#{cli_hab_path}/vendor") + expect(stdout_io.string).to include("export GEM_PATH=\"#{cli_hab_path}/vendor") + end + + describe "autocompletion" do + let(:command_descriptions) do + { + "exec" => "Runs the command in context of the embedded ruby", + "env" => "Prints environment variables used by #{ChefCLI::Dist::PRODUCT}", + "gem" => "Runs the `gem` command in context of the embedded ruby", + "generate" => "Generate a new app, cookbook, or component", + } + end + + let(:omnibus_bin_dir) { "/foo/bin" } + let(:omnibus_embedded_bin_dir) { "/foo/embedded/bin" } + + let(:argv) { [ "bash" ] } + + let(:expected_completion_function) do + <<~END_COMPLETION + _chef_comp() { + local COMMANDS="exec env gem generate" + COMPREPLY=($(compgen -W "$COMMANDS" -- ${COMP_WORDS[COMP_CWORD]} )) + } + complete -F _chef_comp chef-cli + END_COMPLETION + end + + before do + # Stub this or else we'd have to update the test every time a new command + # is added. + allow(command_instance).to receive(:get_pkg_prefix).with("chef/chef-development-kit-enterprise").and_return(chef_dke_path) + allow(command_instance).to receive(:get_pkg_prefix).with("chef/chef-cli").and_return(cli_hab_path) + allow(command_instance.shell_completion_template_context).to receive(:commands) + .and_return(command_descriptions) + allow(command_instance.shell_completion_template_context).to receive(:habitat?).and_return(true) + + allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir) + allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir) + end + + it "generates a completion function for the chef command" do + command_instance.run(argv) + expect(stdout_io.string).to include(expected_completion_function) + end + + it "should generate the autocompletion" do + + end + end + end end diff --git a/spec/unit/helpers_spec.rb b/spec/unit/helpers_spec.rb index 07f1dce2..7ae9891c 100644 --- a/spec/unit/helpers_spec.rb +++ b/spec/unit/helpers_spec.rb @@ -19,6 +19,7 @@ describe ChefCLI::Helpers do context "path_check!" do + let(:ruby_path) { "/opt/chef-workstation/embedded/bin/ruby" } before do allow(Gem).to receive(:ruby).and_return(ruby_path) @@ -38,7 +39,7 @@ let(:expected_GEM_ROOT) { Gem.default_dir } let(:expected_GEM_HOME) { Gem.user_dir } let(:expected_GEM_PATH) { Gem.path.join(File::PATH_SEPARATOR) } - let(:ruby_path) { "/opt/chef-workstation/embedded/bin/ruby" } + it "#omnibus_env path" do allow(ChefCLI::Helpers).to receive(:omnibus_bin_dir).and_return("/opt/chef-workstation/bin") @@ -107,5 +108,32 @@ end end + + context "when installed with habitat" do + let(:chef_dke_path) { "/hab/pkgs/chef/chef-development-kit-enterprise/1.0.0/123" } + let(:cli_hab_path) { "/hab/pkgs/chef/chef-cli/1.0.0/123" } + let(:expected_gem_root) { Gem.default_dir } + let(:expected_env) do + { + "PATH" => "#{chef_dke_path}/bin:/usr/bin:/bin", + "GEM_ROOT" => expected_gem_root, + "GEM_HOME" => "#{cli_hab_path}/vendor", + "GEM_PATH" => "#{cli_hab_path}/vendor", + } + end + + before do + allow(ChefCLI::Helpers).to receive(:habitat_chef_dke?).and_return true + allow(ChefCLI::Helpers).to receive(:habitat_standalone?).and_return false + allow(ENV).to receive(:[]).with("PATH").and_return("/usr/bin:/bin") + end + + it "should return the habitat env" do + expect(ChefCLI::Helpers).to receive(:get_pkg_prefix).with("chef/chef-development-kit-enterprise").and_return(chef_dke_path) + expect(ChefCLI::Helpers).to receive(:get_pkg_prefix).with("chef/chef-cli").and_return(cli_hab_path) + + expect(ChefCLI::Helpers.habitat_env).to eq(expected_env) + end + end end end From f16dfea0fceb442bf14ed581e28a24a2f1a4711b Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 4 Feb 2025 20:38:44 +0530 Subject: [PATCH 47/48] Spec fixes Signed-off-by: Ashique Saidalavi --- spec/unit/helpers_spec.rb | 3 ++- spec/unit/policyfile_services/clean_policies_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/unit/helpers_spec.rb b/spec/unit/helpers_spec.rb index 7ae9891c..0a71e312 100644 --- a/spec/unit/helpers_spec.rb +++ b/spec/unit/helpers_spec.rb @@ -113,9 +113,10 @@ let(:chef_dke_path) { "/hab/pkgs/chef/chef-development-kit-enterprise/1.0.0/123" } let(:cli_hab_path) { "/hab/pkgs/chef/chef-cli/1.0.0/123" } let(:expected_gem_root) { Gem.default_dir } + let(:expected_path) { %W{#{chef_dke_path}/bin /usr/bin:/bin} } let(:expected_env) do { - "PATH" => "#{chef_dke_path}/bin:/usr/bin:/bin", + "PATH" => expected_path.join(File::PATH_SEPARATOR) , "GEM_ROOT" => expected_gem_root, "GEM_HOME" => "#{cli_hab_path}/vendor", "GEM_PATH" => "#{cli_hab_path}/vendor", diff --git a/spec/unit/policyfile_services/clean_policies_spec.rb b/spec/unit/policyfile_services/clean_policies_spec.rb index 6d462fc2..bf19081a 100644 --- a/spec/unit/policyfile_services/clean_policies_spec.rb +++ b/spec/unit/policyfile_services/clean_policies_spec.rb @@ -218,8 +218,8 @@ - appserver (4444444444444444444444444444444444444444444444444444444444444444): Net::HTTPClientException 403 \"Unauthorized\" ERROR - expect { clean_policies_service.run }.to raise_error do |error| - expect(error.message).to eq(expected_message) + expect { clean_policies_service.run }.to raise_error(ChefCLI::PolicyfileCleanError) do |error| + expect(error.message).to include("403 \"Unauthorized\"") end expected_message = <<~MESSAGE DELETE appserver 4444444444444444444444444444444444444444444444444444444444444444 From 23d7601689b862944f1cad688c80cc46f0082869 Mon Sep 17 00:00:00 2001 From: nikhil2611 Date: Wed, 5 Feb 2025 10:56:17 +0530 Subject: [PATCH 48/48] this file is not require Signed-off-by: nikhil2611 --- .../noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore diff --git a/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore b/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore deleted file mode 100644 index e69de29b..00000000