Commit 05e0c4c1 authored by Rémy Coutable's avatar Rémy Coutable

Try to find the merge-base against the canonical master

Also, name the remotes in Gitlab::EeCompatCheck
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 13cfcfc2
...@@ -419,7 +419,7 @@ ee_compat_check: ...@@ -419,7 +419,7 @@ ee_compat_check:
retry: 0 retry: 0
artifacts: artifacts:
name: "${CI_JOB_NAME}_${CI_COMIT_REF_NAME}_${CI_COMMIT_SHA}" name: "${CI_JOB_NAME}_${CI_COMIT_REF_NAME}_${CI_COMMIT_SHA}"
when: on_failure when: always
expire_in: 10d expire_in: 10d
paths: paths:
- ee_compat_check/patches/*.patch - ee_compat_check/patches/*.patch
......
...@@ -31,16 +31,22 @@ module Gitlab ...@@ -31,16 +31,22 @@ module Gitlab
def check def check
ensure_patches_dir ensure_patches_dir
generate_patch(ce_branch, ce_patch_full_path) add_remote('canonical-ce', "#{DEFAULT_CE_PROJECT_URL}.git")
generate_patch(branch: ce_branch, patch_path: ce_patch_full_path, remote: 'canonical-ce')
ensure_ee_repo ensure_ee_repo
Dir.chdir(ee_repo_dir) do Dir.chdir(ee_repo_dir) do
step("In the #{ee_repo_dir} directory") step("In the #{ee_repo_dir} directory")
add_remote('canonical-ee', EE_REPO_URL)
status = catch(:halt_check) do status = catch(:halt_check) do
ce_branch_compat_check! ce_branch_compat_check!
delete_ee_branches_locally! delete_ee_branches_locally!
ee_branch_presence_check! ee_branch_presence_check!
step("Checking out #{ee_branch_found}", %W[git checkout -b #{ee_branch_found} canonical-ee/#{ee_branch_found}])
generate_patch(branch: ee_branch_found, patch_path: ee_patch_full_path, remote: 'canonical-ee')
ee_branch_compat_check! ee_branch_compat_check!
end end
...@@ -56,6 +62,13 @@ module Gitlab ...@@ -56,6 +62,13 @@ module Gitlab
private private
def add_remote(name, url)
step(
"Adding the #{name} remote (#{url})",
%W[git remote add #{name} #{url}]
)
end
def ensure_ee_repo def ensure_ee_repo
if Dir.exist?(ee_repo_dir) if Dir.exist?(ee_repo_dir)
step("#{ee_repo_dir} already exists") step("#{ee_repo_dir} already exists")
...@@ -71,14 +84,14 @@ module Gitlab ...@@ -71,14 +84,14 @@ module Gitlab
FileUtils.mkdir_p(patches_dir) FileUtils.mkdir_p(patches_dir)
end end
def generate_patch(branch, patch_path) def generate_patch(branch:, patch_path:, remote:)
FileUtils.rm(patch_path, force: true) FileUtils.rm(patch_path, force: true)
find_merge_base_with_master(branch: branch) find_merge_base_with_master(branch: branch, master_remote: remote)
step( step(
"Generating the patch against origin/master in #{patch_path}", "Generating the patch against #{remote}/master in #{patch_path}",
%w[git diff --binary origin/master...HEAD] %W[git diff --binary #{remote}/master...#{branch}]
) do |output, status| ) do |output, status|
throw(:halt_check, :ko) unless status.zero? throw(:halt_check, :ko) unless status.zero?
...@@ -89,21 +102,21 @@ module Gitlab ...@@ -89,21 +102,21 @@ module Gitlab
end end
def ce_branch_compat_check! def ce_branch_compat_check!
if check_patch(ce_patch_full_path).zero? if check_patch(ce_patch_full_path, remote: 'canonical-ce').zero?
puts applies_cleanly_msg(ce_branch) puts applies_cleanly_msg(ce_branch)
throw(:halt_check) throw(:halt_check)
end end
end end
def ee_branch_presence_check! def ee_branch_presence_check!
_, status = step("Fetching origin/#{ee_branch_prefix}", %W[git fetch origin #{ee_branch_prefix}]) _, status = step("Fetching origin/#{ee_branch_prefix}", %W[git fetch canonical-ee #{ee_branch_prefix}])
if status.zero? if status.zero?
@ee_branch_found = ee_branch_prefix @ee_branch_found = ee_branch_prefix
return return
end end
_, status = step("Fetching origin/#{ee_branch_suffix}", %W[git fetch origin #{ee_branch_suffix}]) _, status = step("Fetching origin/#{ee_branch_suffix}", %W[git fetch canonical-ee #{ee_branch_suffix}])
if status.zero? if status.zero?
@ee_branch_found = ee_branch_suffix @ee_branch_found = ee_branch_suffix
...@@ -116,11 +129,7 @@ module Gitlab ...@@ -116,11 +129,7 @@ module Gitlab
end end
def ee_branch_compat_check! def ee_branch_compat_check!
step("Checking out origin/#{ee_branch_found}", %W[git checkout -b #{ee_branch_found} FETCH_HEAD]) unless check_patch(ee_patch_full_path, remote: 'canonical-ee').zero?
generate_patch(ee_branch_found, ee_patch_full_path)
unless check_patch(ee_patch_full_path).zero?
puts puts
puts ee_branch_doesnt_apply_cleanly_msg puts ee_branch_doesnt_apply_cleanly_msg
...@@ -131,10 +140,9 @@ module Gitlab ...@@ -131,10 +140,9 @@ module Gitlab
puts applies_cleanly_msg(ee_branch_found) puts applies_cleanly_msg(ee_branch_found)
end end
def check_patch(patch_path) def check_patch(patch_path, remote:)
step("Checking out master", %w[git checkout master]) step("Checking out master", %w[git checkout master])
step("Resetting to latest master", %w[git reset --hard origin/master]) step("Resetting to latest master", %W[git reset --hard #{remote}/master])
step("Fetching CE/#{ce_branch}", %W[git fetch #{ce_repo_url} #{ce_branch}])
step( step(
"Checking if #{patch_path} applies cleanly to EE/master", "Checking if #{patch_path} applies cleanly to EE/master",
# Don't use --check here because it can result in a 0-exit status even # Don't use --check here because it can result in a 0-exit status even
...@@ -171,10 +179,10 @@ module Gitlab ...@@ -171,10 +179,10 @@ module Gitlab
command(%W[git branch --delete --force #{ee_branch_suffix}]) command(%W[git branch --delete --force #{ee_branch_suffix}])
end end
def merge_base_found? def merge_base_found?(master_remote:, branch:)
step( step(
"Finding merge base with master", "Finding merge base with #{master_remote}/master",
%w[git merge-base origin/master HEAD] %W[git merge-base #{master_remote}/master #{branch}]
) do |output, status| ) do |output, status|
if status.zero? if status.zero?
puts "Merge base was found: #{output}" puts "Merge base was found: #{output}"
...@@ -183,7 +191,7 @@ module Gitlab ...@@ -183,7 +191,7 @@ module Gitlab
end end
end end
def find_merge_base_with_master(branch:) def find_merge_base_with_master(branch:, master_remote:)
# Start with (Math.exp(3).to_i = 20) until (Math.exp(6).to_i = 403) # Start with (Math.exp(3).to_i = 20) until (Math.exp(6).to_i = 403)
# In total we go (20 + 54 + 148 + 403 = 625) commits deeper # In total we go (20 + 54 + 148 + 403 = 625) commits deeper
depth = 20 depth = 20
...@@ -192,19 +200,19 @@ module Gitlab ...@@ -192,19 +200,19 @@ module Gitlab
depth += Math.exp(factor).to_i depth += Math.exp(factor).to_i
# Repository is initially cloned with a depth of 20 so we need to fetch # Repository is initially cloned with a depth of 20 so we need to fetch
# deeper in the case the branch has more than 20 commits on top of master # deeper in the case the branch has more than 20 commits on top of master
fetch(branch: branch, depth: depth) fetch(branch: branch, depth: depth, remote: 'origin')
fetch(branch: 'master', depth: depth, remote: DEFAULT_CE_PROJECT_URL) fetch(branch: 'master', depth: depth, remote: master_remote)
merge_base_found? merge_base_found?(master_remote: master_remote, branch: branch)
end end
raise "\n#{branch} is too far behind master, please rebase it!\n" unless success raise "\n#{branch} is too far behind #{master_remote}/master, please rebase it!\n" unless success
end end
def fetch(branch:, depth:, remote: 'origin') def fetch(branch:, depth:, remote: 'origin')
step( step(
"Fetching deeper...", "Fetching deeper...",
%W[git fetch --depth=#{depth} --prune #{remote} +refs/heads/#{branch}:refs/remotes/origin/#{branch}] %W[git fetch --depth=#{depth} --prune #{remote} +refs/heads/#{branch}:refs/remotes/#{remote}/#{branch}]
) do |output, status| ) do |output, status|
raise "Fetch failed: #{output}" unless status.zero? raise "Fetch failed: #{output}" unless status.zero?
end end
...@@ -304,8 +312,8 @@ module Gitlab ...@@ -304,8 +312,8 @@ module Gitlab
1. Create a new branch from master and cherry-pick your CE commits 1. Create a new branch from master and cherry-pick your CE commits
# In the EE repo # In the EE repo
$ git fetch origin $ git fetch #{EE_REPO_URL} master
$ git checkout -b #{ee_branch_prefix} origin/master $ git checkout -b #{ee_branch_prefix} FETCH_HEAD
$ git fetch #{ce_repo_url} #{ce_branch} $ git fetch #{ce_repo_url} #{ce_branch}
$ git cherry-pick SHA # Repeat for all the commits you want to pick $ git cherry-pick SHA # Repeat for all the commits you want to pick
...@@ -314,10 +322,9 @@ module Gitlab ...@@ -314,10 +322,9 @@ module Gitlab
2. Apply your branch's patch to EE 2. Apply your branch's patch to EE
# In the EE repo # In the EE repo
$ git fetch origin master $ git fetch #{EE_REPO_URL} master
$ git checkout -b #{ee_branch_prefix} origin/master $ git checkout -b #{ee_branch_prefix} FETCH_HEAD
$ wget #{patch_url} $ wget #{patch_url} && git apply --3way #{ce_patch_name}
$ git apply --3way #{ce_patch_name}
At this point you might have conflicts such as: At this point you might have conflicts such as:
......
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