From 572d91f65e231529c6990799c43cce26c42c69dc Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Thu, 27 Jan 2022 08:52:24 +0100 Subject: [PATCH] Maintenance: Add CI check for possibly orphaned bundled gems. This runs only on develop and is allowed to fail. --- .gitlab/ci/pre.yml | 41 +++++++++++++------- Gemfile | 2 - Gemfile.lock | 6 --- lib/tasks/zammad/ci/bundle/orphaned.rake | 4 ++ lib/tasks/zammad/ci/bundle/orphaned.rb | 48 ++++++++++++++++++++++++ lib/tasks/zammad/command.rb | 2 +- 6 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 lib/tasks/zammad/ci/bundle/orphaned.rake create mode 100644 lib/tasks/zammad/ci/bundle/orphaned.rb diff --git a/.gitlab/ci/pre.yml b/.gitlab/ci/pre.yml index df70c40d3..5272afac9 100644 --- a/.gitlab/ci/pre.yml +++ b/.gitlab/ci/pre.yml @@ -8,6 +8,20 @@ - source /etc/profile.d/rvm.sh # ensure RVM is loaded - source /opt/rh/rh-nodejs*/enable # ensure Node.js is available +.template_pre_rails: &template_pre_rails + stage: pre + extends: + - .tags_docker + - .rules_singletest + - .services_postgresql + before_script: + - source /etc/profile.d/rvm.sh # ensure RVM is loaded + - source /opt/rh/rh-nodejs*/enable # ensure Node.js is available + - bundle install -j $(nproc) --path vendor + - bundle exec ruby .gitlab/configure_environment.rb + - source .gitlab/environment.env + - bundle exec rake zammad:db:init + rubocop: <<: *template_pre script: @@ -30,27 +44,16 @@ gettext lint: - for FILE in i18n/*.pot i18n/*.po; do echo "Checking $FILE"; msgfmt -o /dev/null -c $FILE; done gettext catalog consistency: - <<: *template_pre + <<: *template_pre_rails extends: - .tags_docker - .services_postgresql script: - - bundle install -j $(nproc) --path vendor - - bundle exec ruby .gitlab/configure_environment.rb - - source .gitlab/environment.env - - bundle exec rake zammad:db:init - bundle exec rails generate translation_catalog --check zeitwerk:check: - <<: *template_pre - extends: - - .tags_docker - - .services_postgresql + <<: *template_pre_rails script: - - bundle install -j $(nproc) --path vendor - - bundle exec ruby .gitlab/configure_environment.rb - - source .gitlab/environment.env - - bundle exec rake zammad:db:init - bundle exec rails zeitwerk:check brakeman: @@ -84,6 +87,18 @@ bundle-audit: - bundle-audit update - bundle-audit --ignore CVE-2015-9284 +bundle-orphaned: + <<: *template_pre_rails + allow_failure: true + rules: + - if: $CI_MERGE_REQUEST_ID + when: never + - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' + when: always + - when: manual + script: + - bundle exec rake zammad:ci:bundle:orphaned 5 + github: <<: *template_pre tags: diff --git a/Gemfile b/Gemfile index 356594b88..f89de9b22 100644 --- a/Gemfile +++ b/Gemfile @@ -158,8 +158,6 @@ group :development, :test do # app boottime improvement gem 'spring' - gem 'spring-commands-rspec' - gem 'spring-commands-testunit' # debugging gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index 67a70e40f..f1c562730 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -563,10 +563,6 @@ GEM websocket-driver slop (3.6.0) spring (4.0.0) - spring-commands-rspec (1.0.4) - spring (>= 0.9.1) - spring-commands-testunit (1.0.1) - spring (>= 0.9.1) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -734,8 +730,6 @@ DEPENDENCIES slack-notifier slack-ruby-client spring - spring-commands-rspec - spring-commands-testunit sprockets (~> 3.7.2) tcr telegramAPI diff --git a/lib/tasks/zammad/ci/bundle/orphaned.rake b/lib/tasks/zammad/ci/bundle/orphaned.rake new file mode 100644 index 000000000..9bfafbced --- /dev/null +++ b/lib/tasks/zammad/ci/bundle/orphaned.rake @@ -0,0 +1,4 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +require_dependency 'tasks/zammad/ci/bundle/orphaned.rb' +Tasks::Zammad::Ci::Bundle::Orphaned.register_rake_task diff --git a/lib/tasks/zammad/ci/bundle/orphaned.rb b/lib/tasks/zammad/ci/bundle/orphaned.rb new file mode 100644 index 000000000..b9196173a --- /dev/null +++ b/lib/tasks/zammad/ci/bundle/orphaned.rb @@ -0,0 +1,48 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +require_dependency 'tasks/zammad/command.rb' + +module Tasks + module Zammad + module Ci + module Bundle + class Orphaned < Tasks::Zammad::Command + + def self.usage + "#{super} age_in_years" + end + + ARGUMENT_COUNT = 1 + + def self.task_handler + age = validate_age + orphaned_gems = find_orphaned_gems(age) + + if orphaned_gems.count.zero? + puts "No bundled gems released more than #{age} year(s) ago found." + return + end + + puts "The following bundled gems were released more than #{age} year(s) ago:" + orphaned_gems.each do |s| + puts " #{s.name}:#{s.version} #{s.date.strftime('%F')}" + end + abort + end + + def self.validate_age + age = ARGV[1] + if age.to_i.to_s != age + abort "Please provide a valid number for 'age_in_years'.\n#{usage}" + end + age.to_i + end + + def self.find_orphaned_gems(age) + Bundler.definition.specs.select { |s| s.date < age.years.ago } + end + end + end + end + end +end diff --git a/lib/tasks/zammad/command.rb b/lib/tasks/zammad/command.rb index ee9a41ee4..47913816d 100644 --- a/lib/tasks/zammad/command.rb +++ b/lib/tasks/zammad/command.rb @@ -40,7 +40,7 @@ module Tasks # self-modification in 'zammad:package:install'). # Enforce the correct number of expected arguments. def self.validate_comandline - if ARGV.first.eql?(task_name) || ARGV.count != (const_get(:ARGUMENT_COUNT) + 1) + if ARGV.first.to_sym != task_name || ARGV.count != (const_get(:ARGUMENT_COUNT) + 1) abort "Error: wrong number of arguments given.\n#{usage}" end # Rake will try to run additional arguments as tasks, so make sure nothing happens for these.