Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2023-01-17 23:30:25 +0300
committerSarah German <sgerman@gitlab.com>2023-01-17 23:30:25 +0300
commitc07878657b7b8eff9181bcb719f69840db2018d7 (patch)
tree4a0468be3b612b39516213aa3c93cb765fe0b548 /lib
parent07eddffe2541f8d3eca9e9eed11fce940e464d46 (diff)
Check the target branch when pulling upstream projects
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/build_site.rake2
-rw-r--r--lib/tasks/task_helpers.rb73
2 files changed, 45 insertions, 30 deletions
diff --git a/lib/tasks/build_site.rake b/lib/tasks/build_site.rake
index 9d32bbf9..7b1fdadf 100644
--- a/lib/tasks/build_site.rake
+++ b/lib/tasks/build_site.rake
@@ -21,7 +21,7 @@ task :clone_repositories do
&& branch == ENV['CI_DEFAULT_BRANCH'] \
&& ENV["CI_PIPELINE_SOURCE"] == 'pipeline'
- puts "\n#{TaskHelpers::COLOR_CODE_GREEN}INFO: Cloning #{product['repo']}..#{TaskHelpers::COLOR_CODE_RESET}"
+ puts "\n#{TaskHelpers::COLOR_CODE_GREEN}INFO: Cloning branch '#{branch}' of #{product['repo']}..#{TaskHelpers::COLOR_CODE_RESET}"
#
# Handle the cases where we land on a runner that already ran a docs build,
diff --git a/lib/tasks/task_helpers.rb b/lib/tasks/task_helpers.rb
index bf5e54ac..fd64afe6 100644
--- a/lib/tasks/task_helpers.rb
+++ b/lib/tasks/task_helpers.rb
@@ -28,38 +28,32 @@ class TaskHelpers
end
def retrieve_branch(slug)
- # If CI_COMMIT_REF_NAME is not defined (run locally), set it to the default branch.
- if ENV["CI_COMMIT_REF_NAME"].nil?
- default_branch(products[slug].fetch('repo'))
-
- # If we're on a gitlab-docs stable branch according to the regex, catch the
- # version and assign the product stable branches correctly.
- elsif version = ENV["CI_COMMIT_REF_NAME"].match(VERSION_FORMAT)
+ #
+ # If we're NOT on a gitlab-docs stable branch, fetch the BRANCH_* environment
+ # variable, and if not assigned, set to the default branch.
+ #
+ return ENV.fetch("BRANCH_#{slug.upcase}", default_branch(products[slug].fetch('repo'))) if stable_branch_name.nil?
- case slug
- # EE has different branch name scheme
- when 'ee'
- "#{version[:major]}-#{version[:minor]}-stable-ee"
+ #
+ # Check the project slug to determine the branch name
+ #
+ case slug
- when 'omnibus', 'runner'
- "#{version[:major]}-#{version[:minor]}-stable"
+ when 'ee'
+ "#{stable_branch_name}-ee"
- # Charts don't use the same version scheme as GitLab, we need to
- # deduct their version from the GitLab equivalent one.
- when 'charts'
- chart = chart_version(ENV.fetch('CI_COMMIT_REF_NAME', nil)).match(VERSION_FORMAT)
- "#{chart[:major]}-#{chart[:minor]}-stable"
+ when 'omnibus', 'runner'
+ stable_branch_name
- # If the upstream product doesn't follow a stable branch scheme, set the
- # branch to the default
- else
- default_branch(products[slug].fetch('repo'))
- end
+ # Charts don't use the same version scheme as GitLab, we need to
+ # deduct their version from the GitLab equivalent one.
+ when 'charts'
+ charts_stable_branch
- # If we're NOT on a gitlab-docs stable branch, fetch the BRANCH_* environment
- # variable, and if not assigned, set to the default branch.
+ # If the upstream product doesn't follow a stable branch scheme, set the
+ # branch to the default
else
- ENV.fetch("BRANCH_#{slug.upcase}", default_branch(products[slug].fetch('repo')))
+ default_branch(products[slug].fetch('repo'))
end
end
@@ -72,6 +66,27 @@ class TaskHelpers
end
#
+ # If we're on a gitlab-docs stable branch (or targeting one) according to the
+ # regex, catch the version and return the branch name.
+ # For example, 15-8-stable.
+ #
+ # 1. Skip if CI_COMMIT_REF_NAME is not defined (run outside the CI environment).
+ # 2. If CI_COMMIT_REF_NAME matches the version format it means we're on a
+ # stable branch. Return the version format of that branch.
+ # 3. If CI_MERGE_REQUEST_TARGET_BRANCH_NAME is defined and its value matches
+ # the version format, return that value.
+ #
+ def stable_branch_name
+ @stable_branch_name ||= begin
+ ref_name = ENV["CI_COMMIT_REF_NAME"]&.match(VERSION_FORMAT)
+ return "#{ref_name[:major]}-#{ref_name[:minor]}-stable" if ref_name
+
+ mr_name = ENV["CI_MERGE_REQUEST_TARGET_BRANCH_NAME"]&.match(VERSION_FORMAT)
+ "#{mr_name[:major]}-#{mr_name[:minor]}-stable" if mr_name
+ end
+ end
+
+ #
# The charts versions do not follow the same GitLab major number, BUT
# they do follow a pattern https://docs.gitlab.com/charts/installation/version_mappings.html:
#
@@ -81,8 +96,8 @@ class TaskHelpers
# This means we can deduct the charts version from the GitLab version, since
# the major charts version is always 9 versions behind its GitLab counterpart.
#
- def chart_version(gitlab_version)
- major, minor = gitlab_version.split('.')
+ def charts_stable_branch
+ major, minor = stable_branch_name.split('-')
# Assume major charts version is nine less than major GitLab version.
# If this breaks and the version isn't found, it might be because they
@@ -90,7 +105,7 @@ class TaskHelpers
# about it.
major = major.to_i - 9
- "#{major}.#{minor}"
+ "#{major}-#{minor}-stable"
end
def default_branch(repo)