diff --git a/lib/gitlab/build/info/git.rb b/lib/gitlab/build/info/git.rb index 479d0329e7f84f645b8a921c6d60d713516921a1_bGliL2dpdGxhYi9idWlsZC9pbmZvL2dpdC5yYg==..6f3a349836df2108cdb7becb15282ff1518e4358_bGliL2dpdGxhYi9idWlsZC9pbmZvL2dpdC5yYg== 100644 --- a/lib/gitlab/build/info/git.rb +++ b/lib/gitlab/build/info/git.rb @@ -57,7 +57,7 @@ branch_for_version = Build::Info::CI.mr_target_branch_name || branch_name version = branch_for_version.delete_suffix('-stable').tr('-', '.') if Build::Check.on_stable_branch? || Build::Check.mr_targetting_stable_branch? - output = tags.find { |t| t.start_with?(version) } if version + output = tags.find { |t| t.start_with?("#{version}.") } if version # If no tags corresponding to the stable branch version was found, we # fall back to the latest available tag @@ -78,7 +78,7 @@ version = branch_for_version.delete_suffix('-stable').tr('-', '.') if Build::Check.on_stable_branch? || Build::Check.mr_targetting_stable_branch? - results = stable_tags.select { |t| t.start_with?(version) } if version + results = stable_tags.select { |t| t.start_with?("#{version}.") } if version # If no tags corresponding to the stable branch version was found, we # fall back to the latest available stable tag diff --git a/spec/lib/gitlab/build/info/git_spec.rb b/spec/lib/gitlab/build/info/git_spec.rb index 479d0329e7f84f645b8a921c6d60d713516921a1_c3BlYy9saWIvZ2l0bGFiL2J1aWxkL2luZm8vZ2l0X3NwZWMucmI=..6f3a349836df2108cdb7becb15282ff1518e4358_c3BlYy9saWIvZ2l0bGFiL2J1aWxkL2luZm8vZ2l0X3NwZWMucmI= 100644 --- a/spec/lib/gitlab/build/info/git_spec.rb +++ b/spec/lib/gitlab/build/info/git_spec.rb @@ -5,8 +5,8 @@ before do stub_default_package_version - ce_tags = "16.1.1+ce.0\n16.0.0+rc42.ce.0\n15.11.1+ce.0\n15.11.0+ce.0\n15.10.0+ce.0\n15.10.0+rc42.ce.0" - ee_tags = "16.1.1+ee.0\n16.0.0+rc42.ee.0\n15.11.1+ee.0\n15.11.0+ee.0\n15.10.0+ee.0\n15.10.0+rc42.ee.0" + ce_tags = "16.1.1+ce.0\n16.0.0+rc42.ce.0\n15.11.1+ce.0\n15.11.0+ce.0\n15.10.0+ce.0\n15.10.0+rc42.ce.0\n15.1.0+ce.0\n" + ee_tags = "16.1.1+ee.0\n16.0.0+rc42.ee.0\n15.11.1+ee.0\n15.11.0+ee.0\n15.10.0+ee.0\n15.10.0+rc42.ee.0\n15.1.0+ee.0\n" allow(Gitlab::Util).to receive(:shellout_stdout).with(/git -c versionsort.*ce/).and_return(ce_tags) allow(Gitlab::Util).to receive(:shellout_stdout).with(/git -c versionsort.*ee/).and_return(ee_tags) end @@ -225,6 +225,17 @@ expect(described_class.latest_tag).to eq('15.10.0+ce.0') end end + + context 'when they target 15-1-stable' do + before do + stub_env_var('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME', 'my-feature-branch') + stub_env_var('CI_MERGE_REQUEST_TARGET_BRANCH_NAME', '15-1-stable') + end + + it 'returns the latest tag in the 15.1 series' do + expect(described_class.latest_tag).to eq('15.1.0+ce.0') + end + end end end @@ -363,7 +374,7 @@ end it 'returns the latest available tag' do - expect(described_class.latest_tag).to eq('16.1.1+ce.0') + expect(described_class.latest_stable_tag).to eq('16.1.1+ce.0') end end @@ -374,7 +385,18 @@ end it 'returns the latest tag in the stable version series' do - expect(described_class.latest_tag).to eq('15.10.0+ce.0') + expect(described_class.latest_stable_tag).to eq('15.10.0+ce.0') + end + end + + context 'when they target 15-1-stable' do + before do + stub_env_var('CI_MERGE_REQUEST_SOURCE_BRANCH_NAME', 'my-feature-branch') + stub_env_var('CI_MERGE_REQUEST_TARGET_BRANCH_NAME', '15-1-stable') + end + + it 'returns the latest tag in the 15.1 series' do + expect(described_class.latest_stable_tag).to eq('15.1.0+ce.0') end end end