Skip to content
Snippets Groups Projects
Verified Commit 9a4ff20a authored by Balasankar C's avatar Balasankar C Committed by DJ Mountney
Browse files

Use latest stable tag in the repo as fallback for stable branches

parent 832dc958
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -9,6 +9,8 @@ require_relative 'image'
 
module Build
class Info
TagsNotFoundError = Class.new(StandardError)
DEPLOYER_OS_MAPPING = {
'AUTO_DEPLOY_ENVIRONMENT' => 'ubuntu-xenial',
'PATCH_DEPLOY_ENVIRONMENT' => 'ubuntu-bionic',
Loading
Loading
@@ -91,7 +93,17 @@ module Build
 
# Level decides tag at which position you want. Level one gives you
# latest stable tag, two gives you the one just before it and so on.
`git -c versionsort.prereleaseSuffix=rc tag -l '#{version}#{Info.tag_match_pattern}' --sort=-v:refname | awk '!/rc/' | head -#{level}`.split("\n").last
output = `git -c versionsort.prereleaseSuffix=rc tag -l '#{version}#{Info.tag_match_pattern}' --sort=-v:refname | awk '!/rc/' | head -#{level}`&.split("\n")&.last
# If no tags exist that start with the specified version, we need to
# fall back to the available latest stable tag. For that, we run the
# same command without the version in the filter argument.
raise TagsNotFoundError if output.nil?
output
rescue TagsNotFoundError
puts "No tags found in #{version}.x series. Falling back to latest available tag."
`git -c versionsort.prereleaseSuffix=rc tag -l '#{Info.tag_match_pattern}' --sort=-v:refname | awk '!/rc/' | head -#{level}`.split("\n").last
end
 
def docker_tag
Loading
Loading
Loading
Loading
@@ -162,6 +162,42 @@ RSpec.describe Build::Info do
expect(described_class.latest_stable_tag).to eq('12.121.12+ee.0')
end
end
describe 'on stable branches' do
before do
stub_env_var('CI_COMMIT_BRANCH', '15-11-stable')
stub_is_ee(false)
end
context 'when no tags exist in the stable branch' do
before do
allow(described_class).to receive(:`).with("git -c versionsort.prereleaseSuffix=rc tag -l '15.11*[+.]ce.*' --sort=-v:refname | awk '!/rc/' | head -1").and_return(nil)
end
it 'returns the latest available stable tag' do
# Twice because we are calling the method two times - once to check
# the return value and another time to check if the message is
# printed
expect(described_class).to receive(:`).with("git -c versionsort.prereleaseSuffix=rc tag -l '15.11*[+.]ce.*' --sort=-v:refname | awk '!/rc/' | head -1").twice
expect(described_class).to receive(:`).with("git -c versionsort.prereleaseSuffix=rc tag -l '*[+.]ce.*' --sort=-v:refname | awk '!/rc/' | head -1").twice.and_return('15.10.3+ce.0')
expect(described_class.latest_stable_tag).to eq('15.10.3+ce.0')
expect { described_class.latest_stable_tag }.to output(/No tags found in 15.11.x series/).to_stdout
end
end
context 'when tags exist in the stable branch' do
before do
allow(described_class).to receive(:`).with("git -c versionsort.prereleaseSuffix=rc tag -l '15.11*[+.]ce.*' --sort=-v:refname | awk '!/rc/' | head -1").and_return('15.11.0+ce.0')
end
it 'returns the latest available stable tag' do
expect(described_class).to receive(:`).with("git -c versionsort.prereleaseSuffix=rc tag -l '15.11*[+.]ce.*' --sort=-v:refname | awk '!/rc/' | head -1")
expect(described_class).not_to receive(:`).with("git -c versionsort.prereleaseSuffix=rc tag -l '*[+.]ce.*' --sort=-v:refname | awk '!/rc/' | head -1")
expect(described_class.latest_stable_tag).to eq('15.11.0+ce.0')
end
end
end
end
 
describe '.gitlab_version' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment