From f2415c373a89f653f991eb7c589da67b6fe36a43 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 14 May 2025 20:52:41 +0000 Subject: [PATCH 1/3] Updating for Ruby 3.4 and Cookstyle Signed-off-by: John McCrae --- .expeditor/verify.pipeline.yml | 16 ++++++++-------- Gemfile | 2 -- Rakefile | 17 +++++++++++------ lib/mixlib/cli.rb | 1 - mixlib-cli.gemspec | 3 ++- spec/mixlib/cli_spec.rb | 4 ++-- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 7b0b786..6572c80 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -6,23 +6,23 @@ expeditor: steps: -- label: run-lint-and-specs-ruby-3.0 +- label: run-lint-and-specs-ruby-3.1 command: - .expeditor/run_linux_tests.sh rake expeditor: executor: docker: - image: ruby:3.0 + image: ruby:3.1 -- label: run-lint-and-specs-ruby-3.1 +- label: run-lint-and-specs-ruby-3.4 command: - .expeditor/run_linux_tests.sh rake expeditor: executor: docker: - image: ruby:3.1 + image: ruby:3.4 -- label: run-specs-ruby-3.0-windows +- label: run-specs-ruby-3.1-windows commands: - .expeditor/run_windows_tests.ps1 @@ -31,9 +31,9 @@ steps: docker: host_os: windows shell: ["powershell"] - image: rubydistros/windows-2019:3.0 + image: rubydistros/windows-2019:3.1 -- label: run-specs-ruby-3.1-windows +- label: run-specs-ruby-3.4-windows commands: - .expeditor/run_windows_tests.ps1 @@ -42,4 +42,4 @@ steps: docker: host_os: windows shell: ["powershell"] - image: rubydistros/windows-2019:3.1 + image: rubydistros/windows-2019:3.4 diff --git a/Gemfile b/Gemfile index da51dff..31f60c0 100644 --- a/Gemfile +++ b/Gemfile @@ -9,10 +9,8 @@ group :docs do end group :test do - gem "chefstyle" gem "rake" gem "rspec", "~> 3.0" - gem "rubocop-ast" end group :debug do diff --git a/Rakefile b/Rakefile index 1d5a2f5..e42b161 100644 --- a/Rakefile +++ b/Rakefile @@ -12,15 +12,20 @@ rescue LoadError end end -begin - require "chefstyle" +desc "Check Linting and code style." +task :style do require "rubocop/rake_task" - desc "Run Chefstyle tests" - RuboCop::RakeTask.new(:style) do |task| - task.options += ["--display-cop-names", "--no-color"] + require "cookstyle/chefstyle" + + if RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/ + # Windows-specific command, rubocop erroneously reports the CRLF in each file which is removed when your PR is uploaeded to GitHub. + # This is a workaround to ignore the CRLF from the files before running cookstyle. + sh "cookstyle --chefstyle -c .rubocop.yml --except Layout/EndOfLine" + else + sh "cookstyle --chefstyle -c .rubocop.yml" end rescue LoadError - puts "chefstyle gem is not installed. bundle install first to make sure all dependencies are installed." + puts "Rubocop or Cookstyle gems are not installed. bundle install first to make sure all dependencies are installed." end begin diff --git a/lib/mixlib/cli.rb b/lib/mixlib/cli.rb index 5961ca4..445d03d 100644 --- a/lib/mixlib/cli.rb +++ b/lib/mixlib/cli.rb @@ -155,7 +155,6 @@ def deprecated_option(name, boolean: false, value_mapper: nil, keep: true) - description = if replacement replacement_cfg = options[replacement] display_name = CLI::Formatter.combined_option_display_name(replacement_cfg[:short], replacement_cfg[:long]) diff --git a/mixlib-cli.gemspec b/mixlib-cli.gemspec index 4432d4e..238f437 100644 --- a/mixlib-cli.gemspec +++ b/mixlib-cli.gemspec @@ -10,8 +10,9 @@ Gem::Specification.new do |s| s.email = "info@chef.io" s.homepage = "https://github.com/chef/mixlib-cli" s.license = "Apache-2.0" - s.required_ruby_version = ">= 3.0" + s.required_ruby_version = ">= 3.1" s.require_path = "lib" s.files = %w{LICENSE NOTICE} + Dir.glob("lib/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } + s.add_development_dependency "cookstyle", "~> 8.1" end diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb index e62b652..65e3278 100644 --- a/spec/mixlib/cli_spec.rb +++ b/spec/mixlib/cli_spec.rb @@ -375,8 +375,8 @@ context "and the replacement and deprecated are both boolean" do before do TestCLI.deprecated_option(:option_x, boolean: true, - long: "--[no-]option-x", - replacement: :option_a) + long: "--[no-]option-x", + replacement: :option_a) end it "sets original and replacement to true when the deprecated flag is used" do cli.parse_options(%w{--option-x}) From 435e0ac9b677ff76b844b81d7612f47ee63d6fbf Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 14 May 2025 20:53:09 +0000 Subject: [PATCH 2/3] Updating for Ruby 3.4 and Cookstyle Signed-off-by: John McCrae --- .github/workflows/lint.yml | 27 +++++++++++++++++++++ .github/workflows/unit.yml | 31 ++++++++++++++++++++++++ .rubocop.yml | 48 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/unit.yml create mode 100644 .rubocop.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..80f6b5b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +--- +name: lint + +on: + pull_request: + push: + branches: + - main + +concurrency: + group: lint-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1 + bundler-cache: false + - uses: r7kamura/rubocop-problem-matchers-action@v1 # this shows the failures in the PR + - run: | + gem install cookstyle + cookstyle --chefstyle -c .rubocop.yml + \ No newline at end of file diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml new file mode 100644 index 0000000..c6080ab --- /dev/null +++ b/.github/workflows/unit.yml @@ -0,0 +1,31 @@ +--- +name: unit + +on: + pull_request: + push: + branches: + - master + +permissions: + contents: read + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: [windows-2019, windows-2022] + ruby: ['3.1', '3.4'] + name: Unit test on ${{ matrix.os }} with Ruby ${{ matrix.ruby }} + runs-on: ${{ matrix.os }} + env: + RUBYOPT: '--disable-error_highlight' + steps: + - uses: actions/checkout@v4 + - name: ruby-setup + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rake spec \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..778afb6 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,48 @@ +AllCops: + TargetRubyVersion: 2.6 + Exclude: + - "spec/data/**/*" + - "habitat/**/*" + - "vendor/**/*" +Security/Eval: + Enabled: false +Lint/UselessAssignment: + Enabled: false +Lint/DeprecatedClassMethods: + Enabled: false +Lint/AmbiguousRegexpLiteral: + Enabled: false +Lint/AssignmentInCondition: + Enabled: false +Lint/AmbiguousBlockAssociation: + Enabled: false +Layout/EndOfLine: + Enabled: false +Lint/ShadowingOuterLocalVariable: + Enabled: false +Lint/IneffectiveAccessModifier: + Enabled: false +Lint/InterpolationCheck: + Enabled: true + Exclude: + - 'spec/unit/property_spec.rb' + - 'spec/functional/shell_spec.rb' +Lint/DeprecatedConstants: + Enabled: true + Exclude: + - lib/chef/node/attribute.rb # false alarms + + +# This cop shouldn't alert on the helper / specs itself +Chef/Ruby/LegacyPowershellOutMethods: + Exclude: + - 'lib/chef/mixin/powershell_out.rb' + - 'spec/functional/mixin/powershell_out_spec.rb' + - 'spec/unit/mixin/powershell_out_spec.rb' + - 'lib/chef/resource/windows_feature_powershell.rb' # https://github.com/chef/chef/issues/10927 + - 'lib/chef/provider/package/powershell.rb' # https://github.com/chef/chef/issues/10926 + +# set additional paths +Chef/Ruby/UnlessDefinedRequire: + Include: + - 'lib/**/*' From be6b2d41286fc60c1f0fe62adfeb4dacf12b0003 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Thu, 15 May 2025 19:04:33 +0000 Subject: [PATCH 3/3] Updating for Ruby 3.4 and Cookstyle Signed-off-by: John McCrae --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 778afb6..a1a0195 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.1 Exclude: - "spec/data/**/*" - "habitat/**/*"