From 87d5f8be0f3e224adde9fe90b7b9227f541f6d77 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Sat, 23 Mar 2024 21:08:25 +0100 Subject: [PATCH] Add Ruby 3.3 support --- .github/dependabot.yml | 17 -------- .github/workflows/release.yml | 4 +- .github/workflows/test.yml | 3 +- .rubocop.yml | 7 +++- Gemfile | 10 ++++- Rakefile | 2 - spec/spec_helper.rb | 77 ++++++++++------------------------- 7 files changed, 39 insertions(+), 81 deletions(-) delete mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 489b5cb..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: 2 -updates: -# raise PRs for gem updates -- package-ecosystem: bundler - directory: "/" - schedule: - interval: daily - time: "13:00" - open-pull-requests-limit: 10 - -# Maintain dependencies for GitHub Actions -- package-ecosystem: github-actions - directory: "/" - schedule: - interval: daily - time: "13:00" - open-pull-requests-limit: 10 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5babc31..7dce0f5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,10 +11,10 @@ jobs: if: github.repository_owner == 'voxpupuli' steps: - uses: actions/checkout@v4 - - name: Install Ruby 3.0 + - name: Install Ruby 3.3 uses: ruby/setup-ruby@v1 with: - ruby-version: '3.0' + ruby-version: '3.3' bundler: 'none' env: BUNDLE_WITHOUT: release:development:rubocop diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73cae83..0dd735e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: - name: Setup ruby uses: ruby/setup-ruby@v1 with: - ruby-version: '3.0' + ruby-version: '3.3' bundler-cache: true - name: Run rake rubocop run: bundle exec rake rubocop @@ -33,6 +33,7 @@ jobs: - ruby: "3.1" coverage: "yes" - ruby: "3.2" + - ruby: "3.3" env: COVERAGE: ${{ matrix.coverage }} name: Ruby ${{ matrix.ruby }} diff --git a/.rubocop.yml b/.rubocop.yml index bc5bb34..636ab39 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,11 @@ --- -inherit_from: .rubocop_todo.yml - # Managed by modulesync - DO NOT EDIT # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ +inherit_from: .rubocop_todo.yml inherit_gem: voxpupuli-rubocop: rubocop.yml + +Naming/FileName: + Exclude: + - "*.gemspec" diff --git a/Gemfile b/Gemfile index 462ca5a..b9ddab0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ -# frozen_string_literal: true - source ENV['GEM_SOURCE'] || 'https://rubygems.org' gemspec @@ -13,3 +11,11 @@ group :coverage, optional: ENV['COVERAGE'] != 'yes' do gem 'codecov', require: false gem 'simplecov-console', require: false end + +group :development do + gem 'rake', '~> 13.0', '>= 13.0.6' + gem 'rspec', '~> 3.12' + gem 'rspec-collection_matchers', '~> 1.2' + gem 'rspec-its', '~> 1.3' + gem 'voxpupuli-rubocop', '~> 2.0' +end diff --git a/Rakefile b/Rakefile index 4cda023..60a342a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6f4af69..2871e8d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,62 +1,29 @@ -require 'puppet-lint' -require 'jgrep' - -PuppetLint::Plugins.load_spec_helper - -class PuppetDB::Client - def puppetdb_to_jgrep(query) - if query[0] == :and || query[0] == :or - "(#{puppetdb_to_jgrep(query[1])} #{query[0]} #{puppetdb_to_jgrep(query[2])})" - else - "#{[query[1]].flatten.join('.')}#{query[0]}#{query[2]}" - end - end - - def process_pql_kv(q) - k, v = q.split(/\s*=\s*/) - ".#{k}=#{v}" - end +# frozen_string_literal: true - def pql_to_jgrep(query) - endpoint_cols = query.split('{').first - endpoint = endpoint_cols.split(/[\s\[]/).first - query.sub!(/^#{Regexp.quote(endpoint_cols)}\{\s*/, '') - query.sub!(/(group\s+by\s+(type|title))/, '') - query.sub!(/\s*}\s*/, '') - query.sub!(/(and\s+)?nodes\s*\{\s*deactivated\s+is\s+null\s*\}/, '') +begin + require 'simplecov' + require 'simplecov-console' + require 'codecov' +rescue LoadError +else + SimpleCov.start do + track_files 'lib/**/*.rb' - return endpoint, '' if query == '' + add_filter '/spec' - query.gsub!('parameters.', 'parameter.') - query.sub!(/\s*=\s*/, '=') + enable_coverage :branch - jgrep_query_and_parts = [] - query.split(/\s+and\s+/).each do |q| - newq = '' - if q.start_with?('(') - newq << '(' - newq << q.split(/\s+or\s+/).map do |qq| - process_pql_kv(qq.sub(/^\(/, '').sub(/\)$/, '')) - end.join(' or ') - newq << ')' - else - newq << process_pql_kv(q) - end - jgrep_query_and_parts << newq - end - jgrep_query = jgrep_query_and_parts.join(' and ') - jgrep_query.rstrip! - - [endpoint, jgrep_query] + # do not track vendored files + add_filter '/vendor' + add_filter '/.vendor' end - def request(endpoint, query, _opts = {}) - if endpoint == '' - endpoint, query = pql_to_jgrep(query) - else - query = puppetdb_to_jgrep(query) - end - ret = JGrep.jgrep(File.read("spec/fixtures/#{endpoint}.json"), query) - PuppetDB::Response.new(ret, ret.size) - end + SimpleCov.formatters = [ + SimpleCov::Formatter::Console, + SimpleCov::Formatter::Codecov, + ] end + +require 'puppet-lint' + +PuppetLint::Plugins.load_spec_helper