diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9223be..c57a91f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,6 @@ jobs: fail-fast: false matrix: include: - - ruby: "2.4" - ruby: "2.5" - ruby: "2.6" - ruby: "2.7" @@ -30,6 +29,6 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: Run tests - run: bundle exec rake spec + run: bundle exec rake - name: Verify gem builds run: bundle exec gem build *.gemspec diff --git a/.rubocop.yml b/.rubocop.yml index 044cbbd..00255d2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,10 @@ -require: rubocop-rspec +--- +require: + - rubocop-rspec AllCops: - TargetRubyVersion: 2.1 + NewCops: enable + TargetRubyVersion: 2.5 Bundler/OrderedGems: Enabled: false @@ -44,3 +47,9 @@ Metrics/MethodLength: Metrics/ModuleLength: Enabled: false + +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma diff --git a/Gemfile b/Gemfile index fe78e19..b634be2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec @@ -16,9 +18,9 @@ group :development do gem 'pry-byebug' end -group :coverage, optional: ENV['COVERAGE']!='yes' do - gem 'simplecov-console', :require => false - gem 'codecov', :require => false +group :coverage, optional: ENV['COVERAGE'] != 'yes' do + gem 'simplecov-console', require: false + gem 'codecov', require: false end group :release do diff --git a/Rakefile b/Rakefile index 9084d44..9c2bb69 100644 --- a/Rakefile +++ b/Rakefile @@ -1,13 +1,9 @@ # frozen_string_literal: true require 'bundler/gem_tasks' -task default: %i[lint spec] - require 'rubocop/rake_task' -desc 'Run rubocop' -RuboCop::RakeTask.new(:lint) do |t| - t.requires << 'rubocop-rspec' -end + +RuboCop::RakeTask.new require 'rspec/core/rake_task' desc 'Run spec tests using rspec' @@ -23,10 +19,19 @@ rescue LoadError # github_changelog_generator isn't available, so we won't define a rake task with it else GitHubChangelogGenerator::RakeTask.new :changelog do |config| - config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file." + config.header = <<-HEADER + # Changelog + + # All notable changes to this project will be documented in this file. + HEADER config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog] config.user = 'voxpupuli' config.project = 'beaker-module_install_helper' config.future_release = Gem::Specification.load("#{config.project}.gemspec").version end end + +task default: %w[ + rubocop + spec +] diff --git a/beaker-module_install_helper.gemspec b/beaker-module_install_helper.gemspec index f6750da..eb6030f 100644 --- a/beaker-module_install_helper.gemspec +++ b/beaker-module_install_helper.gemspec @@ -1,4 +1,6 @@ -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) Gem::Specification.new do |spec| @@ -30,5 +32,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'beaker', '>= 2.0' spec.add_runtime_dependency 'beaker-puppet', '~> 1.0' - spec.required_ruby_version = '>= 2.4.0' + spec.required_ruby_version = '>= 2.5.0' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/lib/beaker/module_install_helper.rb b/lib/beaker/module_install_helper.rb index e5352d4..7757105 100644 --- a/lib/beaker/module_install_helper.rb +++ b/lib/beaker/module_install_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'beaker' require 'beaker-puppet' @@ -33,7 +35,7 @@ def install_module_dependencies(deps = nil) def install_module_dependencies_on(hsts, deps = nil) hsts = [hsts] if hsts.is_a?(Hash) hsts = [hsts] unless hsts.respond_to?(:each) - deps = deps.nil? ? module_dependencies_from_metadata : deps + deps = module_dependencies_from_metadata if deps.nil? fh = ENV['BEAKER_FORGE_HOST'] @@ -111,8 +113,8 @@ def module_version_from_requirement(mod_name, vr_str) # returns an array of Gem::Dependency objects # https://docs.puppet.com/puppet/latest/modules_metadata.html def version_requirements_from_string(vr_str) - ops = vr_str.scan(/[(<|>|=)]{1,2}/i) - vers = vr_str.scan(/[(0-9|\.)]+/i) + ops = vr_str.scan(/[(<|>=)]{1,2}/i) + vers = vr_str.scan(/[(0-9|.)]+/i) raise 'Invalid version requirements' if ops.count != 0 && ops.count != vers.count @@ -143,6 +145,7 @@ def hosts_to_install_module_on def module_name_from_metadata res = get_module_name module_metadata['name'] raise 'Error getting module name' unless res + res[1] end @@ -153,13 +156,14 @@ def module_metadata unless File.exist?(metadata_path) raise "Error loading metadata.json file from #{$module_source_dir}" end + JSON.parse(File.read(metadata_path)) end # Use this property to store the module_source_dir, so we don't traverse # the tree every time def get_module_source_directory(call_stack) - matching_caller = call_stack.select { |i| i =~ /(spec_helper_acceptance|_spec)/i } + matching_caller = call_stack.grep(/(spec_helper_acceptance|_spec)/i) raise 'Error finding module source directory' if matching_caller.empty? @@ -183,7 +187,7 @@ def get_module_source_directory(call_stack) def forge_host fh = ENV['BEAKER_FORGE_HOST'] unless fh.nil? - fh = 'https://' + fh if fh !~ /^(https:\/\/|http:\/\/)/i + fh = "https://#{fh}" if fh !~ /^(https:\/\/|http:\/\/)/i fh += '/' unless fh != /\/$/ return fh end @@ -194,7 +198,7 @@ def forge_host def forge_api fa = ENV['BEAKER_FORGE_API'] unless fa.nil? - fa = 'https://' + fa if fa !~ /^(https:\/\/|http:\/\/)/i + fa = "https://#{fa}" if fa !~ /^(https:\/\/|http:\/\/)/i fa += '/' unless fa != /\/$/ return fa end @@ -203,6 +207,8 @@ def forge_api end end +# rubocop:disable Style/MixinUsage include Beaker::ModuleInstallHelper +# rubocop:enable Style/MixinUsage # Use the caller (requirer) of this file to begin search for module source dir $module_source_dir = get_module_source_directory caller diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5bb7137..66639b5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + begin require 'simplecov' require 'simplecov-console' diff --git a/spec/unit/beaker/module_install_helper_spec.rb b/spec/unit/beaker/module_install_helper_spec.rb index eed2f73..342275e 100644 --- a/spec/unit/beaker/module_install_helper_spec.rb +++ b/spec/unit/beaker/module_install_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Beaker::ModuleInstallHelper do @@ -6,7 +8,7 @@ let(:hosts) do [ { 'roles' => %w[master database dashboard classifier] }, - { 'roles' => ['agent'] } + { 'roles' => ['agent'] }, ] end @@ -159,7 +161,7 @@ let(:desired) do [ { module_name: 'puppetlabs-stdlib', version: '4.14.0' }, - { module_name: 'puppetlabs-concat', version: '2.2.0' } + { module_name: 'puppetlabs-concat', version: '2.2.0' }, ] end @@ -175,7 +177,7 @@ 'name' => 'puppetlabs-vcsrepo', 'dependencies' => [ { 'name' => 'puppetlabs/stdlib' }, - { 'name' => 'puppetlabs/concat' } + { 'name' => 'puppetlabs/concat' }, ] } end @@ -183,7 +185,7 @@ let(:desired) do [ { module_name: 'puppetlabs-stdlib' }, - { module_name: 'puppetlabs-concat' } + { module_name: 'puppetlabs-concat' }, ] end @@ -298,7 +300,7 @@ { 'name' => 'puppetlabs/stdlib', 'version_requirement' => '>= 4.13.1 <= 4.14.0' - } + }, ] } end @@ -319,7 +321,7 @@ 'name' => 'puppetlabs-vcsrepo', 'dependencies' => [ { 'name' => 'puppetlabs/stdlib' }, - { 'name' => 'puppetlabs/concat' } + { 'name' => 'puppetlabs/concat' }, ] } end