From 55e91d9da60e9096a941198c6ddc48bf653a4675 Mon Sep 17 00:00:00 2001 From: fartem Date: Wed, 7 Aug 2024 08:52:59 +0300 Subject: [PATCH] 2024-08-07 v. 6.4.1.1: refactored CI jobs --- ci/ci_job.rb | 5 +++++ ci/links_checker.rb | 9 +++++---- ci/readme_checker.rb | 5 +---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ci/ci_job.rb b/ci/ci_job.rb index d3f60ca2..94075ff2 100644 --- a/ci/ci_job.rb +++ b/ci/ci_job.rb @@ -6,19 +6,24 @@ module CI # Use it to create concrete CI jobs. class CIJob PROCESS_NO_IMPL_ERROR = "No implementation for process in #{self.class.name}" + private_constant :PROCESS_NO_IMPL_ERROR # Main entry of job class that runs your check. def run puts("#{self.class.name} started...") + process + puts("#{self.class.name} ended without errors!") end # Use this method in your realization when task completed with error. def end_with_error(details) details.call + puts("#{self.class.name} ended with an error.") + exit(1) end diff --git a/ci/links_checker.rb b/ci/links_checker.rb index 31bc9b29..360f50b2 100644 --- a/ci/links_checker.rb +++ b/ci/links_checker.rb @@ -20,10 +20,11 @@ def check(difficulty) lines = ::IO.readlines("#{path}/#{file_name}") has_comment = false lines.each do |line| - if line.start_with?('# https://leetcode.com/') - has_comment = true - break - end + next unless line.start_with?('# https://leetcode.com/') + + has_comment = true + + break end end_with_error(-> { puts("LinksChecker ends with an error from #{file_name}.") }) unless has_comment diff --git a/ci/readme_checker.rb b/ci/readme_checker.rb index 12331084..13bc83ba 100644 --- a/ci/readme_checker.rb +++ b/ci/readme_checker.rb @@ -19,10 +19,7 @@ def check(difficulty) readme = ::File.readlines('./README.md') solutions.each do |file_name| - links_count = 0 - readme.each do |line| - links_count += 1 if line.include?(file_name) - end + links_count = readme.count { |line| line.include?(file_name) } end_with_error(-> { puts("ReadmeChecker ends with an error from #{file_name}.") }) if links_count != 1 end