Skip to content

Updating for Ruby 3.4 and Cookstyle #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 6, 2025
Merged
8 changes: 8 additions & 0 deletions .expeditor/run_windows_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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:\ gcc.exe -Recurse -ErrorAction SilentlyContinue
$env:path = "$($gccs[0].DirectoryName)" + ";" + $env:path

$makes = gci -Path c:\ make.exe -Recurse -ErrorAction SilentlyContinue
$env:path = "$($makes[0].DirectoryName)" + ";" + $env:path


Write-Output "--- Bundle install"

bundle config --local path vendor/bundle
Expand Down
16 changes: 8 additions & 8 deletions .expeditor/verify.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@ 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:
executor:
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:
executor:
docker:
host_os: windows
shell: ["powershell", "-Command"]
image: rubydistros/windows-2019:3.1
image: rubydistros/windows-2019:3.4
user: 'NT AUTHORITY\SYSTEM'
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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

31 changes: 31 additions & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
AllCops:
TargetRubyVersion: 3.1
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/**/*'
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 11 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion mixlib-authentication.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ Gem::Specification.new do |s|
s.author = "Chef Software, Inc."
s.email = "[email protected]"
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"]
# 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", "~> 1.1.6"
s.add_dependency "base64"
s.add_development_dependency "cookstyle", "~> 8.1"
end
Loading