Tag Omnibus during auto deploy

parent 38ffe709
......@@ -19,6 +19,7 @@ module ReleaseTools
def_delegator :client, :update_variable
def_delegator :client, :create_commit
def_delegator :client, :create_tag
end
class MissingMilestone
......
......@@ -28,7 +28,9 @@ module ReleaseTools
def trigger_build(version_map)
if ref.match?(/\A\d+-\d+-auto-deploy-\d+\z/)
trigger_commit_build(version_map)
update_omnibus(version_map).tap do |commit|
tag_omnibus(commit, version_map)
end
else
trigger_branch_build(version_map)
end
......@@ -36,14 +38,26 @@ module ReleaseTools
private
def trigger_commit_build(version_map)
def update_omnibus(version_map)
commit = ReleaseTools::ComponentVersions.update_omnibus(ref, version_map)
url = commit_url(ReleaseTools::Project::OmnibusGitlab, commit.short_id)
$stdout.puts "Updated Omnibus versions at #{url}".indent(4)
# TODO: Tagging
commit
end
def tag_omnibus(commit, version_map)
tag_name = ReleaseTools::AutoDeploy::Naming.tag(
ee_ref: version_map['VERSION'],
omnibus_ref: commit.id
)
ReleaseTools::GitlabClient.create_tag(
ReleaseTools::Project::OmnibusGitlab,
tag_name,
commit.id
)
end
def trigger_branch_build(version_map)
......
......@@ -52,11 +52,11 @@ describe ReleaseTools::PassingBuild do
end
describe '#trigger_build' do
describe 'when using auto-deploy' do
let(:fake_client) { spy }
let(:project) { ReleaseTools::Project::GitlabCe }
let(:version_map) { { 'VERSION' => '1.2.3' } }
let(:fake_client) { spy }
let(:project) { ReleaseTools::Project::GitlabCe }
let(:version_map) { { 'VERSION' => '1.2.3' } }
context 'when using auto-deploy' do
subject(:service) { described_class.new(project, '11-10-auto-deploy-1234') }
it 'updates Omnibus versions', :silence_stdout do
......@@ -64,31 +64,44 @@ describe ReleaseTools::PassingBuild do
.to receive(:update_omnibus).with('11-10-auto-deploy-1234', version_map)
.and_return(double('Commit', short_id: 'abcdefg'))
allow(service).to receive(:tag_omnibus)
service.trigger_build(version_map)
end
end
describe 'when not using auto-deploy' do
let(:fake_client) { spy }
let(:project) { ReleaseTools::Project::GitlabCe }
let(:version_map) { { 'VERSION' => '1.2.3' } }
let(:pipeline_id) { ENV.fetch('CI_PIPELINE_ID', 'pipeline_id_unset') }
it 'tags Omnibus' do
commit = double('Commit', id: 'abcdefg')
subject(:service) { described_class.new(project, 'master') }
expect(service).to receive(:update_omnibus)
.and_return(commit)
expect(service).to receive(:tag_omnibus).with(commit, version_map)
.and_call_original
it 'triggers a pipeline build', :silence_stdout do
expect(ReleaseTools::GitlabDevClient)
.to receive(:create_branch).with("master-#{pipeline_id}", 'master', project)
expect(ReleaseTools::AutoDeploy::Naming).to receive(:tag)
.and_return('tag-name')
expect(ReleaseTools::GitlabClient).to receive(:create_tag)
.with(ReleaseTools::Project::OmnibusGitlab, 'tag-name', commit.id)
allow(ReleaseTools::Pipeline).to receive(:new).and_call_original
expect(ReleaseTools::Pipeline)
.to receive(:new).with(project, 'master', version_map)
service.trigger_build(version_map)
end
end
expect(ReleaseTools::GitlabDevClient)
.to receive(:delete_branch).with("master-#{pipeline_id}", project)
context 'when not using auto-deploy' do
subject(:service) { described_class.new(project, 'master') }
VCR.use_cassette('pipeline/trigger') do
service.trigger_build(version_map)
it 'triggers a pipeline build', :silence_stdout do
ClimateControl.modify(CI_PIPELINE_ID: '1234', OMNIBUS_BUILD_TRIGGER_TOKEN: 'token') do
expect(ReleaseTools::GitlabDevClient)
.to receive(:create_branch).with("master-1234", 'master', project)
expect(ReleaseTools::Pipeline)
.to receive(:new).with(project, 'master', version_map)
.and_return(double(trigger: true))
expect(ReleaseTools::GitlabDevClient)
.to receive(:delete_branch).with("master-1234", project)
VCR.use_cassette('pipeline/trigger') do
service.trigger_build(version_map)
end
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment