From faa03c8ea7ca3e82d3538a505e0d2233a7bc0f31 Mon Sep 17 00:00:00 2001 From: Leslie Hoare Date: Thu, 22 Feb 2024 23:34:44 +0000 Subject: [PATCH] Retain modified version file content when bumping version When bumping the version, the content of the version file is updated to the new version. This change retains the modified content of the version file when bumping the version, for example, if any packages in the package.json file are updated. --- lib/utils/bump.rb | 3 +-- spec/lib/utils/bump_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/utils/bump.rb b/lib/utils/bump.rb index e7cdbde..86b5371 100644 --- a/lib/utils/bump.rb +++ b/lib/utils/bump.rb @@ -25,9 +25,8 @@ def bump_everything commit = Commit.new(@config) files = [] @other_version_file_paths.push(@version_file_path).each do |version_file_path| - base_branch_content = Content.new(config: @config, ref: @base_branch, path: version_file_path) head_branch_content = Content.new(config: @config, ref: @head_branch, path: version_file_path) - updated_base_branch_content = base_branch_content.content.gsub @version.to_s, @updated_version.to_s + 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}" diff --git a/spec/lib/utils/bump_spec.rb b/spec/lib/utils/bump_spec.rb index b2778ec..d190b9d 100644 --- a/spec/lib/utils/bump_spec.rb +++ b/spec/lib/utils/bump_spec.rb @@ -68,5 +68,23 @@ "#{version_file_path}\n" ).to_stdout end + + it 'retains modified version file content' do + allow(head_content).to receive(:content).and_return('version: 1.0.0 extra stuff here') + allow(base_content).to receive(:content).and_return('version: 1.0.0') + + bump = Bump.new(config, 'patch') + expect(commit).to receive(:multiple_files).with( + [ + { + path: other_version_file_paths[0], mode: '100644', type: 'blob', + content: 'version: 1.0.1 extra stuff here' + }, + { path: version_file_path, mode: '100644', type: 'blob', content: 'version: 1.0.1 extra stuff here' } + ], + 'Bump patch version' + ) + bump.bump_everything + end end end