Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

add rubocop to CI / bump min ruby to 2.5 #33

Merged
merged 7 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
fail-fast: false
matrix:
include:
- ruby: "2.4"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a major change. 2.5 is eol since 2022-03-31 as well. the question is if we want to drop it as well. thats the version that puppet 6 ships. maybe keeping it untill end of 2022 is okay.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably adopt a voxpupuli wide policy on when to drop ruby 2.5 (and 2.6). Normally I would say it should be dropped as soon as it is EOL but it sounds like puppet 6 will be supported until Feb of 2023: https://puppet.com/docs/puppet/7/platform_lifecycle.html

I am in favor of dropping support for 2.6 on 2022-03-31 or even now since there is no major puppet version tied to it.

- ruby: "2.5"
- ruby: "2.6"
- ruby: "2.7"
Expand All @@ -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
13 changes: 11 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require: rubocop-rspec
---
require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.1
NewCops: enable
TargetRubyVersion: 2.5

Bundler/OrderedGems:
Enabled: false
Expand Down Expand Up @@ -44,3 +47,9 @@ Metrics/MethodLength:

Metrics/ModuleLength:
Enabled: false

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
Expand All @@ -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
Expand Down
19 changes: 12 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
]
7 changes: 5 additions & 2 deletions beaker-module_install_helper.gemspec
Original file line number Diff line number Diff line change
@@ -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|
Expand Down Expand Up @@ -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
18 changes: 12 additions & 6 deletions lib/beaker/module_install_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'beaker'
require 'beaker-puppet'

Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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?

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require 'simplecov'
require 'simplecov-console'
Expand Down
14 changes: 8 additions & 6 deletions spec/unit/beaker/module_install_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe Beaker::ModuleInstallHelper do
Expand All @@ -6,7 +8,7 @@
let(:hosts) do
[
{ 'roles' => %w[master database dashboard classifier] },
{ 'roles' => ['agent'] }
{ 'roles' => ['agent'] },
]
end

Expand Down Expand Up @@ -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

Expand All @@ -175,15 +177,15 @@
'name' => 'puppetlabs-vcsrepo',
'dependencies' => [
{ 'name' => 'puppetlabs/stdlib' },
{ 'name' => 'puppetlabs/concat' }
{ 'name' => 'puppetlabs/concat' },
]
}
end

let(:desired) do
[
{ module_name: 'puppetlabs-stdlib' },
{ module_name: 'puppetlabs-concat' }
{ module_name: 'puppetlabs-concat' },
]
end

Expand Down Expand Up @@ -298,7 +300,7 @@
{
'name' => 'puppetlabs/stdlib',
'version_requirement' => '>= 4.13.1 <= 4.14.0'
}
},
]
}
end
Expand All @@ -319,7 +321,7 @@
'name' => 'puppetlabs-vcsrepo',
'dependencies' => [
{ 'name' => 'puppetlabs/stdlib' },
{ 'name' => 'puppetlabs/concat' }
{ 'name' => 'puppetlabs/concat' },
]
}
end
Expand Down