From 1a30cca0dc1b25dbd4892012213798cba0a23057 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 14 May 2025 21:03:38 +0000 Subject: [PATCH 01/11] 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 +++++++++++++++++++++++++++++++++++ Gemfile | 1 - Rakefile | 17 ++++++++----- mixlib-authentication.gemspec | 3 ++- 6 files changed, 119 insertions(+), 8 deletions(-) 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/**/*' diff --git a/Gemfile b/Gemfile index 93bb8f1..7fde256 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,6 @@ source "https://rubygems.org" gemspec group :test do - gem "cookstyle", ">= 7.32.8" gem "mixlib-log", "~> 3" gem "net-ssh" gem "rake" diff --git a/Rakefile b/Rakefile index b3bc937..90669af 100644 --- a/Rakefile +++ b/Rakefile @@ -12,15 +12,20 @@ rescue LoadError end end -begin - require "cookstyle/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 "cookstyle 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 task :console do diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index a9d4ddd..9009038 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -10,8 +10,9 @@ Gem::Specification.new do |s| s.author = "Chef Software, Inc." s.email = "info@chef.io" s.homepage = "https://github.com/chef/mixlib-authentication" - s.required_ruby_version = ">= 2.5" + s.required_ruby_version = ">= 3.1" s.files = %w{LICENSE} + Dir.glob("lib/**/*") s.require_paths = ["lib"] + s.add_development_dependency "cookstyle", "~> 8.1" end From 0fb91a59291b1895888f756a71ac79308ab62845 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 14 May 2025 21:05:20 +0000 Subject: [PATCH 02/11] Updating for Ruby 3.4 and Cookstyle Signed-off-by: John McCrae --- .expeditor/verify.pipeline.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.expeditor/verify.pipeline.yml b/.expeditor/verify.pipeline.yml index 69d6ed8..4ddccc8 100644 --- a/.expeditor/verify.pipeline.yml +++ b/.expeditor/verify.pipeline.yml @@ -8,23 +8,23 @@ expeditor: steps: -- label: run-specs-:ruby:-3.0 +- label: run-specs-:ruby:-3.1 command: - .expeditor/run_linux_tests.sh rake spec expeditor: executor: docker: - image: ruby:3.0 + image: ruby:3.1 -- label: run-specs-:ruby:-3.1 +- label: run-specs-:ruby:-3.4 command: - .expeditor/run_linux_tests.sh rake spec 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 command: - .expeditor/run_windows_tests.ps1 expeditor: @@ -32,10 +32,10 @@ steps: docker: host_os: windows shell: ["powershell", "-Command"] - image: rubydistros/windows-2019:3.0 + image: rubydistros/windows-2019:3.1 user: 'NT AUTHORITY\SYSTEM' -- label: run-specs-ruby-3.1-windows +- label: run-specs-ruby-3.4-windows command: - .expeditor/run_windows_tests.ps1 expeditor: @@ -43,5 +43,5 @@ steps: docker: host_os: windows shell: ["powershell", "-Command"] - image: rubydistros/windows-2019:3.1 + image: rubydistros/windows-2019:3.4 user: 'NT AUTHORITY\SYSTEM' From 743ef4f600f858b927eb3d8e5d1f8b4dd277f3f6 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Wed, 14 May 2025 21:27:33 +0000 Subject: [PATCH 03/11] Explicitly adding gems that are moving out of the Ruby System Signed-off-by: John McCrae --- mixlib-authentication.gemspec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index 9009038..2a06d5e 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -14,5 +14,9 @@ Gem::Specification.new do |s| s.files = %w{LICENSE} + Dir.glob("lib/**/*") s.require_paths = ["lib"] + s.add_dependency "logger" + s.add_dependency "ostruct" + s.add_dependency "fiddle" + s.add_dependency "base64" s.add_development_dependency "cookstyle", "~> 8.1" end From ada0038ac55ef21c3e532f6381aa7f8938c1180f Mon Sep 17 00:00:00 2001 From: John McCrae Date: Thu, 15 May 2025 13:20:43 +0000 Subject: [PATCH 04/11] Explicitly adding gems that are moving out of the Ruby System Signed-off-by: John McCrae --- mixlib-authentication.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index 2a06d5e..216a972 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.files = %w{LICENSE} + Dir.glob("lib/**/*") s.require_paths = ["lib"] - s.add_dependency "logger" + s.add_dependency "logger" # logger, ostruct, fiddle, and base64 are part of the stdlib and are being removed in ruby 3.5 so they must be included in the gemspec s.add_dependency "ostruct" s.add_dependency "fiddle" s.add_dependency "base64" From f8f4c8340c12f0fcdf055bf75527b24c2568198c Mon Sep 17 00:00:00 2001 From: John McCrae Date: Thu, 15 May 2025 13:57:21 +0000 Subject: [PATCH 05/11] Explicitly adding gems that are moving out of the Ruby System Signed-off-by: John McCrae --- mixlib-authentication.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index 216a972..ca6896b 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.files = %w{LICENSE} + Dir.glob("lib/**/*") s.require_paths = ["lib"] - s.add_dependency "logger" # logger, ostruct, fiddle, and base64 are part of the stdlib and are being removed in ruby 3.5 so they must be included in the gemspec + s.add_dependency "logger" # logger, ostruct, fiddle, and base64 are part of the stdlib and are being removed in ruby 3.5 so they must be included in the gemspec s.add_dependency "ostruct" s.add_dependency "fiddle" s.add_dependency "base64" From 757fe2994f8909e72161010842664e5e1c538b51 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Thu, 15 May 2025 19:07:18 +0000 Subject: [PATCH 06/11] making the Ruby versions match gemspec Signed-off-by: John McCrae --- .rubocop.yml | 2 +- mixlib-authentication.gemspec | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) 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/**/*" diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index ca6896b..6f01e5a 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -14,7 +14,9 @@ Gem::Specification.new do |s| s.files = %w{LICENSE} + Dir.glob("lib/**/*") s.require_paths = ["lib"] - s.add_dependency "logger" # logger, ostruct, fiddle, and base64 are part of the stdlib and are being removed in ruby 3.5 so they must be included in the gemspec + # logger, ostruct, fiddle, and base64 are part of the stdlib + # and are being removed in ruby 3.5 so they must be included in the gemspec + s.add_dependency "logger" s.add_dependency "ostruct" s.add_dependency "fiddle" s.add_dependency "base64" From d95d722e108504e1cfde0bebfe0c8e663750edae Mon Sep 17 00:00:00 2001 From: John McCrae Date: Fri, 16 May 2025 20:47:17 +0000 Subject: [PATCH 07/11] making the Ruby versions match gemspec Signed-off-by: John McCrae --- mixlib-authentication.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index 6f01e5a..0c0f052 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| # and are being removed in ruby 3.5 so they must be included in the gemspec s.add_dependency "logger" s.add_dependency "ostruct" - s.add_dependency "fiddle" + s.add_dependency "fiddle", "~> 1.1.6" s.add_dependency "base64" s.add_development_dependency "cookstyle", "~> 8.1" end From 11d52a2c0172038e575641e9c5eb1be36a32df95 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Mon, 19 May 2025 19:12:20 +0000 Subject: [PATCH 08/11] Where are GCC and Make? Signed-off-by: John McCrae --- .expeditor/run_windows_tests.ps1 | 8 ++++++++ mixlib-authentication.gemspec | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.expeditor/run_windows_tests.ps1 b/.expeditor/run_windows_tests.ps1 index c37728b..372877f 100644 --- a/.expeditor/run_windows_tests.ps1 +++ b/.expeditor/run_windows_tests.ps1 @@ -2,6 +2,14 @@ $ErrorActionPreference = "Stop" # This will run ruby test on windows platform +Write-Output "--- Ensuring GCC and Make are in the path" +$gccs = gci -path c:\opscode gcc.exe -Recurse -ErrorAction SilentlyContinue +$env:path = "$($gccs[0].DirectoryName)" + ";" + $env:path + +$makes = gci -Path c:\opscode make.exe -Recurse -ErrorAction SilentlyContinue +$env:path = "$($makes[0].DirectoryName)" + ";" + $env:path + + Write-Output "--- Bundle install" bundle config --local path vendor/bundle diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index 0c0f052..9b74842 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| # and are being removed in ruby 3.5 so they must be included in the gemspec s.add_dependency "logger" s.add_dependency "ostruct" - s.add_dependency "fiddle", "~> 1.1.6" + s.add_dependency "fiddle", "~> 1.1.8" s.add_dependency "base64" s.add_development_dependency "cookstyle", "~> 8.1" end From 97e79ddc319acb1c4c063cfd07335c4c94aeb009 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Tue, 20 May 2025 14:03:49 +0000 Subject: [PATCH 09/11] where the heck is gcc? Signed-off-by: John McCrae --- .expeditor/run_windows_tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.expeditor/run_windows_tests.ps1 b/.expeditor/run_windows_tests.ps1 index 372877f..5c7fdea 100644 --- a/.expeditor/run_windows_tests.ps1 +++ b/.expeditor/run_windows_tests.ps1 @@ -3,10 +3,10 @@ $ErrorActionPreference = "Stop" # This will run ruby test on windows platform Write-Output "--- Ensuring GCC and Make are in the path" -$gccs = gci -path c:\opscode gcc.exe -Recurse -ErrorAction SilentlyContinue +$gccs = gci -path c:\ gcc.exe -Recurse -ErrorAction SilentlyContinue $env:path = "$($gccs[0].DirectoryName)" + ";" + $env:path -$makes = gci -Path c:\opscode make.exe -Recurse -ErrorAction SilentlyContinue +$makes = gci -Path c:\ make.exe -Recurse -ErrorAction SilentlyContinue $env:path = "$($makes[0].DirectoryName)" + ";" + $env:path From d1a328872a6e57a01576c45f2f4d6fdd37c5a934 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Tue, 27 May 2025 18:52:46 +0000 Subject: [PATCH 10/11] tweaking the fiddle gem dependency Signed-off-by: John McCrae --- mixlib-authentication.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index 9b74842..41d063a 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| # and are being removed in ruby 3.5 so they must be included in the gemspec s.add_dependency "logger" s.add_dependency "ostruct" - s.add_dependency "fiddle", "~> 1.1.8" + s.add_dependency "fiddle", "~> 1.1" s.add_dependency "base64" s.add_development_dependency "cookstyle", "~> 8.1" end From bdb65d1130b1f15887528b536803c5a97f555621 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Fri, 6 Jun 2025 18:59:17 +0000 Subject: [PATCH 11/11] Pinning fiddle to 1.1.6 Signed-off-by: John McCrae --- mixlib-authentication.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mixlib-authentication.gemspec b/mixlib-authentication.gemspec index 41d063a..0c0f052 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| # and are being removed in ruby 3.5 so they must be included in the gemspec s.add_dependency "logger" s.add_dependency "ostruct" - s.add_dependency "fiddle", "~> 1.1" + s.add_dependency "fiddle", "~> 1.1.6" s.add_dependency "base64" s.add_development_dependency "cookstyle", "~> 8.1" end