From 1dfe4a69e8a9160002909c61739dc47d94ce4157 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 4 Aug 2024 14:52:08 +0000 Subject: [PATCH 1/8] fix tests that depend on docker command existing discovered when running test suite with ruby:3.2 image on docker --- spec/lib/vanagon/engine/docker_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/lib/vanagon/engine/docker_spec.rb b/spec/lib/vanagon/engine/docker_spec.rb index f4df24d3..94c0186b 100644 --- a/spec/lib/vanagon/engine/docker_spec.rb +++ b/spec/lib/vanagon/engine/docker_spec.rb @@ -2,6 +2,10 @@ require 'vanagon/platform' describe Vanagon::Engine::Docker do + before(:each) do + allow(Vanagon::Utilities).to receive(:find_program_on_path).with('docker').and_return('/usr/bin/docker') + end + let (:platform_with_docker_image) do plat = Vanagon::Platform::DSL.new('debian-10-amd64') plat.instance_eval(<<~EOF) @@ -34,6 +38,7 @@ describe '#initialize' do it 'fails without docker installed' do + allow(Vanagon::Utilities).to receive(:find_program_on_path).with('docker').and_call_original ENV['PATH'].split(File::PATH_SEPARATOR).each do |path_elem| expect(FileTest).to receive(:executable?).with(File.join(path_elem, 'docker')).and_return(false) end @@ -44,18 +49,15 @@ describe "#validate_platform" do it 'raises an error if the platform is missing a required attribute' do - expect(Vanagon::Utilities).to receive(:find_program_on_path).with('docker').and_return('/usr/bin/docker') expect { described_class.new(platform_without_docker_image).validate_platform }.to raise_error(Vanagon::Error) end it 'returns true if the platform has the required attributes' do - expect(Vanagon::Utilities).to receive(:find_program_on_path).with('docker').and_return('/usr/bin/docker') expect(described_class.new(platform_with_docker_image).validate_platform).to be(true) end end it 'returns "docker" name' do - expect(Vanagon::Utilities).to receive(:find_program_on_path).with('docker').and_return('/usr/bin/docker') expect(described_class.new(platform_with_docker_image).name).to eq('docker') end From d63be4e67150c1132e422b9eb6f05971f1a03119 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 4 Aug 2024 14:56:29 +0000 Subject: [PATCH 2/8] update actions/checkout to v4 v3 is deprecated and produces a warning message --- .github/workflows/release.yml | 2 +- .github/workflows/ruby.yml | 2 +- .github/workflows/ruby3.yml | 2 +- .github/workflows/security.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 559b6e1a..7afc3b2c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Build gem uses: scarhand/actions-ruby@master with: diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 2a3062a9..599af64c 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby 2.7 uses: ruby/setup-ruby@v1 with: diff --git a/.github/workflows/ruby3.yml b/.github/workflows/ruby3.yml index f8f5d79b..a59f4c9f 100644 --- a/.github/workflows/ruby3.yml +++ b/.github/workflows/ruby3.yml @@ -11,7 +11,7 @@ jobs: ruby: [ '3.0', '3.1', '3.2'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby 3.x uses: ruby/setup-ruby@v1 with: diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index db7d4302..79e81c5d 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout repo content - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 - name: setup ruby From 6f7ef9a235c7896e760a571fb62a0e21b206849c Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 4 Aug 2024 15:32:05 +0000 Subject: [PATCH 3/8] enable newcops and remove cops not explicitly installed 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 --- .rubocop.yml | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5180d598..68524532 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,7 @@ require: AllCops: TargetRubyVersion: 2.3 + NewCops: enable Exclude: - "**/*.erb" - spec/**/* @@ -13,21 +14,6 @@ AllCops: - 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 @@ -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 @@ -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 From 7202efa17b0e53cf79c501a0b49a1aa0642c0ec9 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 4 Aug 2024 15:32:50 +0000 Subject: [PATCH 4/8] fix rubocop namespaces --- .rubocop.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 68524532..88070f5a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -408,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: From 0746b3c888e42d424dac880bfa5ccdb593d277f5 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 4 Aug 2024 15:33:35 +0000 Subject: [PATCH 5/8] bump rubocop target ruby version --- .rubocop.yml | 2 +- CHANGELOG.md | 1 + vanagon.gemspec | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 88070f5a..998a2a8e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ require: - rubocop-rspec AllCops: - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.7 NewCops: enable Exclude: - "**/*.erb" diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cfeafe5..375c280d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org). This changelog adheres to [Keep a CHANGELOG](https://keepachangelog.com). ## [Unreleased] +- Bump minimum ruby requirement to 2.7 ## [0.52.0] - 2024-06-03 ### Added diff --git a/vanagon.gemspec b/vanagon.gemspec index 3587b5dd..09f00e8e 100644 --- a/vanagon.gemspec +++ b/vanagon.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |gem| gem.authors = ['Puppet By Perforce'] gem.email = 'release@puppet.com' gem.homepage = 'http://github.com/puppetlabs/vanagon' - gem.required_ruby_version = '>=2.3', '<4' + gem.required_ruby_version = '>=2.7', '<4' gem.add_runtime_dependency('docopt') # Handle git repos responsibly From 4bfe33da66cefde4afbc3e44092294d063d8ca52 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 4 Aug 2024 16:07:45 +0000 Subject: [PATCH 6/8] fix all rubocops for ruby >= 2.7 --- lib/vanagon/cli/build.rb | 2 +- lib/vanagon/cli/build_host_info.rb | 2 +- lib/vanagon/cli/build_requirements.rb | 7 ++--- lib/vanagon/cli/completion.rb | 2 +- lib/vanagon/cli/dependencies.rb | 12 ++++---- lib/vanagon/cli/inspect.rb | 2 +- lib/vanagon/cli/list.rb | 2 +- lib/vanagon/cli/render.rb | 2 +- lib/vanagon/cli/ship.rb | 2 +- lib/vanagon/cli/sign.rb | 2 +- lib/vanagon/common/user.rb | 8 +++--- lib/vanagon/component.rb | 40 +++++++++++++-------------- lib/vanagon/engine/docker.rb | 10 +++---- lib/vanagon/logger.rb | 2 +- lib/vanagon/platform/deb.rb | 2 +- lib/vanagon/platform/dsl.rb | 6 ++-- lib/vanagon/platform/osx.rb | 2 +- lib/vanagon/platform/rpm.rb | 2 +- lib/vanagon/platform/rpm/aix.rb | 2 +- lib/vanagon/platform/rpm/eos.rb | 4 +-- lib/vanagon/platform/solaris_10.rb | 2 +- lib/vanagon/platform/solaris_11.rb | 2 +- lib/vanagon/platform/windows.rb | 2 +- lib/vanagon/project.rb | 7 +---- lib/vanagon/utilities.rb | 12 ++++---- vanagon.gemspec | 12 ++++---- 26 files changed, 68 insertions(+), 82 deletions(-) diff --git a/lib/vanagon/cli/build.rb b/lib/vanagon/cli/build.rb index 3197dbcf..69c3f1ee 100644 --- a/lib/vanagon/cli/build.rb +++ b/lib/vanagon/cli/build.rb @@ -71,7 +71,7 @@ def options_translate(docopt_options) '' => :platforms, '' => :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) diff --git a/lib/vanagon/cli/build_host_info.rb b/lib/vanagon/cli/build_host_info.rb index c49745f1..02eb731f 100644 --- a/lib/vanagon/cli/build_host_info.rb +++ b/lib/vanagon/cli/build_host_info.rb @@ -51,7 +51,7 @@ def options_translate(docopt_options) '' => :platforms, '' => :targets } - return docopt_options.map { |k, v| [translations[k], v] }.to_h + return docopt_options.transform_keys { |k| translations[k] } end end end diff --git a/lib/vanagon/cli/build_requirements.rb b/lib/vanagon/cli/build_requirements.rb index 9fa4b2e7..419302aa 100644 --- a/lib/vanagon/cli/build_requirements.rb +++ b/lib/vanagon/cli/build_requirements.rb @@ -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) @@ -61,7 +60,7 @@ def options_translate(docopt_options) '' => :project_name, '' => :platform, } - return docopt_options.map { |k, v| [translations[k], v] }.to_h + return docopt_options.transform_keys { |k| translations[k] } end end end diff --git a/lib/vanagon/cli/completion.rb b/lib/vanagon/cli/completion.rb index 8d291b56..a6fad621 100644 --- a/lib/vanagon/cli/completion.rb +++ b/lib/vanagon/cli/completion.rb @@ -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 diff --git a/lib/vanagon/cli/dependencies.rb b/lib/vanagon/cli/dependencies.rb index b0cdb99a..7cf054b7 100644 --- a/lib/vanagon/cli/dependencies.rb +++ b/lib/vanagon/cli/dependencies.rb @@ -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 @@ -92,7 +90,7 @@ def options_translate(docopt_options) '' => :project_name, '' => :platforms } - return docopt_options.map { |k, v| [translations[k], v] }.to_h + return docopt_options.transform_keys { |k| translations[k] } end end end diff --git a/lib/vanagon/cli/inspect.rb b/lib/vanagon/cli/inspect.rb index 8b5fbb49..fea6539d 100644 --- a/lib/vanagon/cli/inspect.rb +++ b/lib/vanagon/cli/inspect.rb @@ -56,7 +56,7 @@ def options_translate(docopt_options) '' => :project_name, '' => :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) diff --git a/lib/vanagon/cli/list.rb b/lib/vanagon/cli/list.rb index 4c83af1f..5cd938f9 100644 --- a/lib/vanagon/cli/list.rb +++ b/lib/vanagon/cli/list.rb @@ -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 diff --git a/lib/vanagon/cli/render.rb b/lib/vanagon/cli/render.rb index d92be204..585f5a59 100644 --- a/lib/vanagon/cli/render.rb +++ b/lib/vanagon/cli/render.rb @@ -53,7 +53,7 @@ def options_translate(docopt_options) '' => :project_name, '' => :platforms, } - return docopt_options.map { |k, v| [translations[k], v] }.to_h + return docopt_options.transform_keys { |k| translations[k] } end end end diff --git a/lib/vanagon/cli/ship.rb b/lib/vanagon/cli/ship.rb index ab3fcefa..04d87371 100644 --- a/lib/vanagon/cli/ship.rb +++ b/lib/vanagon/cli/ship.rb @@ -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 diff --git a/lib/vanagon/cli/sign.rb b/lib/vanagon/cli/sign.rb index 72d33796..4f3c4859 100644 --- a/lib/vanagon/cli/sign.rb +++ b/lib/vanagon/cli/sign.rb @@ -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 diff --git a/lib/vanagon/common/user.rb b/lib/vanagon/common/user.rb index eb96c88b..3735e023 100644 --- a/lib/vanagon/common/user.rb +++ b/lib/vanagon/common/user.rb @@ -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 diff --git a/lib/vanagon/component.rb b/lib/vanagon/component.rb index 7692bbda..08123f91 100644 --- a/lib/vanagon/component.rb +++ b/lib/vanagon/component.rb @@ -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 diff --git a/lib/vanagon/engine/docker.rb b/lib/vanagon/engine/docker.rb index a67251e2..c77d4cde 100644 --- a/lib/vanagon/engine/docker.rb +++ b/lib/vanagon/engine/docker.rb @@ -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.") diff --git a/lib/vanagon/logger.rb b/lib/vanagon/logger.rb index 5f927f82..75434ede 100644 --- a/lib/vanagon/logger.rb +++ b/lib/vanagon/logger.rb @@ -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" diff --git a/lib/vanagon/platform/deb.rb b/lib/vanagon/platform/deb.rb index 8061a157..e8215804 100644 --- a/lib/vanagon/platform/deb.rb +++ b/lib/vanagon/platform/deb.rb @@ -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 diff --git a/lib/vanagon/platform/dsl.rb b/lib/vanagon/platform/dsl.rb index b580fd62..fc2b5b86 100644 --- a/lib/vanagon/platform/dsl.rb +++ b/lib/vanagon/platform/dsl.rb @@ -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 @@ -263,7 +263,7 @@ 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 @@ -271,7 +271,7 @@ def servicetype(type, servicedir: nil) # rubocop:disable Metrics/AbcSize 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 diff --git a/lib/vanagon/platform/osx.rb b/lib/vanagon/platform/osx.rb index 6efbb2fd..c4916302 100644 --- a/lib/vanagon/platform/osx.rb +++ b/lib/vanagon/platform/osx.rb @@ -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 diff --git a/lib/vanagon/platform/rpm.rb b/lib/vanagon/platform/rpm.rb index 850090b5..9255c352 100644 --- a/lib/vanagon/platform/rpm.rb +++ b/lib/vanagon/platform/rpm.rb @@ -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 diff --git a/lib/vanagon/platform/rpm/aix.rb b/lib/vanagon/platform/rpm/aix.rb index 61a620e3..5140ea7e 100644 --- a/lib/vanagon/platform/rpm/aix.rb +++ b/lib/vanagon/platform/rpm/aix.rb @@ -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 diff --git a/lib/vanagon/platform/rpm/eos.rb b/lib/vanagon/platform/rpm/eos.rb index fcbfa5ae..e7a76b1b 100644 --- a/lib/vanagon/platform/rpm/eos.rb +++ b/lib/vanagon/platform/rpm/eos.rb @@ -14,7 +14,7 @@ def generate_package(project) else case project.platform.package_type when "rpm" - return super(project) + return super when "swix" return generate_swix_package(project) else @@ -34,7 +34,7 @@ def package_name(project) else case project.platform.package_type when "rpm" - return super(project) + return super when "swix" return swix_package_name(project) else diff --git a/lib/vanagon/platform/solaris_10.rb b/lib/vanagon/platform/solaris_10.rb index 73c60b99..17bc5b62 100644 --- a/lib/vanagon/platform/solaris_10.rb +++ b/lib/vanagon/platform/solaris_10.rb @@ -189,7 +189,7 @@ def initialize(name) @shasum = "/opt/csw/bin/shasum" # solaris 10 @num_cores = "/usr/bin/kstat cpu_info | awk '{print $$1}' | grep '^core_id$$' | wc -l" - super(name) + super if @architecture == "sparc" @platform_triple = "sparc-sun-solaris2.#{@os_version}" elsif @architecture == "i386" diff --git a/lib/vanagon/platform/solaris_11.rb b/lib/vanagon/platform/solaris_11.rb index ce979496..52fd433d 100644 --- a/lib/vanagon/platform/solaris_11.rb +++ b/lib/vanagon/platform/solaris_11.rb @@ -118,7 +118,7 @@ def initialize(name) @patch = "/usr/bin/gpatch" @sed = "/usr/gnu/bin/sed" @num_cores = "/usr/bin/kstat cpu_info | /usr/bin/ggrep -E '[[:space:]]+core_id[[:space:]]' | wc -l" - super(name) + super if @architecture == "sparc" @platform_triple = "sparc-sun-solaris2.#{@os_version}" elsif @architecture == "i386" diff --git a/lib/vanagon/platform/windows.rb b/lib/vanagon/platform/windows.rb index 66699c94..66a44e51 100644 --- a/lib/vanagon/platform/windows.rb +++ b/lib/vanagon/platform/windows.rb @@ -457,7 +457,7 @@ def initialize(name) @install = "/usr/bin/install" @copy = "/usr/bin/cp" @package_type = "msi" - super(name) + super end end end diff --git a/lib/vanagon/project.rb b/lib/vanagon/project.rb index 03cebc0e..ece6391f 100644 --- a/lib/vanagon/project.rb +++ b/lib/vanagon/project.rb @@ -462,13 +462,8 @@ def get_all_trigger_pkgs() # @return [Array] of OpenStructs of all interest triggers for the pkg_state # Use array of openstructs because we need both interest_name and the scripts def get_interest_triggers(pkg_state) - interest_triggers = [] check_pkg_state_string(pkg_state) - interests = components.flat_map(&:interest_triggers).compact.select { |s| s.pkg_state.include? pkg_state } - interests.each do |interest| - interest_triggers.push(interest) - end - interest_triggers.flatten.compact + components.flat_map(&:interest_triggers).compact.select { |s| s.pkg_state.include? pkg_state }.flatten.compact end # Collects activate triggers for the project and its components diff --git a/lib/vanagon/utilities.rb b/lib/vanagon/utilities.rb index 48a34986..9fb8cb75 100644 --- a/lib/vanagon/utilities.rb +++ b/lib/vanagon/utilities.rb @@ -162,13 +162,11 @@ def retry_with_timeout(tries = 5, timeout = 1, &blk) error = nil tries.to_i.times do Timeout::timeout(timeout.to_i) do - begin - yield - return true - rescue StandardError => e - VanagonLogger.error 'An error was encountered evaluating block. Retrying..' - error = e - end + yield + return true + rescue StandardError => e + VanagonLogger.error 'An error was encountered evaluating block. Retrying..' + error = e end end diff --git a/vanagon.gemspec b/vanagon.gemspec index 09f00e8e..96629136 100644 --- a/vanagon.gemspec +++ b/vanagon.gemspec @@ -18,20 +18,20 @@ Gem::Specification.new do |gem| gem.homepage = 'http://github.com/puppetlabs/vanagon' gem.required_ruby_version = '>=2.7', '<4' - gem.add_runtime_dependency('docopt') + gem.add_dependency('docopt') # Handle git repos responsibly # - MIT licensed: https://rubygems.org/gems/git - gem.add_runtime_dependency('git', '~> 1.13.0') + gem.add_dependency('git', '~> 1.13.0') # Parse scp-style triplets like URIs; used for Git source handling. # - MIT licensed: https://rubygems.org/gems/build-uri - gem.add_runtime_dependency('build-uri', '~> 1.0') + gem.add_dependency('build-uri', '~> 1.0') # Handle locking hardware resources # - ASL v2 licensed: https://rubygems.org/gems/lock_manager - gem.add_runtime_dependency('lock_manager', '>= 0') + gem.add_dependency('lock_manager', '>= 0') # Utilities for `ship` and `repo` commands # - ASL v2 licensed: https://rubygems.org/gems/packaging - gem.add_runtime_dependency('packaging') - gem.add_runtime_dependency('psych', '>= 4.0') + gem.add_dependency('packaging') + gem.add_dependency('psych', '>= 4.0') gem.require_path = 'lib' gem.bindir = 'bin' From 7e96527c677212cc7de5d2264dbec353af494d92 Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Sun, 4 Aug 2024 16:18:01 +0000 Subject: [PATCH 7/8] fix ruby 2 workflow to use cache --- .github/workflows/ruby.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 599af64c..41e7498b 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -13,8 +13,7 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: '2.7' + bundler: '2.4.22' + bundler-cache: true - name: Build and test with Rake - run: | - gem install bundler -v 2.4.22 - bundle install --jobs 4 --retry 3 - bundle exec rake + run: bundle exec rake From 09e250aab197ef48ec88777e1c63599797b2862f Mon Sep 17 00:00:00 2001 From: Jeffrey Clark Date: Wed, 17 Apr 2024 13:21:26 -0500 Subject: [PATCH 8/8] optimize fetch to use local download if source is already downloaded and can be verified, skip downloading again. --- lib/vanagon/component/source/http.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/vanagon/component/source/http.rb b/lib/vanagon/component/source/http.rb index 05097b1d..5d272d26 100644 --- a/lib/vanagon/component/source/http.rb +++ b/lib/vanagon/component/source/http.rb @@ -82,6 +82,16 @@ def initialize(url, sum:, workdir:, sum_type:, **options) # Download the source from the url specified. Sets the full path to the # file as @file and the @extension for the file as a side effect. def fetch + @file = File.basename(URI.parse(@url).path) + if File.exist?(File.join(workdir, file)) + begin + return if verify + rescue RuntimeError, Errno::ENOENT + # ignore invalid "cached" file + end + end + remove_instance_variable(:@file) + @file = download(@url) end @@ -93,9 +103,13 @@ def file # # @raise [RuntimeError] an exception is raised if the sum does not match the sum of the file def verify + return true if @verified + VanagonLogger.info "Verifying file: #{file} against sum: '#{sum}'" actual = get_sum(File.join(workdir, file), sum_type) - return true if sum == actual + + @verified = (sum == actual) + return true if @verified fail "Unable to verify '#{File.join(workdir, file)}': #{sum_type} mismatch (expected '#{sum}', got '#{actual}')" end