Skip to content

Commit

Permalink
enable newcops and remove cops not explicitly installed
Browse files Browse the repository at this point in the history
removed cops are provided by gems not explicitly installed
they seem to be installed using the setup ruby action, but not
when testing in a ruby docker image

either way, they are covered by enabling newcops

fix rubocop namespaces

bump rubocop target ruby version

fix tests that depend on docker command existing

discovered when running test suite with ruby:3.2 image on docker

(maint) Rubocop 1.65.1 Autocorrect fixes
  • Loading branch information
h0tw1r3 authored and cthorn42 committed Aug 29, 2024
1 parent 2cfb1a8 commit 368dcd7
Show file tree
Hide file tree
Showing 30 changed files with 85 additions and 129 deletions.
50 changes: 6 additions & 44 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,15 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.7
NewCops: enable
Exclude:
- "**/*.erb"
- spec/**/*
- vendor/**/*
- examples/**/*
- lib/vanagon/platform/defaults/*

Capybara/MatchStyle:
Enabled: true

Capybara/NegationMatcher:
Enabled: true

Capybara/SpecificActions:
Enabled: true

Capybara/SpecificFinders:
Enabled: true

Capybara/SpecificMatcher:
Enabled: true

Gemspec/DeprecatedAttributeAssignment:
Enabled: true

Expand Down Expand Up @@ -395,15 +381,6 @@ RSpec/DuplicatedMetadata:
RSpec/ExcessiveDocstringSpacing:
Enabled: true

RSpec/FactoryBot/ConsistentParenthesesStyle:
Enabled: true

RSpec/FactoryBot/FactoryNameStyle:
Enabled: true

RSpec/FactoryBot/SyntaxMethods:
Enabled: true

RSpec/IdenticalEqualityAssertion:
Enabled: true

Expand All @@ -416,21 +393,6 @@ RSpec/NoExpectationExample:
RSpec/PendingWithoutReason:
Enabled: true

RSpec/Rails/AvoidSetupHook:
Enabled: true

RSpec/Rails/HaveHttpStatus:
Enabled: true

RSpec/Rails/InferredSpecType:
Enabled: true

RSpec/Rails/MinitestAssertions:
Enabled: true

RSpec/Rails/TravelAround:
Enabled: true

RSpec/RedundantAround:
Enabled: true

Expand All @@ -446,16 +408,16 @@ RSpec/SubjectDeclaration:
RSpec/VerifiedDoubleReference:
Enabled: true

Rspec/BeforeAfterAll:
RSpec/BeforeAfterAll:
Enabled: false

Rspec/ExampleLength:
RSpec/ExampleLength:
Enabled: false

Rspec/HookArgument:
RSpec/HookArgument:
Enabled: false

Rspec/MultipleMemoizedHelpers:
RSpec/MultipleMemoizedHelpers:
Enabled: false

Security/CompoundHash:
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org).

This changelog adheres to [Keep a CHANGELOG](https://keepachangelog.com).

### Changed
## [Unreleased]
- Bump minimum ruby requirement to 2.7

### Added
- Add DigiCertGlobalRootG2 cert as part of Solaris default
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/cli/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def options_translate(docopt_options)
'<platforms>' => :platforms,
'<targets>' => :targets
}
return docopt_options.map { |k, v| [translations[k], v] }.to_h
return docopt_options.transform_keys { |k| translations[k] }
end

def options_validate(options)
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/cli/build_host_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def options_translate(docopt_options)
'<platforms>' => :platforms,
'<targets>' => :targets
}
return docopt_options.map { |k, v| [translations[k], v] }.to_h
return docopt_options.transform_keys { |k| translations[k] }
end
end
end
Expand Down
7 changes: 3 additions & 4 deletions lib/vanagon/cli/build_requirements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def run(options) # rubocop:disable Metrics/AbcSize

components = driver.project.components
component_names = components.map(&:name)
build_requirements = []
components.each do |component|
build_requirements << component.build_requires.reject do |requirement|
build_requirements = components.map do |component|
component.build_requires.reject do |requirement|
# only include external requirements: i.e. those that do not match
# other components in the project
component_names.include?(requirement)
Expand All @@ -61,7 +60,7 @@ def options_translate(docopt_options)
'<project-name>' => :project_name,
'<platform>' => :platform,
}
return docopt_options.map { |k, v| [translations[k], v] }.to_h
return docopt_options.transform_keys { |k| translations[k] }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/cli/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def options_translate(docopt_options)
translations = {
'--shell' => :shell,
}
return docopt_options.map { |k, v| [translations[k], v] }.to_h
return docopt_options.transform_keys { |k| translations[k] }
end
end
end
Expand Down
12 changes: 5 additions & 7 deletions lib/vanagon/cli/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ def run(options)

projects.each do |project|
platforms.each do |platform|
begin
artifact = Vanagon::Driver.new(platform, project, options)
artifact.dependencies
rescue RuntimeError => e
failures.push("#{project}, #{platform}: #{e}")
end
artifact = Vanagon::Driver.new(platform, project, options)
artifact.dependencies
rescue RuntimeError => e
failures.push("#{project}, #{platform}: #{e}")
end
end

Expand Down Expand Up @@ -92,7 +90,7 @@ def options_translate(docopt_options)
'<project-name>' => :project_name,
'<platforms>' => :platforms
}
return docopt_options.map { |k, v| [translations[k], v] }.to_h
return docopt_options.transform_keys { |k| translations[k] }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/cli/inspect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def options_translate(docopt_options)
'<project-name>' => :project_name,
'<platforms>' => :platforms
}
return docopt_options.map { |k, v| [translations[k], v] }.to_h
return docopt_options.transform_keys { |k| translations[k] }
end

def options_validate(options)
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/cli/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def options_translate(docopt_options)
'--projects' => :projects,
'--use-spaces' => :use_spaces,
}
return docopt_options.map { |k, v| [translations[k], v] }.to_h
return docopt_options.transform_keys { |k| translations[k] }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/cli/render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def options_translate(docopt_options)
'<project-name>' => :project_name,
'<platforms>' => :platforms,
}
return docopt_options.map { |k, v| [translations[k], v] }.to_h
return docopt_options.transform_keys { |k| translations[k] }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/cli/ship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def parse(argv)
def run(_)
ENV['PROJECT_ROOT'] = Dir.pwd

if Dir['output/**/*'].select { |entry| File.file?(entry) }.empty?
if Dir['output/**/*'].none? { |entry| File.file?(entry) }
VanagonLogger.error 'vanagon: Error: No packages to ship in the "output" directory. Maybe build some first?'
exit 1
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/cli/sign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def parse(argv)

