From 0b1e39681a3d15591fe1e4520e6d4a3490636c05 Mon Sep 17 00:00:00 2001 From: Markus Bucher Date: Wed, 29 Jul 2026 16:39:05 +0200 Subject: [PATCH] chore(ruby): update to ruby-4.0 --- .github/workflows/rubocop.yml | 5 ++-- .github/workflows/spec_tests.yml | 5 ++-- .github/workflows/tests.yml | 5 ++-- .gitlab-ci.yml | 2 +- .rubocop.yml | 11 ++++++-- Dockerfile | 2 +- Gemfile | 4 ++- Gemfile.lock | 34 ++++++++++++++--------- debRelease.rb | 7 +++-- errata_parser.rb | 2 ++ gen_errata.rb | 21 +++++++-------- parse_dsalist.rb | 5 ++-- test/gen_test_data.rb | 9 +++---- test/test_gen_errata.rb | 46 +++++++++++++++++--------------- 14 files changed, 89 insertions(+), 69 deletions(-) diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 1a88c37..8cccad5 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -16,11 +16,12 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.3 + ruby-version: 4.0 bundler-cache: true - name: Setup rubocop run: | - bundle install --with=rubocop + bundle config set with rubocop + bundle install - name: Execute rubocop run: | bundle exec rubocop diff --git a/.github/workflows/spec_tests.yml b/.github/workflows/spec_tests.yml index 6d4aab2..effd408 100644 --- a/.github/workflows/spec_tests.yml +++ b/.github/workflows/spec_tests.yml @@ -16,11 +16,12 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.3 + ruby-version: 4.0 bundler-cache: true - name: Setup bundle run: | - bundle install --with=test + bundle config set with test + bundle install - name: Run rspec run: | bundle exec rspec diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 25f3ed1..29714da 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,11 +16,12 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.3 + ruby-version: 4.0 bundler-cache: true - name: Setup rubocop run: | - bundle install --with=rubocop + bundle config set with rubocop + bundle install - name: Run tests run: | bundle exec ruby test/all.rb diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bb82c99..81e7439 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: - test variables: - RUBY_VERSION: "3.3" + RUBY_VERSION: "4.0" RUBY_IMAGE: "ruby:${RUBY_VERSION}-bookworm" .common: diff --git a/.rubocop.yml b/.rubocop.yml index b6d41ab..f325fae 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,8 @@ AllCops: - TargetRubyVersion: 3.3 + TargetRubyVersion: 4.0 NewCops: enable -require: +plugins: - rubocop-rspec Layout/LineLength: @@ -17,6 +17,13 @@ Layout/SpaceInsideBlockBraces: Exclude: - 'Gemfile' +Style/OneClassPerFile: + Exclude: + - parse_dsalist.rb + - lib/deb_erratum_rss.rb + - gen_errata.rb + - debRelease.rb + Metrics/AbcSize: Max: 73 diff --git a/Dockerfile b/Dockerfile index 712d7fe..f3e3766 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:3.3-bookworm +FROM ruby:4.0-trixie LABEL maintainer="Markus Bucher " \ description="This container provides an errata-parser for Debian and Ubuntu" \ diff --git a/Gemfile b/Gemfile index a222bd7..e8b5b0a 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,7 @@ gem 'parallel', '~> 1.20', '< 1.21', group: %i[build test] # Added at 2018-12-05 19:28:10 +0100 by markus: group :rubocop, optional: true do - gem "rubocop", "~> 1.51.0" + gem "rubocop", "~> 1.88.0" gem "rubocop-rspec", "~> 3.0" end @@ -45,3 +45,5 @@ end gem "feedjira", "~> 3.2", group: :monitor gem "faraday", "~> 2.14", group: :monitor + +gem "fiddle", "~> 1.1", group: %i[build test] diff --git a/Gemfile.lock b/Gemfile.lock index ef2b9ce..de5fe0e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,10 +20,13 @@ GEM loofah (>= 2.3.1, < 3) sax-machine (>= 1.0, < 2) ffi (1.17.4-x86_64-linux-gnu) + fiddle (1.1.8) json (2.21.1) json-stream (1.0.0) json-streamer (2.1.0) json-stream + language_server-protocol (3.17.0.6) + lint_roller (1.1.0) logger (1.7.0) loofah (2.25.2) crass (~> 1.0.2) @@ -45,7 +48,6 @@ GEM racc (1.8.1) rainbow (3.1.1) regexp_parser (2.12.0) - rexml (3.4.4) rspec (3.13.2) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) @@ -61,21 +63,24 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.7) - rubocop (1.51.0) + rubocop (1.88.2) json (~> 2.3) - parallel (~> 1.10) - parser (>= 3.2.0.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (>= 1.10) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.0, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.49.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) + unicode-display_width (>= 2.4.0, < 4.0) rubocop-ast (1.50.0) parser (>= 3.3.7.2) prism (~> 1.7) - rubocop-rspec (3.0.0) - rubocop (~> 1.40) + rubocop-rspec (3.10.2) + lint_roller (~> 1.1) + regexp_parser (>= 2.0) + rubocop (~> 1.86, >= 1.86.2) ruby-debian (0.3.8) ruby-progressbar (1.13.0) ruby-xz (1.0.3) @@ -89,7 +94,9 @@ GEM simplecov_json_formatter (0.1.4) test-unit (3.7.8) power_assert - unicode-display_width (2.6.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.2.0) uri (1.1.1) PLATFORMS @@ -100,12 +107,13 @@ DEPENDENCIES bzip2-ffi (~> 1.0) faraday (~> 2.14) feedjira (~> 3.2) + fiddle (~> 1.1) json-streamer (~> 2.1) parallel (~> 1.20, < 1.21) pry (~> 0.14.2) rspec (~> 3.13) rspec-collection_matchers (~> 1.2) - rubocop (~> 1.51.0) + rubocop (~> 1.88.0) rubocop-rspec (~> 3.0) ruby-debian (~> 0.3.8) ruby-xz (~> 1.0) @@ -114,4 +122,4 @@ DEPENDENCIES test-unit (~> 3.5) BUNDLED WITH - 2.5.9 + 4.0.16 diff --git a/debRelease.rb b/debRelease.rb index 4cd16c7..66662d1 100755 --- a/debRelease.rb +++ b/debRelease.rb @@ -4,7 +4,6 @@ require 'debian' require 'fileutils' require 'time' -require 'pathname' require 'xz' require 'zlib' @@ -13,6 +12,7 @@ # Debian / Ubuntu release file download / parsing class DebRelease include Downloader + @@tempdir = '/tmp/errata_parser_cache/debian' attr_reader :data, :files @@ -233,8 +233,7 @@ def self.assemble_ubuntu_packages(target, source) end threads = [] - pckgs = [] - suites.each do |s| + pckgs = suites.map do |s| threads << Thread.new do warn "Loading Release for #{s.inspect}" debrel = DebRelease.new(repository_url, s) @@ -245,7 +244,7 @@ def self.assemble_ubuntu_packages(target, source) warn "From #{s.inspect} get archs:#{debrel.architectures.inspect} and comps: #{debrel.components.inspect}" - pckgs << debrel.all_packages + debrel.all_packages end end diff --git a/errata_parser.rb b/errata_parser.rb index 580358d..3da42f1 100755 --- a/errata_parser.rb +++ b/errata_parser.rb @@ -284,7 +284,9 @@ def load_config(filename) repository = cfg['repository'] + # rubocop:disable Style/MapIntoArray repository['releases'].each do |s| + # rubocop:enable Style/MapIntoArray threads << Thread.new do Thread.current[:repo_url] = repository['repo_url'] if repository.key?('credentials') diff --git a/gen_errata.rb b/gen_errata.rb index 648ef2b..b4230d5 100755 --- a/gen_errata.rb +++ b/gen_errata.rb @@ -5,7 +5,6 @@ require 'yaml' require 'time' require 'debian' -require 'pathname' require_relative 'parse_dsalist' require_relative 'downloader' @@ -379,7 +378,7 @@ def gen_ubuntu_errata(usn_db, packages, packages_by_name, release_whitelist=nil, package = {} pkg.each do |k, v| - package[k.to_sym || key] = v + package[k.to_sym] = v end package[:release] = rel @@ -596,21 +595,19 @@ def get_binary_packages_for_erratum_package(source_pkg, pkg, packages, architect require 'bzip2/ffi' require 'stringio' - usn_db_f = File.open('test/data/database.json.bz2', 'rb') - - packages = JSON.parse(File.read('test/data/packages_everything_ubuntu.json')) - errata = parser.gen_ubuntu_errata(JSON.parse(Bzip2::FFI::Reader.read(usn_db_f)), packages, {}, ['bionic'], ['amd64']) - usn_db_f.close + File.open('test/data/database.json.bz2', 'rb') do |usn_db_f| + packages = JSON.parse(File.read('test/data/packages_everything_ubuntu.json')) + errata = parser.gen_ubuntu_errata(JSON.parse(Bzip2::FFI::Reader.read(usn_db_f)), packages, {}, ['bionic'], ['amd64']) + end when 'ubuntu-esm_test_record' require 'bzip2/ffi' require 'stringio' - usn_db_f = File.open('test/data/database.json.bz2', 'rb') - - packages_by_name = JSON.parse(File.read('test/data/packages_everything_ubuntu_debstyle.json')) - errata = parser.gen_ubuntu_errata(JSON.parse(Bzip2::FFI::Reader.read(usn_db_f)), {}, packages_by_name, ['xenial'], ['amd64']) - usn_db_f.close + File.open('test/data/database.json.bz2', 'rb') do |usn_db_f| + packages_by_name = JSON.parse(File.read('test/data/packages_everything_ubuntu_debstyle.json')) + errata = parser.gen_ubuntu_errata(JSON.parse(Bzip2::FFI::Reader.read(usn_db_f)), {}, packages_by_name, ['xenial'], ['amd64']) + end else warn "Unsupported option #{type}" diff --git a/parse_dsalist.rb b/parse_dsalist.rb index ef1515f..ad640ec 100644 --- a/parse_dsalist.rb +++ b/parse_dsalist.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true require 'json' +require 'stringio' -REGEX_1ST_LINE = /^\[(?[^\]]+)\]\s*(?[A-z0-9-]+)\s*(?\S+)\s*-*\s*(?.*)$/ +REGEX_1ST_LINE = /^\[(?[^\]]+)\]\s*(?[A-Za-z0-9-]+)\s*(?\S+)\s*-*\s*(?.*)$/ REGEX_CVE_LINE = /\s+{(?[^}]*)}/ REGEX_REL_LINE = /\s+\[(?[^\]]*)\]\s*-\s*(?\S+)\s*(?\S*)/ REGEX_NOT_LINE = /\s+NOTE:/ @@ -82,7 +83,7 @@ def add_cve(cve_numbers) end def cve_empty? - (@cve.nil? || @cve.empty?) + @cve.nil? || @cve.empty? end def add_release(release:, package:, version:) diff --git a/test/gen_test_data.rb b/test/gen_test_data.rb index d7f6ad1..2975819 100644 --- a/test/gen_test_data.rb +++ b/test/gen_test_data.rb @@ -53,7 +53,7 @@ class Download cve_list.each do |package, cves| cves_filtered = {} cves.each do |cve_id, cve| - releases = cve['releases'].select { |release, _pkgs| releases.include? release } + releases = cve['releases'].slice(*releases) if cve_ids.include?(cve_id) || !releases.empty? cves_filtered[cve_id] = cve.clone cves_filtered[cve_id]['releases'] = releases @@ -71,7 +71,7 @@ class Download usn_db = Download.new.download_file_cached(config_ubuntu['usn_list_url']) usn_db_filtered = {} JSON.parse(Bzip2::FFI::Reader.read(StringIO.new(usn_db))).each do |usn_id, usn_data| - releases_data = usn_data['releases'].select { |r, _dat| rel_whitelist.include? r } + releases_data = usn_data['releases'].slice(*rel_whitelist) next if releases_data.empty? usn_db_filtered[usn_id] = usn_data.clone.merge('releases' => releases_data) @@ -121,8 +121,7 @@ class Download end threads = [] - pckgs = [] - suites.each do |s| + pckgs = suites.map do |s| threads << Thread.new do warn "Loading Release for #{s.inspect}" debrel = DebRelease.new(repository_url, s) @@ -133,7 +132,7 @@ class Download warn "From #{s.inspect} get archs:#{debrel.architectures.inspect} and comps: #{debrel.components.inspect}" - pckgs << debrel.all_packages + debrel.all_packages end end diff --git a/test/test_gen_errata.rb b/test/test_gen_errata.rb index 8083afa..1fa0872 100644 --- a/test/test_gen_errata.rb +++ b/test/test_gen_errata.rb @@ -59,17 +59,18 @@ def test_gen_ubuntu_errata packages = JSON.parse(File.read(pkg_json_path)) packages_by_name = JSON.parse(File.read(pkg_deb_json_path)) - f = File.open usn_list_path, 'rb' - errata = parser.gen_ubuntu_errata( - JSON.parse( - Bzip2::FFI::Reader.read(f) - ), - packages, - packages_by_name, - ['bionic'], - ['amd64'] - ) - f.close + errata = nil + File.open usn_list_path, 'rb' do |f| + errata = parser.gen_ubuntu_errata( + JSON.parse( + Bzip2::FFI::Reader.read(f) + ), + packages, + packages_by_name, + ['bionic'], + ['amd64'] + ) + end assert_instance_of(Array, errata) hsh = {} @@ -107,17 +108,18 @@ def test_gen_ubuntu_esm_errata packages_by_name = JSON.parse(File.read(pkg_json_path)) - f = File.open usn_list_path, 'rb' - errata = parser.gen_ubuntu_errata( - JSON.parse( - Bzip2::FFI::Reader.read(f) - ), - {}, - packages_by_name, - ['xenial'], - ['amd64'] - ) - f.close + errata = nil + File.open usn_list_path, 'rb' do |f| + errata = parser.gen_ubuntu_errata( + JSON.parse( + Bzip2::FFI::Reader.read(f) + ), + {}, + packages_by_name, + ['xenial'], + ['amd64'] + ) + end assert_instance_of(Array, errata) hsh = {}