Commit 3972506d authored by John Jarvis's avatar John Jarvis Committed by Yorick Peterse

Only update omnibus versions when they change

parent 5ef67f08
......@@ -22,7 +22,7 @@ module ReleaseTools
def self.update_omnibus(target_branch, version_map)
return if SharedStatus.dry_run?
actions = version_map.map do |filename, contents|
actions = version_changes(target_branch, version_map).map do |filename, contents|
{
action: 'update',
file_path: "/#{filename}",
......@@ -30,6 +30,13 @@ module ReleaseTools
}
end
if actions.empty?
return ReleaseTools::GitlabClient.commit(
ReleaseTools::Project::OmnibusGitlab,
target_branch
)
end
ReleaseTools::GitlabClient.create_commit(
ReleaseTools::Project::OmnibusGitlab,
target_branch,
......@@ -37,5 +44,16 @@ module ReleaseTools
actions
)
end
def self.version_changes(target_branch, version_map)
project = ReleaseTools::Project::OmnibusGitlab
version_map.reject do |filename, contents|
ReleaseTools::GitlabClient.file_contents(
project.path,
"/#{filename}",
target_branch
).chomp == contents
end
end
end
end
......@@ -17,12 +17,12 @@ module ReleaseTools
raise "Unable to find a passing #{project} build for `#{ref}` on dev"
end
versions = ReleaseTools::ComponentVersions.get(project, commit.id)
component_strings(versions).each do |string|
version_map = ReleaseTools::ComponentVersions.get(project, commit.id)
component_strings(version_map).each do |string|
$stdout.puts string.indent(4)
end
trigger_build(versions) if args.trigger_build
trigger_build(version_map) if args.trigger_build
end
def trigger_build(version_map)
......
......@@ -29,17 +29,20 @@ describe ReleaseTools::ComponentVersions do
end
describe '.update_omnibus' do
it 'commits version updates for the specified ref' do
map = {
let(:project) { ReleaseTools::Project::OmnibusGitlab }
let(:version_map) do
{
'GITALY_SERVER_VERSION' => '1.33.0',
'GITLAB_PAGES_VERSION' => '1.5.0',
'GITLAB_SHELL_VERSION' => '9.0.0',
'GITLAB_WORKHORSE_VERSION' => '8.6.0',
'VERSION' => '0cfa69752d82b8e134bdb8e473c185bdae26ccc2'
}
end
it 'commits version updates for the specified ref' do
without_dry_run do
described_class.update_omnibus('foo-branch', map)
described_class.update_omnibus('foo-branch', version_map)
end
expect(fake_client).to have_received(:create_commit).with(
......@@ -49,7 +52,45 @@ describe ReleaseTools::ComponentVersions do
array_including(
action: 'update',
file_path: '/VERSION',
content: "#{map['VERSION']}\n"
content: "#{version_map['VERSION']}\n"
)
)
end
it 'does not create a commit with a version update without changes' do
allow(described_class).to receive(:version_changes).and_return({})
expect(fake_client).not_to have_received(:create_commit)
without_dry_run do
described_class.update_omnibus('foo-branch', version_map)
end
end
end
describe '.version_changes' do
let(:project) { ReleaseTools::Project::OmnibusGitlab }
let(:version_map) { { 'GITALY_SERVER_VERSION' => '1.33.0' } }
it 'keeps omnibus versions that have changed' do
expect(fake_client).to receive(:file_contents)
.with(project.path, "/GITALY_SERVER_VERSION", 'foo-branch')
.and_return("1.2.3\n")
expect(described_class.version_changes('foo-branch', version_map)).to match(
a_hash_including(
'GITALY_SERVER_VERSION' => '1.33.0'
)
)
end
it 'rejects omnibus versions that have not changed' do
expect(fake_client).to receive(:file_contents)
.with(project.path, "/GITALY_SERVER_VERSION", 'foo-branch')
.and_return("1.33.0\n")
expect(described_class.version_changes('foo-branch', version_map)).not_to match(
a_hash_including(
'GITALY_SERVER_VERSION' => '1.33.0'
)
)
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