diff options
author | Sarah German <sgerman@gitlab.com> | 2023-01-17 23:30:26 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2023-01-20 22:53:57 +0300 |
commit | 3cada5de4e45f60a0204c8a69743167d331faea0 (patch) | |
tree | d68552d01e8661375a064205debffc1954c5f7e0 | |
parent | 32cfc361e249a0a2d4fa28835e5febe7fd681fc6 (diff) |
Merge branch 'axil-target-branch-upstream' into 'main'
Check the target branch when pulling upstream projects
Closes #1362
See merge request https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3433
Merged-by: Sarah German <sgerman@gitlab.com>
Approved-by: Sarah German <sgerman@gitlab.com>
Reviewed-by: Achilleas Pipinellis <axil@gitlab.com>
Reviewed-by: Ash McKenzie <amckenzie@gitlab.com>
Co-authored-by: Achilleas Pipinellis <axil@gitlab.com>
(cherry picked from commit a3377b6b59f01a2833e5bd39b72f55b9331b7126)
9aed7add Check the target branch when pulling upstream projects
5443965d DRY the code needed to pull the repositories
a8b96f70 Show the branch name in the output when cloning repositories
5ef39162 Use stable_branch_major_minor_version directly in charts_stable_version
d7fc995f Fix charts_stable_branch test
3ab09821 Merge stable_branch_major_minor_version and stable_version
-rw-r--r-- | lib/tasks/build_site.rake | 2 | ||||
-rw-r--r-- | lib/tasks/task_helpers.rb | 73 | ||||
-rw-r--r-- | spec/lib/task_helpers_spec.rb | 14 |
3 files changed, 52 insertions, 37 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) diff --git a/spec/lib/task_helpers_spec.rb b/spec/lib/task_helpers_spec.rb index 2a5ada7e..3ccd87a6 100644 --- a/spec/lib/task_helpers_spec.rb +++ b/spec/lib/task_helpers_spec.rb @@ -13,16 +13,16 @@ describe TaskHelpers do end end - describe '#chart_version' do - let(:gitlab_version) { nil } + describe '#charts_stable_branch' do + subject(:charts_stable_branch) { described_class.new.charts_stable_branch } - subject(:chart_version) { described_class.new.chart_version(gitlab_version) } + context 'when GitLab version is 15-0-stable' do + ENV['CI_COMMIT_REF_NAME'] = '15.0' - context 'when GitLab version is 15' do - let(:gitlab_version) { '15.0' } + let(:stable_branch_name) { '15-0-stable' } - it 'returns charts version 6.0' do - expect(chart_version).to eq('6.0') + it 'returns charts branch 6-0-stable' do + expect(charts_stable_branch).to eq('6-0-stable') end end end |