Commit 8aebca12 authored by John Jarvis's avatar John Jarvis

Addressing review comments

parent 98428619
......@@ -19,9 +19,11 @@ unless ENV['CI'] || Rake.application.top_level_tasks.include?('default') || Rele
abort('Please use the master branch and make sure you are up to date.'.colorize(:red))
end
namespace :auto_deploy do
namespace :auto_deploy do
desc "Create auto-deploy branches from the latest green commit on gitlab-ee and omnibus-gitlab"
task :create_branches do |_t, args|
task :create_branches do
pipeline_id = ENV['CI_PIPELINE_IID']
abort('CI_PIPELINE_IID must be set for this rake task'.colorize(:red)) unless pipeline_id
ReleaseTools::Services::AutoDeployBranchService.new(pipeline_id).create_auto_deploy_branches!
end
end
......
......@@ -97,7 +97,7 @@ require 'release_tools/release_managers/sync_result'
require 'release_tools/release_managers/schedule'
require 'release_tools/remote_repository'
require 'release_tools/security_patch_issue'
require 'release_tools/services/branch_service'
require 'release_tools/services/branch_creation'
require 'release_tools/services/auto_deploy_branch_service'
require 'release_tools/services/monthly_preparation_service'
require 'release_tools/services/security_preparation_service'
......
......@@ -19,10 +19,9 @@ module ReleaseTools
def commit_list
@commit_list ||= @client.commits(
@project.path,
{
per_page: 1,
ref_name: 'master'
})
per_page: 1,
sha: 'master'
)
end
def filter_for_green_builds
......
......@@ -2,8 +2,10 @@
module ReleaseTools
module Services
class AutoDeployBranchService < BranchService
class AutoDeployBranchService
include BranchCreation
PIPELINE_ID_PADDING = 7
def initialize(pipeline_id)
@pipeline_id = pipeline_id.to_s.rjust(PIPELINE_ID_PADDING, '0')
@version = client.current_milestone.title.tr('.', '-')
......@@ -11,11 +13,11 @@ module ReleaseTools
def create_auto_deploy_branches!
# Find passing commits before creating branches
commit_ee = branch_commit(Project::GitlabEe)
commit_omnibus = branch_commit(Project::OmnibusGitlab)
ref_ee = latest_successful_ref(Project::GitlabEe)
ref_omnibus = latest_successful_ref(Project::OmnibusGitlab)
create_branch(Project::GitlabEe, branch_name, commit_ee)
create_branch(Project::OmnibusGitlab, branch_name, commit_omnibus)
create_branch_from_ref(Project::GitlabEe, branch_name, ref_ee)
create_branch_from_ref(Project::OmnibusGitlab, branch_name, ref_omnibus)
end
private
......@@ -24,7 +26,7 @@ module ReleaseTools
"#{@version}-auto-deploy-#{@pipeline_id}-ee"
end
def branch_commit(project)
def latest_successful_ref(project)
ReleaseTools::Commits.new(project).latest_successful.id
end
end
......
# frozen_string_literal: true
module ReleaseTools
module BranchCreation
def client
ReleaseTools::GitlabClient
end
def ignoring_duplicates(&block)
yield
rescue Gitlab::Error::Conflict, Gitlab::Error::BadRequest => ex
if ex.message.match?('already exists')
# no-op for idempotency
else
raise
end
end
def create_branch_from_ref(project, branch, ref)
$stdout.puts "Creating `#{branch}` from `#{ref}` on `#{project.path}`"
return if dry_run?
ignoring_duplicates do
client.create_branch(branch, ref, project)
end
end
end
end
# frozen_string_literal: true
module ReleaseTools
module Services
class BranchService
private
def client
ReleaseTools::GitlabClient
end
def ignoring_duplicates(&block)
yield
rescue Gitlab::Error::Conflict, Gitlab::Error::BadRequest => ex
if ex.message.match?('already exists')
# no-op for idempotency
else
raise
end
end
def create_branch(project, branch, commit = 'master')
$stdout.puts "Creating `#{branch}` on `#{project.path}` using commit #{commit}"
return if dry_run?
ignoring_duplicates do
client.create_branch(branch, commit, project)
end
end
end
end
end
......@@ -2,7 +2,9 @@
module ReleaseTools
module Services
class MonthlyPreparationService < BranchService
class MonthlyPreparationService
include BranchCreation
def initialize(version)
@version = version
end
......@@ -21,10 +23,10 @@ module ReleaseTools
ce_branch = @version.stable_branch(ee: false)
ee_branch = @version.stable_branch(ee: true)
create_branch(Project::GitlabEe, ee_branch)
create_branch(Project::GitlabCe, ce_branch)
create_branch(Project::OmnibusGitlab, ee_branch)
create_branch(Project::OmnibusGitlab, ce_branch)
create_branch_from_ref(Project::GitlabEe, ee_branch, 'master')
create_branch_from_ref(Project::GitlabCe, ce_branch, 'master')
create_branch_from_ref(Project::OmnibusGitlab, ee_branch, 'master')
create_branch_from_ref(Project::OmnibusGitlab, ce_branch, 'master')
end
end
end
......
# frozen_string_literal: true
def pipeline_id
pipeline_id = ENV['CI_PIPELINE_IID']
unless pipeline_id
$stdout.puts "Warning: CI_PIPELINE_IID is not set, using `1` as the ID"
pipeline_id = '1'
end
pipeline_id
end
def get_version(args)
version = ReleaseTools::Version.new(args[:version])
......
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