Tag Deployer on Ops during auto-deploy building

parent 78101b8c
......@@ -18,9 +18,8 @@ module ReleaseTools
end
versions = ReleaseTools::ComponentVersions.get(project, commit.id)
versions.each do |component, version|
$stdout.puts "#{component}: #{version}".indent(4)
component_strings(versions).each do |string|
$stdout.puts string.indent(4)
end
trigger_build(versions) if args.trigger_build
......@@ -29,7 +28,16 @@ module ReleaseTools
def trigger_build(version_map)
if ref.match?(/\A\d+-\d+-auto-deploy-\d+\z/)
update_omnibus(version_map).tap do |commit|
tag_omnibus(commit, version_map)
tag_name = ReleaseTools::AutoDeploy::Naming.tag(
ee_ref: version_map['VERSION'],
omnibus_ref: commit.id
)
tag_message = +"Auto-deploy #{tag_name}\n\n"
tag_message << component_strings(version_map).join("\n")
tag_omnibus(tag_name, tag_message, commit)
tag_deployer(tag_name, tag_message, commit)
end
else
trigger_branch_build(version_map)
......@@ -38,36 +46,35 @@ module ReleaseTools
private
def component_strings(version_map)
version_map.map { |component, version| "#{component}: #{version}" }
end
def update_omnibus(version_map)
commit = ReleaseTools::ComponentVersions.update_omnibus(ref, version_map)
url = commit_url(ReleaseTools::Project::OmnibusGitlab, commit.short_id)
url = commit_url(ReleaseTools::Project::OmnibusGitlab, commit.id)
$stdout.puts "Updated Omnibus versions at #{url}".indent(4)
commit
end
def tag_omnibus(commit, version_map)
tag_name = ReleaseTools::AutoDeploy::Naming.tag(
ee_ref: version_map['VERSION'],
omnibus_ref: commit.id
)
def tag_omnibus(name, message, commit)
project = ReleaseTools::Project::OmnibusGitlab
$stdout.puts "Creating `#{project}` tag `#{tag_name}`".indent(4)
$stdout.puts "Creating `#{project}` tag `#{name}`".indent(4)
message = +"Auto-deploy #{tag_name}\n\n"
version_map.each_pair do |file, version|
message << "#{file}: #{version}\n"
end
ReleaseTools::GitlabClient
.create_tag(project, name, commit.id, message)
end
ReleaseTools::GitlabClient.create_tag(
project,
tag_name,
commit.id,
message.strip
)
def tag_deployer(name, message, commit)
project = ReleaseTools::Project::Deployer
$stdout.puts "Creating `#{project}` tag `#{name}`".indent(4)
ReleaseTools::GitlabOpsClient
.create_tag(project, name, commit.id, message)
end
def trigger_branch_build(version_map)
......@@ -87,6 +94,7 @@ module ReleaseTools
ReleaseTools::GitlabDevClient.delete_branch(branch_name, project)
end
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/25392
def commit_url(project, id)
"https://gitlab.com/#{project.path}/commit/#{id}"
end
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
describe ReleaseTools::PassingBuild do
let(:project) { ReleaseTools::Project::GitlabCe }
let(:fake_commit) { double('Commit', id: '1234') }
let(:fake_commit) { double('Commit', id: SecureRandom.hex(20)) }
let(:version_map) { { 'VERSION' => '1.2.3' } }
subject(:service) { described_class.new(project, 'master') }
......@@ -53,41 +53,70 @@ describe ReleaseTools::PassingBuild do
describe '#trigger_build' do
let(:fake_client) { spy }
let(:fake_ops_client) { spy }
let(:project) { ReleaseTools::Project::GitlabCe }
let(:version_map) { { 'VERSION' => '1.2.3' } }
context 'when using auto-deploy' do
let(:tag_name) { 'tag-name' }
subject(:service) { described_class.new(project, '11-10-auto-deploy-1234') }
before do
allow(ReleaseTools::AutoDeploy::Naming).to receive(:tag)
.and_return(tag_name)
stub_const('ReleaseTools::GitlabClient', fake_client)
stub_const('ReleaseTools::GitlabOpsClient', fake_ops_client)
end
it 'updates Omnibus versions', :silence_stdout do
expect(ReleaseTools::ComponentVersions)
.to receive(:update_omnibus).with('11-10-auto-deploy-1234', version_map)
.and_return(double('Commit', short_id: 'abcdefg'))
.and_return(fake_commit)
allow(service).to receive(:tag_omnibus)
expect(service).to receive(:tag_omnibus)
expect(service).to receive(:tag_deployer)
service.trigger_build(version_map)
end
it 'tags Omnibus with an annotated tag', :silence_stdout do
commit = double('Commit', id: 'abcdefg')
expect(service).to receive(:update_omnibus)
.and_return(commit)
expect(service).to receive(:tag_omnibus).with(commit, version_map)
.and_return(fake_commit)
expect(service).to receive(:tag_omnibus)
.with(tag_name, anything, fake_commit)
.and_call_original
expect(ReleaseTools::AutoDeploy::Naming).to receive(:tag)
.and_return('tag-name')
expect(ReleaseTools::GitlabClient).to receive(:create_tag)
service.trigger_build(version_map)
expect(fake_client)
.to have_received(:create_tag)
.with(
ReleaseTools::Project::OmnibusGitlab,
'tag-name',
commit.id,
tag_name,
fake_commit.id,
"Auto-deploy tag-name\n\nVERSION: 1.2.3"
)
end
it 'tags Deployer with an annotated tag', :silence_stdout do
expect(service).to receive(:update_omnibus)
.and_return(fake_commit)
expect(service).to receive(:tag_deployer)
.with(tag_name, anything, fake_commit)
.and_call_original
service.trigger_build(version_map)
expect(fake_ops_client)
.to have_received(:create_tag)
.with(
ReleaseTools::Project::Deployer,
tag_name,
fake_commit.id,
"Auto-deploy tag-name\n\nVERSION: 1.2.3"
)
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