diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ae2f053d..27e83c72 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,23 +1,30 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-01-15 19:01:58 UTC using RuboCop version 1.57.2. +# on 2024-10-18 15:57:43 UTC using RuboCop version 1.66.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 +# Offense count: 2 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 34 -# Offense count: 1 +# Offense count: 3 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 17 + Max: 20 -# Offense count: 6 +# Offense count: 5 # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: - 'spec/lib/utils/bump_spec.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 173 diff --git a/Gemfile.lock b/Gemfile.lock index 2bd6bf5e..0e3113d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (7.2.1) + activesupport (7.2.1.1) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) @@ -21,7 +21,7 @@ GEM concurrent-ruby (1.3.4) connection_pool (2.4.1) diff-lcs (1.5.1) - docile (1.4.0) + docile (1.4.1) drb (2.2.1) faraday (2.12.0) faraday-net_http (>= 2.0, < 3.4) @@ -38,7 +38,7 @@ GEM base64 language_server-protocol (3.17.0.3) logger (1.6.1) - method_source (1.0.0) + method_source (1.1.0) minitest (5.25.1) net-http (0.4.1) uri @@ -54,16 +54,16 @@ GEM method_source (~> 1.0) public_suffix (6.0.1) racc (1.8.1) - rack (3.1.7) + rack (3.1.8) rainbow (3.1.1) regexp_parser (2.9.2) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) rspec-mocks (~> 3.13.0) - rspec-core (3.13.0) + rspec-core (3.13.1) rspec-support (~> 3.13.0) - rspec-expectations (3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-mocks (3.13.2) @@ -139,4 +139,4 @@ DEPENDENCIES simplycop (= 2.5.1) BUNDLED WITH - 2.4.12 + 2.5.22 diff --git a/lib/action.rb b/lib/action.rb index cada2ce6..68fe72f6 100644 --- a/lib/action.rb +++ b/lib/action.rb @@ -26,6 +26,7 @@ def initiate_version_update(level) else add_reaction('confused') puts "::error title=Unknown semver level::The semver level #{level} is not valid" + "## :boom: Error:boom: \n\nThe semver level #{level} is not valid so failing the action. Expecting a semver level of #{VALID_SEMVER_LEVELS.join(', ')}" end end diff --git a/lib/command.rb b/lib/command.rb index 0d416440..97f510e4 100644 --- a/lib/command.rb +++ b/lib/command.rb @@ -10,10 +10,12 @@ class Command def initialize(config) @config = config + @message = "### Dobby bumping the version\n" comment = config.payload['comment']['body'].strip.downcase unless comment.start_with?(COMMAND_PREFIX) error_msg = "Comment must start with #{COMMAND_PREFIX}" puts "::error title=Argument Error::#{error_msg}" + @message += "## :boom: Error:boom:\n\n The comment must start with #{COMMAND_PREFIX} so failing the action." raise ArgumentError, error_msg end @@ -26,10 +28,14 @@ def call action = Action.new(config) case command when 'version' - action.initiate_version_update(options) + @message += action.initiate_version_update(options).to_s else + @message += "## :boom: Error:boom:\n\nThe command #{command} is not valid so failing the action. Expecting a command of 'version'." puts "::error title=Unknown command::The command #{command} is not valid" action.add_reaction('confused') end + File.open(ENV.fetch('GITHUB_STEP_SUMMARY', nil), 'w') do |file| + file.puts @message + end end end diff --git a/lib/utils/bump.rb b/lib/utils/bump.rb index 86b53711..9e10f9fb 100644 --- a/lib/utils/bump.rb +++ b/lib/utils/bump.rb @@ -24,21 +24,25 @@ def initialize(config, level) def bump_everything commit = Commit.new(@config) files = [] + files_messages = {} @other_version_file_paths.push(@version_file_path).each do |version_file_path| head_branch_content = Content.new(config: @config, ref: @head_branch, path: version_file_path) updated_base_branch_content = head_branch_content.content.gsub @version.to_s, @updated_version.to_s if head_branch_content.content == updated_base_branch_content puts "::notice title=Nothing to update::The desired version bump is already present for: #{version_file_path}" + files_messages[version_file_path] = 'Nothing to update as the desired version bump is already present' else files.push( { :path => version_file_path, :mode => '100644', :type => 'blob', :content => updated_base_branch_content } ) + files_messages[version_file_path] = "Bump #{@level} version from #{@version} to #{@updated_version}" end end commit.multiple_files(files, "Bump #{@level} version") if files.any? + generate_message(files_messages) end private @@ -63,4 +67,15 @@ def fetch_version(content) def bump_version(version, level) version.increment!(level.to_sym) end + + def generate_message(files_messages) + message = "### Bump version from #{@version} to #{@updated_version}\n" + message += "| File Name | Message |\n" + message += "|-----------|---------|\n" + files_messages.each do |file_name, msg| + message += "| #{file_name} | #{msg} |\n" + end + message += "|-----------|---------|\n" + message + end end diff --git a/spec/lib/action_spec.rb b/spec/lib/action_spec.rb index b7292cd3..07faecd0 100644 --- a/spec/lib/action_spec.rb +++ b/spec/lib/action_spec.rb @@ -35,7 +35,8 @@ describe '#initiate_version_update' do it 'reacts with confused emoji for invalid semver' do expect(action).to receive(:add_reaction).with('confused') - action.initiate_version_update('invalid_semver') + message = action.initiate_version_update('invalid_semver') + expect(message).to eq("## :boom: Error:boom: \n\nThe semver level invalid_semver is not valid so failing the action. Expecting a semver level of minor, major, patch") end it 'bumps major version' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9448e434..7ee72a85 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,4 +17,8 @@ end config.shared_context_metadata_behavior = :apply_to_host_groups + + config.before do + ENV['GITHUB_STEP_SUMMARY'] = 'temp.md' + end end diff --git a/temp.md b/temp.md new file mode 100644 index 00000000..0115fc55 --- /dev/null +++ b/temp.md @@ -0,0 +1,4 @@ +### Dobby bumping the version +## :boom: Error:boom: + +The command barney is not valid so failing the action. Expecting a command of 'version'.