diff --git a/.expeditor/run_windows_tests.ps1 b/.expeditor/run_windows_tests.ps1 index c37728b..5c7fdea 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:\ 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 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' 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..a1a0195 --- /dev/null +++ b/.rubocop.yml @@ -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/**/*' 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..0c0f052 100644 --- a/mixlib-authentication.gemspec +++ b/mixlib-authentication.gemspec @@ -10,8 +10,15 @@ 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"] + # 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