Skip to content
Snippets Groups Projects
Commit 4dc2f3e2 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Merge branch '864-fix-nightly-build-versions' into 'master'

Fix versioning of nightly and branch builds

Closes #864

See merge request !1835
parents 0a7d0267 42b6ce5d
No related branches found
No related tags found
1 merge request!1835Fix versioning of nightly and branch builds
Loading
Loading
@@ -22,14 +22,20 @@ module Build
# different.
# To resolve this, we append a PIPELINE_ID to change the name of the package
def semver_version
# timestamp is disabled in omnibus configuration
Omnibus.load_configuration('omnibus.rb')
semver = Omnibus::BuildVersion.semver
if ENV['NIGHTLY'] && ENV['CI_PIPELINE_ID']
semver = "#{semver}.#{ENV['CI_PIPELINE_ID']}"
if Build::Check.on_tag?
# timestamp is disabled in omnibus configuration
Omnibus.load_configuration('omnibus.rb')
Omnibus::BuildVersion.semver
else
latest_git_tag = Info.latest_tag.strip
latest_version = latest_git_tag[0, latest_git_tag.match("[+]").begin(0)]
commit_sha = ENV['CI_COMMIT_SHA'][0, 8]
if Build::Check.add_nightly_tag?
"#{latest_version}+rnightly.#{ENV['CI_PIPELINE_ID']}.#{commit_sha}"
else
"#{latest_version}+rfbranch.#{ENV['CI_PIPELINE_ID']}.#{commit_sha}"
end
end
semver
end
 
def release_version
Loading
Loading
# This module has tests in spec/gitlab/build_iteration_spec.rb
require_relative 'build/check.rb'
 
# This module has tests in spec/gitlab/build_iteration_spec.rb
module Gitlab
class BuildIteration
def initialize(git_describe = nil)
Loading
Loading
@@ -8,12 +9,16 @@ module Gitlab
end
 
def build_iteration
match = /[^+]*\+([^\-]*)/.match(@git_describe)
if match && !match[1].empty?
match[1]
else
'0'
if Build::Check.on_tag?
match = /[^+]*\+([^\-]*)/.match(@git_describe)
return match[1] if match && !match[1].empty?
end
# For any builds other than a tag release, built_iteration value is not of
# much use. If not here, we would have to add this check in project
# definition as well as for docker builds. It is easier to simply use 0
# for non-release builds.
'0'
end
end
end
Loading
Loading
@@ -25,6 +25,7 @@ describe Build::Info do
 
describe 'release_version' do
before do
allow(Build::Check).to receive(:on_tag?).and_return(true)
allow_any_instance_of(Omnibus::BuildVersion).to receive(:semver).and_return('12.121.12')
allow_any_instance_of(Gitlab::BuildIteration).to receive(:build_iteration).and_return('ce.1')
end
Loading
Loading
@@ -45,13 +46,14 @@ describe Build::Info do
stub_env_var('NIGHTLY', 'true')
stub_env_var('CI_PIPELINE_ID', '5555')
 
expect(described_class.release_version).to eq('12.121.12.5555-ce.1')
expect(described_class.release_version).to eq('12.121.12-ce.1')
end
end
end
 
describe 'docker_tag' do
before do
allow(Build::Check).to receive(:on_tag?).and_return(true)
allow_any_instance_of(Omnibus::BuildVersion).to receive(:semver).and_return('12.121.12')
allow_any_instance_of(Gitlab::BuildIteration).to receive(:build_iteration).and_return('ce.1')
end
Loading
Loading
Loading
Loading
@@ -9,6 +9,7 @@ describe Gitlab::BuildIteration do
let(:git_describe) { '1.2.3-foo.3' }
 
it 'returns 0' do
allow(Build::Check).to receive(:on_tag?).and_return(true)
expect(subject.build_iteration).to eq('0')
end
end
Loading
Loading
@@ -17,6 +18,7 @@ describe Gitlab::BuildIteration do
let(:git_describe) { '1.2.3+rc1.ce.2-6-ge5626d5' }
 
it 'returns rc1.ce.2' do
allow(Build::Check).to receive(:on_tag?).and_return(true)
expect(subject.build_iteration).to eq('rc1.ce.2')
end
end
Loading
Loading
@@ -25,6 +27,7 @@ describe Gitlab::BuildIteration do
let(:git_describe) { '1.2.3+foo.4' }
 
it 'returns foo.4' do
allow(Build::Check).to receive(:on_tag?).and_return(true)
expect(subject.build_iteration).to eq('foo.4')
end
end
Loading
Loading
@@ -33,6 +36,7 @@ describe Gitlab::BuildIteration do
let(:git_describe) { "1.2.3+foo.4\n" }
 
it 'returns foo.4' do
allow(Build::Check).to receive(:on_tag?).and_return(true)
expect(subject.build_iteration).to eq('foo.4')
end
end
Loading
Loading
@@ -41,6 +45,7 @@ describe Gitlab::BuildIteration do
let(:git_describe) { '1.2.3+foo.4+bar' }
 
it 'returns everything after the first plus' do
allow(Build::Check).to receive(:on_tag?).and_return(true)
expect(subject.build_iteration).to eq('foo.4+bar')
end
end
Loading
Loading
@@ -49,6 +54,16 @@ describe Gitlab::BuildIteration do
let(:git_describe) { '1.2.3+' }
 
it 'returns an empty string' do
allow(Build::Check).to receive(:on_tag?).and_return(true)
expect(subject.build_iteration).to eq('0')
end
end
context 'not on a git tag' do
subject { Gitlab::BuildIteration.new }
it 'returns 0' do
allow(Build::Check).to receive(:system).with("git describe --exact-match").and_return(false)
expect(subject.build_iteration).to eq('0')
end
end
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