def run(_)
ENV['PROJECT_ROOT'] = Dir.pwd
if Dir['output/**/*'].select { |entry| File.file?(entry) }.empty?
if Dir['output/**/*'].none? { |entry| File.file?(entry) }
VanagonLogger.error 'sign: Error: No packages to sign in the "output" directory. Maybe build some first?'
exit 1
end
Expand Down
8 changes: 4 additions & 4 deletions lib/vanagon/common/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def initialize(name, group = nil, shell = nil, is_system = false, homedir = nil)
#
# @return [true, false] true if all attributes have equal values. false otherwise.
def ==(other)
other.name == self.name && \
other.group == self.group && \
other.shell == self.shell && \
other.is_system == self.is_system && \
other.name == self.name &&
other.group == self.group &&
other.shell == self.shell &&
other.is_system == self.is_system &&
other.homedir == self.homedir
end
end
Expand Down
40 changes: 19 additions & 21 deletions lib/vanagon/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,27 +260,25 @@ def mirrors # rubocop:disable Lint/DuplicateMethods
# if #fetch is successful.
def fetch_mirrors(options)
mirrors.to_a.shuffle.each do |mirror|
begin
VanagonLogger.info %(Attempting to fetch from mirror URL "#{mirror}")
@source = Vanagon::Component::Source.source(mirror, **options)
return true if source.fetch
rescue Vanagon::InvalidSource
# This means that the URL was not a git repo or a valid downloadable file,
# which means either the URL is incorrect, or we don't have access to that
# resource. Return false, so that the pkg.url value can be used instead.
VanagonLogger.error %(Invalid source "#{mirror}")
rescue SocketError
# SocketError means that there was no DNS/name resolution
# for whatever remote protocol the mirror tried to use.
VanagonLogger.error %(Unable to resolve mirror URL "#{mirror}")
rescue StandardError
# Source retrieval does not consistently return a meaningful
# namespaced error message, which means we're brute-force rescuing
# StandardError. Also, we want to handle other unexpected things when
# we try reaching out to the URL, so that we can gracefully return
# false and fall back to fetching the pkg.url value instead.
VanagonLogger.error %(Unable to retrieve mirror URL "#{mirror}")
end
VanagonLogger.info %(Attempting to fetch from mirror URL "#{mirror}")
@source = Vanagon::Component::Source.source(mirror, **options)
return true if source.fetch
rescue Vanagon::InvalidSource
# This means that the URL was not a git repo or a valid downloadable file,
# which means either the URL is incorrect, or we don't have access to that
# resource. Return false, so that the pkg.url value can be used instead.
VanagonLogger.error %(Invalid source "#{mirror}")
rescue SocketError
# SocketError means that there was no DNS/name resolution
# for whatever remote protocol the mirror tried to use.
VanagonLogger.error %(Unable to resolve mirror URL "#{mirror}")
rescue StandardError
# Source retrieval does not consistently return a meaningful
# namespaced error message, which means we're brute-force rescuing
# StandardError. Also, we want to handle other unexpected things when
# we try reaching out to the URL, so that we can gracefully return
# false and fall back to fetching the pkg.url value instead.
VanagonLogger.error %(Unable to retrieve mirror URL "#{mirror}")
end
false
end
Expand Down
10 changes: 4 additions & 6 deletions lib/vanagon/engine/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,10 @@ def docker_cp_globs_from(globs, host_path)
# @return [void]
def wait_for_ssh
Vanagon::Utilities.retry_with_timeout(5, 5) do
begin
Vanagon::Utilities.remote_ssh_command("#{@target_user}@#{@target}", 'exit', @target_port)
rescue StandardError => e
sleep(1) # Give SSHD some time to start.
raise e
end
Vanagon::Utilities.remote_ssh_command("#{@target_user}@#{@target}", 'exit', @target_port)
rescue StandardError => e
sleep(1) # Give SSHD some time to start.
raise e
end
rescue StandardError => e
raise Vanagon::Error.wrap(e, "SSH was not up in the container after 5 seconds.")
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.error(msg)
end

def initialize(output = $stdout)
super(output)
super
self.level = ::Logger::INFO
self.formatter = proc do |severity, datetime, progname, msg|
"#{msg}\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/platform/deb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def initialize(name)
@num_cores = "/usr/bin/nproc"
@curl = "curl --silent --show-error --fail --location"
@valid_operators = ['<', '>', '<=', '>=', '=', '<<', '>>']
super(name)
super
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/vanagon/platform/defaults/solaris-11-i386.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Serial #: 03:3A:F1:E6:A7:11:A9:A0:BB:28:64:B1:1D:09:FA:E5
# SHA256 Fingerprint: CB:3C:CB:B7:60:31:E5:E0:13:8F:8D:D3:9A:23:F9:DE:47:FF:C3:5E:43:C1:14:4C:EA:27:D4:6A:5A:B1:CB:5F
# https://perforce.atlassian.net/browse/RE-16540 for long term fix for this
# Required by Vanagon while on Solaris 11.1 (solaris-11-x86_64 in our local vmpooler)
DigiCertGlobalRootG2 = <<-STRING
-----BEGIN CERTIFICATE-----
MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh
Expand Down Expand Up @@ -32,7 +33,7 @@
plat.servicedir "/lib/svc/manifest"
plat.defaultdir "/lib/svc/method"
plat.servicetype "smf"

plat.vmpooler_template "solaris-11-x86_64"
plat.provision_with "echo '#{DigiCertGlobalRootG2}'> /etc/openssl/certs/DigiCertGlobalRootG2.pem"
plat.provision_with 'chmod a+r /etc/openssl/certs/DigiCertGlobalRootG2.pem'
Expand Down
6 changes: 3 additions & 3 deletions lib/vanagon/platform/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def servicedir(dir)
@platform.servicedir = dir

# Add to the servicetypes array if we haven't already
if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty?
if @platform.servicetype && @platform.servicedir && @platform.servicetypes.none? { |s| s.servicetype == @platform.servicetype }
@platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir)
end
end
Expand All @@ -263,15 +263,15 @@ def defaultdir(dir)
#
# @param type [String] service type for the platform ('sysv' for example)
# @param servicedir [String] service dir for this platform and service type ('/etc/init.d' for example). Optional.
def servicetype(type, servicedir: nil) # rubocop:disable Metrics/AbcSize
def servicetype(type, servicedir: nil)
if servicedir
@platform.servicetypes << OpenStruct.new(:servicetype => type, :servicedir => servicedir)
else
@platform.servicetype = type
end

# Add to the servicetypes array if we haven't already
if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty?
if @platform.servicetype && @platform.servicedir && @platform.servicetypes.none? { |s| s.servicetype == @platform.servicetype }
@platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/platform/osx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def initialize(name)
@num_cores = "/usr/sbin/sysctl -n hw.physicalcpu"
@mktemp = "mktemp -d -t 'tmp'"
@brew = '/usr/local/bin/brew'
super(name)
super
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/platform/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def initialize(name)
@num_cores ||= "/bin/grep -c 'processor' /proc/cpuinfo"
@rpmbuild ||= "/usr/bin/rpmbuild"
@curl = "curl --silent --show-error --fail --location"
super(name)
super
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vanagon/platform/rpm/aix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(name)
@num_cores = "lsdev -Cc processor |wc -l"
@install = "/opt/freeware/bin/install"
@rpmbuild = "/usr/bin/rpm"
super(name)
super
end
end
end
Expand Down
Loading

0 comments on commit 368dcd7

Please sign in to comment.