summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-01-23 12:54:19 -0800
committerStan Hu <stanhu@gmail.com>2019-01-23 13:03:28 -0800
commitfe93010c936c2bc1c15b4ed1ffaa18675d26406f (patch)
treec5cbb57853b67415bddc80c937e59d7b70653e8d
parent768475bd78420b6ca023c1322bc13c336d688056 (diff)
downloadgitlab-ce-sh-fix-issue-56760.tar.gz
Make ee_compat_check work on other remotes and branchessh-fix-issue-56760
Right now ee_compat_check can only use GitLab.com CE and EE repositories and only checks against a target branch of `master`. The EE repository can now be overriden via the `EE_REPOSITORY_URL` variable. In addition, the EE target branch will be derived from the CI variable CI_MERGE_REQUEST_TARGET_BRANCH_NAME. If the variable is blank or `master`, then the EE target branch will be `master`. Otherwise, if the merge request targets some other branch, it will append `-ee` as the target branch. For example, if a merge request targets `11-7-stable`, then ee_compat_check will check `11-7-stable-ee`. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/56760
-rw-r--r--lib/gitlab/ee_compat_check.rb77
1 files changed, 45 insertions, 32 deletions
diff --git a/lib/gitlab/ee_compat_check.rb b/lib/gitlab/ee_compat_check.rb
index 01fd261404b..b565b5d7b48 100644
--- a/lib/gitlab/ee_compat_check.rb
+++ b/lib/gitlab/ee_compat_check.rb
@@ -33,16 +33,17 @@ module Gitlab
@patches_dir = CHECK_DIR.join('patches')
@ce_branch = branch
@ce_project_url = ce_project_url
- @ee_repo_url = ce_public_repo_url.sub('gitlab-ce', 'gitlab-ee')
+ @ee_repo_url = ENV.fetch(
+ 'EE_REPOSITORY_URL', ce_public_repo_url.sub('gitlab-ce', 'gitlab-ee'))
@job_id = job_id
end
def check
ensure_patches_dir
# We're generating the patch against the canonical-ce remote since forks'
- # master branch are not necessarily up-to-date.
+ # target EE branch (e.g. master) may not be up-to-date.
add_remote('canonical-ce', "#{CANONICAL_CE_PROJECT_URL}.git")
- generate_patch(branch: ce_branch, patch_path: ce_patch_full_path, branch_remote: 'origin', master_remote: 'canonical-ce')
+ generate_patch(branch: ce_branch, patch_path: ce_patch_full_path, branch_remote: 'origin', target_remote: 'canonical-ce')
ensure_ee_repo
Dir.chdir(ee_repo_dir) do
@@ -51,7 +52,7 @@ module Gitlab
ee_remotes.each do |key, url|
add_remote(key, url)
end
- fetch(branch: 'master', depth: 20, remote: 'canonical-ee')
+ fetch(branch: target_ee_branch, depth: 20, remote: 'canonical-ee')
status = catch(:halt_check) do
ce_branch_compat_check!
@@ -59,7 +60,7 @@ module Gitlab
ee_branch_presence_check!
step("Checking out #{ee_remote_with_branch}/#{ee_branch_found}", %W[git checkout -b #{ee_branch_found} #{ee_remote_with_branch}/#{ee_branch_found}])
- generate_patch(branch: ee_branch_found, patch_path: ee_patch_full_path, branch_remote: ee_remote_with_branch, master_remote: 'canonical-ee')
+ generate_patch(branch: ee_branch_found, patch_path: ee_patch_full_path, branch_remote: ee_remote_with_branch, target_remote: 'canonical-ee')
ee_branch_compat_check!
end
@@ -96,16 +97,16 @@ module Gitlab
end
def ensure_ee_repo
- unless clone_repo(ee_repo_url, ee_repo_dir)
+ unless clone_repo(ee_repo_url, target_ee_branch, ee_repo_dir)
# Fallback to using the canonical EE if there is no forked EE
- clone_repo(CANONICAL_EE_REPO_URL, ee_repo_dir)
+ clone_repo(CANONICAL_EE_REPO_URL, target_ee_branch, ee_repo_dir)
end
end
- def clone_repo(url, dir)
+ def clone_repo(url, branch, dir)
_, status = step(
"Cloning #{url} into #{dir}",
- %W[git clone --branch master --single-branch --depth=200 #{url} #{dir}]
+ %W[git clone --branch #{branch} --single-branch --depth=200 #{url} #{dir}]
)
status.zero?
end
@@ -114,14 +115,14 @@ module Gitlab
FileUtils.mkdir_p(patches_dir)
end
- def generate_patch(branch:, patch_path:, branch_remote:, master_remote:)
+ def generate_patch(branch:, patch_path:, branch_remote:, target_remote:)
FileUtils.rm(patch_path, force: true)
- find_merge_base_with_master(branch: branch, branch_remote: branch_remote, master_remote: master_remote)
+ find_merge_base_with_target_branch(branch: branch, branch_remote: branch_remote, target_remote: target_remote, target_branch: target_ee_branch)
step(
- "Generating the patch against #{master_remote}/master in #{patch_path}",
- %W[git diff --binary #{master_remote}/master...#{branch_remote}/#{branch}]
+ "Generating the patch against #{target_remote}/#{target_ee_branch} in #{patch_path}",
+ %W[git diff --binary #{target_remote}/#{target_ee_branch}...#{branch_remote}/#{branch}]
) do |output, status|
throw(:halt_check, :ko) unless status.zero?
@@ -178,10 +179,10 @@ module Gitlab
end
def check_patch(patch_path)
- step("Checking out master", %w[git checkout master])
- step("Resetting to latest master", %w[git reset --hard canonical-ee/master])
+ step("Checking out #{target_ee_branch}", %W[git checkout #{target_ee_branch}])
+ step("Resetting to latest #{target_ee_branch}", %W[git reset --hard canonical-ee/#{target_ee_branch}])
step(
- "Checking if #{patch_path} applies cleanly to EE/master",
+ "Checking if #{patch_path} applies cleanly to EE/#{target_ee_branch}",
# Don't use --check here because it can result in a 0-exit status even
# though the patch doesn't apply cleanly, e.g.:
# > git apply --check --3way foo.patch
@@ -213,15 +214,15 @@ module Gitlab
end
def delete_ee_branches_locally!
- command(%w[git checkout master])
+ command(%W[git checkout #{target_ee_branch}])
command(%W[git branch --delete --force #{ee_branch_prefix}])
command(%W[git branch --delete --force #{ee_branch_suffix}])
end
- def merge_base_found?(branch:, branch_remote:, master_remote:)
+ def merge_base_found?(branch:, branch_remote:, target_remote:, target_branch:)
step(
- "Finding merge base with #{master_remote}/master",
- %W[git merge-base #{master_remote}/master #{branch_remote}/#{branch}]
+ "Finding merge base with #{target_remote}/#{target_branch}",
+ %W[git merge-base #{target_remote}/#{target_branch} #{branch_remote}/#{branch}]
) do |output, status|
if status.zero?
puts "Merge base was found: #{output}"
@@ -230,7 +231,7 @@ module Gitlab
end
end
- def find_merge_base_with_master(branch:, branch_remote:, master_remote:)
+ def find_merge_base_with_target_branch(branch:, branch_remote:, target_remote:, target_branch:)
# 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
depth = 20
@@ -240,12 +241,12 @@ module Gitlab
# 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
fetch(branch: branch, depth: depth, remote: branch_remote)
- fetch(branch: 'master', depth: depth, remote: master_remote)
+ fetch(branch: target_branch, depth: depth, remote: target_remote)
- merge_base_found?(branch: branch, branch_remote: branch_remote, master_remote: master_remote)
+ merge_base_found?(branch: branch, branch_remote: branch_remote, target_remote: target_remote, target_branch: target_branch)
end
- raise "\n#{branch} is too far behind #{master_remote}/master, please rebase it!\n" unless success
+ raise "\n#{branch} is too far behind #{target_remote}/#{target_branch}, please rebase it!\n" unless success
end
def fetch(branch:, depth:, remote: 'origin')
@@ -293,6 +294,18 @@ module Gitlab
"#{ce_project_url}/-/jobs/#{job_id}/artifacts/raw/ee_compat_check/patches/#{ce_patch_name}"
end
+ def target_ee_branch
+ @target_ee_branch ||= begin
+ target = ENV['CI_MERGE_REQUEST_TARGET_BRANCH_NAME']
+
+ if target.blank? || target == 'master'
+ 'master'
+ else
+ ENV['CI_MERGE_REQUEST_TARGET_BRANCH_NAME'] + '-ee'
+ end
+ end
+ end
+
def step(desc, cmd = nil)
puts "\n=> #{desc}\n"
@@ -327,7 +340,7 @@ module Gitlab
#{PLEASE_READ_THIS_BANNER}
🎉 Congratulations!! 🎉
- The `#{branch}` branch applies cleanly to EE/master!
+ The `#{branch}` branch applies cleanly to EE/#{target_ee_branch}!
Much ❤️! For more information, see
https://docs.gitlab.com/ce/development/automatic_ce_ee_merge.html
@@ -343,7 +356,7 @@ module Gitlab
💥 Oh no! 💥
The `#{ce_branch}` branch does not apply cleanly to the current
- EE/master, and no `#{ee_branch_prefix}` or `#{ee_branch_suffix}` branch
+ EE/#{target_ee_branch}, and no `#{ee_branch_prefix}` or `#{ee_branch_suffix}` branch
was found in #{ee_repos.join(' nor in ')}.
If you're a community contributor, don't worry, someone from
@@ -355,16 +368,16 @@ module Gitlab
We advise you to create a `#{ee_branch_prefix}` or `#{ee_branch_suffix}`
branch that includes changes from `#{ce_branch}` but also specific changes
- than can be applied cleanly to EE/master. In some cases, the conflicts
+ than can be applied cleanly to EE/#{target_ee_branch}. In some cases, the conflicts
are trivial and you can ignore the warning from this job. As always,
use your best judgement!
There are different ways to create such branch:
- 1. Create a new branch from master and cherry-pick your CE commits
+ 1. Create a new branch from #{target_ee_branch} and cherry-pick your CE commits
# In the EE repo
- $ git fetch #{CANONICAL_EE_REPO_URL} master
+ $ git fetch #{CANONICAL_EE_REPO_URL} #{target_ee_branch}
$ git checkout -b #{ee_branch_prefix} FETCH_HEAD
$ git fetch #{ce_public_repo_url} #{ce_branch}
$ git cherry-pick SHA # Repeat for all the commits you want to pick
@@ -374,7 +387,7 @@ module Gitlab
2. Apply your branch's patch to EE
# In the EE repo
- $ git fetch #{CANONICAL_EE_REPO_URL} master
+ $ git fetch #{CANONICAL_EE_REPO_URL} #{target_ee_branch}
$ git checkout -b #{ee_branch_prefix} FETCH_HEAD
$ wget #{patch_url} && git apply --3way #{ce_patch_name}
@@ -418,10 +431,10 @@ module Gitlab
#{PLEASE_READ_THIS_BANNER}
💥 Oh no! 💥
- The `#{ce_branch}` does not apply cleanly to the current EE/master, and
+ The `#{ce_branch}` does not apply cleanly to the current EE/#{target_ee_branch}, and
even though a `#{ee_branch_found}` branch
exists in #{ee_repo_url}, it does not apply cleanly either to
- EE/master!
+ EE/#{target_ee_branch}!
#{conflicting_files_msg}