From 273d4b02ef0aab176c754d674926d5eaaf5b0b32 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 26 Oct 2023 16:20:44 +0100 Subject: [PATCH 1/5] (bug) - Fix ruby 3.x incompatibility It was noted that this gem was failing spec tests when running on ruby 3.x and above. The root cause of this issue seemed to be the absolute_path property found on the Thread::Backtrace::Location class. Updating this to path allows spec tests to pass on both ruby 2.x and 3.x. Can confirm that when consumed by other tools, this also works as expected. Open to suggested changes and improvements. --- lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb | 2 +- lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb b/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb index 56480ed..ebd8934 100644 --- a/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb +++ b/lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb @@ -21,7 +21,7 @@ def self.parse(puppetfile_contents) rescue StandardError, LoadError => e # Find the originating error from within the puppetfile loc = e.backtrace_locations - .select { |item| item.absolute_path == PUPPETFILE_MONIKER } + .select { |item| item.path == PUPPETFILE_MONIKER } .first start_line_number = loc.nil? ? 0 : loc.lineno - 1 # Line numbers from ruby are base 1 end_line_number = loc.nil? ? puppetfile_contents.lines.count - 1 : loc.lineno - 1 # Line numbers from ruby are base 1 diff --git a/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb b/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb index 3f3d6e3..576df41 100644 --- a/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb +++ b/lib/puppetfile-resolver/puppetfile/parser/r10k_eval/dsl.rb @@ -41,7 +41,7 @@ def method_missing(method_name, *_args) # rubocop:disable Style/MethodMissingSup def find_load_line_number loc = Kernel.caller_locations - .find { |call_loc| call_loc.absolute_path == ::PuppetfileResolver::Puppetfile::Parser::R10KEval::PUPPETFILE_MONIKER } + .find { |call_loc| call_loc.path == ::PuppetfileResolver::Puppetfile::Parser::R10KEval::PUPPETFILE_MONIKER } loc.nil? ? 0 : loc.lineno - 1 # Line numbers from ruby are base 1 end end From 4cd4e76e87413858bba31fcc10249cdd1757bfe7 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Fri, 27 Oct 2023 08:27:10 +0100 Subject: [PATCH 2/5] (maint) - add nightly & ci.yml --- .github/workflows/ci.yml | 55 +++++++++++++---------------------- .github/workflows/nightly.yml | 30 +++++++++++++++++++ 2 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/nightly.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 028abc5..8c23a50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,44 +1,31 @@ -name: CI for Puppetfile Resolver +name: "ci" on: - push: - branches: - - main pull_request: branches: - - main + - "main" + workflow_dispatch: jobs: - build: - name: CI Tasks + spec: strategy: fail-fast: false matrix: - ruby: [2.7] - check: [rspec] - os: [ubuntu-latest, windows-latest] + ruby_version: + - '2.7' + - '3.2' include: - # Run linting - - ruby: 2.7 - os: ubuntu-latest - check: rubocop - # Test on the oldest ruby we support - - ruby: 2.5 - os: ubuntu-latest - check: rspec - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Output Ruby Information - run: | - echo "Ruby version" - ruby --version - echo "gem version" - gem --version - echo "bundler version" - bundle -v - - run: bundle exec ${{ matrix.check }} + - ruby_version: '2.7' + puppet_version: '~> 7.0' + - ruby_version: '3.2' + puppet_version: '~> 8.0' + runs-on: + - ubuntu-latest + - windows-latest + name: "spec (ruby ${{ matrix.ruby_version }} | puppet ${{ matrix.puppet_version }} - ${{ matrix.runs-on }})" + uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" + secrets: "inherit" + with: + ruby_version: ${{ matrix.ruby_version }} + puppet_gem_version: ${{ matrix.puppet_version }} + runs_on: ${{ matrix.runs-on }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..4f02189 --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,30 @@ +name: "nightly" + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + spec: + strategy: + fail-fast: false + matrix: + ruby_version: + - '2.7' + - '3.2' + include: + - ruby_version: '2.7' + puppet_version: '~> 7.0' + - ruby_version: '3.2' + puppet_version: '~> 8.0' + runs-on: + - ubuntu-latest + - windows-latest + name: "spec (ruby ${{ matrix.ruby_version }} | puppet ${{ matrix.puppet_version }} - ${{ matrix.runs-on }})" + uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main" + secrets: "inherit" + with: + ruby_version: ${{ matrix.ruby_version }} + puppet_gem_version: ${{ matrix.puppet_version }} + runs_on: ${{ matrix.runs-on }} From 8477be8f1b1e24fda84e84888a86dc493bf51f47 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Fri, 27 Oct 2023 08:37:19 +0100 Subject: [PATCH 3/5] (maint) - Update gems to DevX guidelines --- Gemfile | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/Gemfile b/Gemfile index b7a1226..670d1fe 100644 --- a/Gemfile +++ b/Gemfile @@ -1,33 +1,22 @@ -source ENV['GEM_SOURCE'] || 'https://rubygems.org' +source 'https://rubygems.org' -# Specify your gem's dependencies in pdk.gemspec gemspec -group :development do - gem 'rspec', '>= 3.2', :require => false - gem 'pry' - if RUBY_VERSION =~ /^2\.1\./ - gem "rubocop", "<= 0.57.2", :require => false, :platforms => [:ruby, :x64_mingw] - gem 'rake', '~> 12.3', :require => false - else - gem "rubocop", "~> 0.80", :require => false, :platforms => [:ruby, :x64_mingw] - gem 'rake', '>= 10.4', :require => false - end +group :test do + gem 'rake' + gem 'rspec', '~> 3.1' + gem 'rspec-collection_matchers', '~> 1.0' + gem 'rspec-its', '~> 1.0' - gem "yard", :require => false - gem 'redcarpet', :require => false - gem 'github-markup', :require => false -end + gem 'rubocop', '~> 1.48.1' + gem 'rubocop-rspec', '~> 2.19' + gem 'rubocop-performance', '~> 1.16' -# Evaluate Gemfile.local and ~/.gemfile if they exist -extra_gemfiles = [ - "#{__FILE__}.local", - File.join(Dir.home, '.gemfile'), -] + gem 'codecov' + gem 'simplecov' +end -extra_gemfiles.each do |gemfile| - if File.file?(gemfile) && File.readable?(gemfile) - eval(File.read(gemfile), binding) - end +group :development do + gem 'pry' + gem 'yard' end -# vim: syntax=ruby From 303293a235252c17e1990850739935972096e408 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Fri, 27 Oct 2023 08:37:37 +0100 Subject: [PATCH 4/5] (maint) - regen rubocop_todo --- .rubocop_todo.yml | 97 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 92fb0d5..d737759 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,15 +1,82 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2019-11-04 20:38:19 +0800 using RuboCop version 0.76.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 2 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. -# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS -Naming/FileName: - Exclude: - - 'lib/puppetfile-resolver.rb' - - 'puppetfile-cli.rb' +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-10-27 07:36:27 UTC using RuboCop version 1.48.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/DuplicateRequire: + Exclude: + - 'lib/puppetfile-resolver/spec_searchers/git/gclone.rb' + +# Offense count: 1 +Lint/MissingSuper: + Exclude: + - 'lib/puppetfile-resolver/puppetfile/parser/errors.rb' + +# Offense count: 2 +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# CheckDefinitionPathHierarchyRoots: lib, spec, test, src +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'lib/puppetfile-resolver.rb' + - 'puppetfile-cli.rb' + +# Offense count: 27 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: separated, grouped +Style/AccessorGrouping: + Exclude: + - 'lib/puppetfile-resolver/models/module_dependency.rb' + - 'lib/puppetfile-resolver/models/module_specification.rb' + - 'lib/puppetfile-resolver/puppetfile/document.rb' + - 'lib/puppetfile-resolver/puppetfile/git_module.rb' + - 'lib/puppetfile-resolver/puppetfile/validation_errors.rb' + - 'lib/puppetfile-resolver/resolver.rb' + - 'lib/puppetfile-resolver/spec_searchers/configuration.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedMethods, AllowedPatterns. +# AllowedMethods: ==, equal?, eql? +Style/ClassEqualityComparison: + Exclude: + - 'lib/puppetfile-resolver/util.rb' + +# Offense count: 1 +Style/CombinableLoops: + Exclude: + - 'lib/puppetfile-resolver/puppetfile/document.rb' + +# Offense count: 1 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'lib/puppetfile-resolver/cache/base.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantAssignment: + Exclude: + - 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval/module/local.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantRegexpEscape: + Exclude: + - 'lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb' + +# Offense count: 7 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/puppetfile-resolver/cache/persistent.rb' + - 'lib/puppetfile-resolver/spec_searchers/git/github.rb' + - 'lib/puppetfile-resolver/spec_searchers/git/gitlab.rb' From f717ce2a122aca792afbe7ef68c06f3cef000ffe Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Fri, 27 Oct 2023 09:01:51 +0100 Subject: [PATCH 5/5] (maint) - Add webrick gem The webrick gem is no longer shipped as part of the ruby stdlib as of 3.x. Add a development requirement to the .gemspec, as we use this gem for testing. --- puppetfile-resolver.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/puppetfile-resolver.gemspec b/puppetfile-resolver.gemspec index e411eab..b85e2ad 100644 --- a/puppetfile-resolver.gemspec +++ b/puppetfile-resolver.gemspec @@ -20,4 +20,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'molinillo', '~> 0.6' spec.add_runtime_dependency 'semantic_puppet', '~> 1.0' + + spec.add_development_dependency 'webrick', '~> 1.8' end